bug_id
string | issue_url
string | bug_type
string | base_commit
string | knowledge_cutoff
timestamp[s] | lit_test_dir
list | hints
dict | patch
string | tests
list | issue
dict | verified
bool | test_commit
string |
---|---|---|---|---|---|---|---|---|---|---|---|
90900
|
https://github.com/llvm/llvm-project/issues/90900
|
crash
|
311339e25cd4d431902f93b1cbc6b67ac3fd2abf
| 2024-05-02T19:52:37 |
[
"llvm/test/Transforms/Reg2Mem"
] |
{
"fix_commit": "fdaad738753cde2bba6480c2ee5d1e9fb45064b9",
"components": [
"DemoteRegToStack"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": [
[
50,
55
],
[
102,
110
]
],
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/include/llvm/IR/Instruction.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": [
"llvm::DemoteRegToStack"
],
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit fdaad738753cde2bba6480c2ee5d1e9fb45064b9
Author: XChy <[email protected]>
Date: Thu May 16 20:13:39 2024 +0800
[Reg2Mem] Handle CallBr instructions (#90953)
Fixes #90900
diff --git a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
index b2a88eadd3de..f03de2f25a41 100644
--- a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
+++ b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
@@ -50,6 +50,15 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
assert(BB && "Unable to split critical edge.");
(void)BB;
}
+ } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) {
+ for (int i = 0; i < CBI->getNumSuccessors(); i++) {
+ auto *Succ = CBI->getSuccessor(i);
+ if (!Succ->getSinglePredecessor()) {
+ assert(isCriticalEdge(II, i) && "Expected a critical edge!");
+ BasicBlock *BB = SplitCriticalEdge(II, i);
+ assert(BB && "Unable to split critical edge.");
+ }
+ }
}
// Change all of the users of the instruction to read from the stack slot.
@@ -102,9 +111,14 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
new StoreInst(&I, Slot, Handler->getFirstInsertionPt());
return Slot;
}
+ } else if (InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
+ InsertPt = II->getNormalDest()->getFirstInsertionPt();
+ } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) {
+ for (BasicBlock *Succ : successors(CBI))
+ new StoreInst(CBI, Slot, Succ->getFirstInsertionPt());
+ return Slot;
} else {
- InvokeInst &II = cast<InvokeInst>(I);
- InsertPt = II.getNormalDest()->getFirstInsertionPt();
+ llvm_unreachable("Unsupported terminator for Reg2Mem");
}
new StoreInst(&I, Slot, InsertPt);
|
[
{
"file": "llvm/test/Transforms/Reg2Mem/callbr-crash.ll",
"commands": [
"opt -passes=reg2mem -S < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\ndefine void @crash() {\n;\nentry:\n %a = callbr i64 asm \"\", \"=r,r,!i\"(i64 0)\n to label %then [label %else]\n\nthen:\n %b = inttoptr i64 %a to ptr\n br label %else\n\nelse:\n ret void\n}",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "Reg2Mem pass triggered assertion `isa<To>(V al) && \"cast<Ty>() argument of incompatible type!\"",
"body": "https://godbolt.org/z/oxW8zbKr6\r\n`opt --passes=reg2mem reduced.ll`\r\n```llvm\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n%struct.__large_struct = type { [100 x i64] }\r\n\r\ndefine fastcc i64 @__se_sys_pselect6() {\r\n %1 = callbr i64 asm sideeffect \"\\0A1:\\09movq $1,$0\\0A .pushsection \\22__ex_table\\22,\\22a\\22\\0A .balign 4\\0A .long (1b) - .\\0A .long (${2:l}) - .\\0A .long 3 \\0A .popsection\\0A\", \"=r,*m,!i,~{dirflag},~{fpsr},~{flags}\"(ptr elementtype(%struct.__large_struct) null)\r\n to label %2 [label %common.ret]\r\n\r\n2: ; preds = %0\r\n %3 = inttoptr i64 %1 to ptr\r\n %4 = callbr i64 asm sideeffect \"\\0A1:\\09movq $1,$0\\0A .pushsection \\22__ex_table\\22,\\22a\\22\\0A .balign 4\\0A .long (1b) - .\\0A .long (${2:l}) - .\\0A .long 3 \\0A .popsection\\0A\", \"=r,*m,!i,~{dirflag},~{fpsr},~{flags}\"(ptr elementtype(%struct.__large_struct) null)\r\n to label %common.ret [label %common.ret]\r\n\r\ncommon.ret: ; preds = %2, %2, %0\r\n ret i64 0\r\n}\r\n```",
"author": "XChy",
"labels": [
"crash",
"llvm:transforms"
],
"comments": []
}
| true | null |
114191
|
https://github.com/llvm/llvm-project/issues/114191
|
miscompilation
|
e577f14b670ee2ae6bb717133310b215be4331b3
| 2024-10-30T07:41:28 |
[
"llvm/test/Transforms/InstCombine",
"llvm/test/Transforms/InstSimplify"
] |
{
"fix_commit": "a77dedcacb4c5eb221395b69877981dd6ad98989",
"components": [
"IR",
"InstCombine",
"InstructionSimplify"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": [
[
1095,
1113
]
],
"llvm/lib/IR/ConstantFold.cpp": [
[
902,
912
]
],
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [
[
102,
107
]
],
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [
[
1158,
1186
],
[
1189,
1194
],
[
2138,
2166
]
],
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/include/llvm/IR/Instruction.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": [
"simplifyDivRem"
],
"llvm/lib/IR/ConstantFold.cpp": [
"llvm::ConstantFoldBinaryInstruction"
],
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [
"InstCombinerImpl::commonIDivTransforms",
"InstCombinerImpl::commonIRemTransforms",
"foldIDivShl"
],
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit a77dedcacb4c5eb221395b69877981dd6ad98989
Author: Yingwei Zheng <[email protected]>
Date: Fri Nov 1 22:56:22 2024 +0800
[InstSimplify][InstCombine][ConstantFold] Move vector div/rem by zero fold to InstCombine (#114280)
Previously we fold `div/rem X, C` into `poison` if any element of the
constant divisor `C` is zero or undef. However, it is incorrect when
threading udiv over an vector select:
https://alive2.llvm.org/ce/z/3Ninx5
```
define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {
%sel = select <2 x i1> %x, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 1>
%div = udiv <2 x i32> <i32 42, i32 -7>, %sel
ret <2 x i32> %div
}
```
In this case, `threadBinOpOverSelect` folds `udiv <i32 42, i32 -7>, <i32
-1, i32 -1>` and `udiv <i32 42, i32 -7>, <i32 0, i32 1>` into
`zeroinitializer` and `poison`, respectively. One solution is to
introduce a new flag indicating that we are threading over a vector
select. But it requires to modify both `InstSimplify` and
`ConstantFold`.
However, this optimization doesn't provide benefits to real-world
programs:
https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908
https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107
This patch moves the fold into InstCombine to avoid breaking numerous
existing tests.
Fixes #114191 and #113866 (only poison-safety issue).
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index d08be1e55c85..2cb2612bf611 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -1095,19 +1095,6 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
if (match(Op1, m_Zero()))
return PoisonValue::get(Ty);
- // If any element of a constant divisor fixed width vector is zero or undef
- // the behavior is undefined and we can fold the whole op to poison.
- auto *Op1C = dyn_cast<Constant>(Op1);
- auto *VTy = dyn_cast<FixedVectorType>(Ty);
- if (Op1C && VTy) {
- unsigned NumElts = VTy->getNumElements();
- for (unsigned i = 0; i != NumElts; ++i) {
- Constant *Elt = Op1C->getAggregateElement(i);
- if (Elt && (Elt->isNullValue() || Q.isUndefValue(Elt)))
- return PoisonValue::get(Ty);
- }
- }
-
// poison / X -> poison
// poison % X -> poison
if (isa<PoisonValue>(Op0))
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 07dfbc41e79b..c2780faee403 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -902,11 +902,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
Constant *ExtractIdx = ConstantInt::get(Ty, i);
Constant *LHS = ConstantExpr::getExtractElement(C1, ExtractIdx);
Constant *RHS = ConstantExpr::getExtractElement(C2, ExtractIdx);
-
- // If any element of a divisor vector is zero, the whole op is poison.
- if (Instruction::isIntDivRem(Opcode) && RHS->isNullValue())
- return PoisonValue::get(VTy);
-
Constant *Res = ConstantExpr::isDesirableBinOp(Opcode)
? ConstantExpr::get(Opcode, LHS, RHS)
: ConstantFoldBinaryInstruction(Opcode, LHS, RHS);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 7a060cdab2d3..adbd9186c59c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -102,6 +102,7 @@ public:
Instruction *visitSRem(BinaryOperator &I);
Instruction *visitFRem(BinaryOperator &I);
bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I);
+ Instruction *commonIDivRemTransforms(BinaryOperator &I);
Instruction *commonIRemTransforms(BinaryOperator &I);
Instruction *commonIDivTransforms(BinaryOperator &I);
Instruction *visitUDiv(BinaryOperator &I);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index b9c165da906d..f85a3c936513 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1158,29 +1158,39 @@ static Value *foldIDivShl(BinaryOperator &I, InstCombiner::BuilderTy &Builder) {
return nullptr;
}
-/// This function implements the transforms common to both integer division
-/// instructions (udiv and sdiv). It is called by the visitors to those integer
-/// division instructions.
-/// Common integer divide transforms
-Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {
- if (Instruction *Phi = foldBinopWithPhiOperands(I))
- return Phi;
-
+/// Common integer divide/remainder transforms
+Instruction *InstCombinerImpl::commonIDivRemTransforms(BinaryOperator &I) {
+ assert(I.isIntDivRem() && "Unexpected instruction");
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
- bool IsSigned = I.getOpcode() == Instruction::SDiv;
+
+ // If any element of a constant divisor fixed width vector is zero or undef
+ // the behavior is undefined and we can fold the whole op to poison.
+ auto *Op1C = dyn_cast<Constant>(Op1);
Type *Ty = I.getType();
+ auto *VTy = dyn_cast<FixedVectorType>(Ty);
+ if (Op1C && VTy) {
+ unsigned NumElts = VTy->getNumElements();
+ for (unsigned i = 0; i != NumElts; ++i) {
+ Constant *Elt = Op1C->getAggregateElement(i);
+ if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt)))
+ return replaceInstUsesWith(I, PoisonValue::get(Ty));
+ }
+ }
+
+ if (Instruction *Phi = foldBinopWithPhiOperands(I))
+ return Phi;
// The RHS is known non-zero.
if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I))
return replaceOperand(I, 1, V);
- // Handle cases involving: [su]div X, (select Cond, Y, Z)
- // This does not apply for fdiv.
+ // Handle cases involving: div/rem X, (select Cond, Y, Z)
if (simplifyDivRemOfSelectWithZeroOp(I))
return &I;
// If the divisor is a select-of-constants, try to constant fold all div ops:
- // C / (select Cond, TrueC, FalseC) --> select Cond, (C / TrueC), (C / FalseC)
+ // C div/rem (select Cond, TrueC, FalseC) --> select Cond, (C div/rem TrueC),
+ // (C div/rem FalseC)
// TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.
if (match(Op0, m_ImmConstant()) &&
match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {
@@ -1189,6 +1199,21 @@ Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {
return R;
}
+ return nullptr;
+}
+
+/// This function implements the transforms common to both integer division
+/// instructions (udiv and sdiv). It is called by the visitors to those integer
+/// division instructions.
+/// Common integer divide transforms
+Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {
+ if (Instruction *Res = commonIDivRemTransforms(I))
+ return Res;
+
+ Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
+ bool IsSigned = I.getOpcode() == Instruction::SDiv;
+ Type *Ty = I.getType();
+
const APInt *C2;
if (match(Op1, m_APInt(C2))) {
Value *X;
@@ -2138,29 +2163,11 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I,
/// remainder instructions.
/// Common integer remainder transforms
Instruction *InstCombinerImpl::commonIRemTransforms(BinaryOperator &I) {
- if (Instruction *Phi = foldBinopWithPhiOperands(I))
- return Phi;
+ if (Instruction *Res = commonIDivRemTransforms(I))
+ return Res;
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
- // The RHS is known non-zero.
- if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I))
- return replaceOperand(I, 1, V);
-
- // Handle cases involving: rem X, (select Cond, Y, Z)
- if (simplifyDivRemOfSelectWithZeroOp(I))
- return &I;
-
- // If the divisor is a select-of-constants, try to constant fold all rem ops:
- // C % (select Cond, TrueC, FalseC) --> select Cond, (C % TrueC), (C % FalseC)
- // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds.
- if (match(Op0, m_ImmConstant()) &&
- match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) {
- if (Instruction *R = FoldOpIntoSelect(I, cast<SelectInst>(Op1),
- /*FoldWithMultiUse*/ true))
- return R;
- }
-
if (isa<Constant>(Op1)) {
if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) {
if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {
|
[
{
"file": "llvm/test/Transforms/InstCombine/div.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec",
"test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "udiv_constant_dividend_select_of_constants_divisor_vec",
"test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec_ub1",
"test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "udiv_constant_dividend_select_of_constants_divisor_vec_ub1",
"test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
},
{
"file": "llvm/test/Transforms/InstCombine/rem.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "urem_constant_dividend_select_of_constants_divisor_vec_ub1",
"test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "urem_constant_dividend_select_of_constants_divisor_vec",
"test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
},
{
"file": "llvm/test/Transforms/InstCombine/vector-udiv.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "vec_select_udiv_poison",
"test_body": "define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {\n %sel = select <2 x i1> %x, <2 x i32> splat (i32 -1), <2 x i32> <i32 0, i32 1>\n %div = udiv <2 x i32> <i32 42, i32 -7>, %sel\n ret <2 x i32> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "test_v4i32_zext_shl_const_pow2",
"test_body": "define <4 x i32> @test_v4i32_zext_shl_const_pow2(<4 x i32> %a0, <4 x i16> %a1) {\n %1 = shl <4 x i16> <i16 4, i16 8, i16 16, i16 32>, %a1\n %2 = zext <4 x i16> %1 to <4 x i32>\n %3 = udiv <4 x i32> %a0, %2\n ret <4 x i32> %3\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
},
{
"file": "llvm/test/Transforms/InstSimplify/div.ll",
"commands": [
"opt < %s -passes=instsimplify -S"
],
"tests": [
{
"test_name": "udiv_zero_elt_vec",
"test_body": "define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "sdiv_zero_elt_vec",
"test_body": "define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "udiv_poison_elt_vec",
"test_body": "define <2 x i8> @udiv_poison_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 poison, i8 42>\n ret <2 x i8> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "sdiv_zero_elt_vec_constfold",
"test_body": "define <2 x i8> @sdiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = sdiv <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "sdiv_poison_elt_vec",
"test_body": "define <2 x i8> @sdiv_poison_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 poison>\n ret <2 x i8> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "udiv_zero_elt_vec_constfold",
"test_body": "define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = udiv <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %div\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "zero_dividend_vector_poison_elt",
"test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = sdiv <2 x i32> <i32 0, i32 poison>, %A\n ret <2 x i32> %B\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
},
{
"file": "llvm/test/Transforms/InstSimplify/rem.ll",
"commands": [
"opt < %s -passes=instsimplify -S"
],
"tests": [
{
"test_name": "srem_zero_elt_vec_constfold",
"test_body": "define <2 x i8> @srem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = srem <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %rem\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "urem_zero_elt_vec",
"test_body": "define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %rem\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "urem_zero_elt_vec_constfold",
"test_body": "define <2 x i8> @urem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = urem <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %rem\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "srem_undef_elt_vec",
"test_body": "define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 undef>\n ret <2 x i8> %rem\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "urem_undef_elt_vec",
"test_body": "define <2 x i8> @urem_undef_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 undef, i8 42>\n ret <2 x i8> %rem\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "zero_dividend_vector_poison_elt",
"test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = urem <2 x i32> <i32 poison, i32 0>, %A\n ret <2 x i32> %B\n}\n",
"additional_args": null,
"lli_expected_out": null
},
{
"test_name": "srem_zero_elt_vec",
"test_body": "define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %rem\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "[InstCombine] miscompilation of `or` of vectors",
"body": "Alive2 report: https://alive2.llvm.org/ce/z/LyM8sY\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = udiv <2 x i32> { 42, 4294967289 }, %#1\r\n ret <2 x i32> %#2\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 0, 0 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #x00000000 (0), #x00000000 (0) >\r\n\r\n\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = sdiv <2 x i32> { 42, 4294967289 }, %#1\r\n %#3 = udiv exact <2 x i32> %#2, %#2\r\n %#4 = or <2 x i32> %#2, %#2\r\n ret <2 x i32> %#4\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 4294967254, 7 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n<2 x i32> %#3 = < #x00000001 (1), #x00000001 (1) >\r\n<2 x i32> %#4 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #xffffffd6 (4294967254, -42), #x00000007 (7) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 2 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```",
"author": "bongjunj",
"labels": [
"miscompilation",
"llvm:instcombine",
"llvm:analysis"
],
"comments": [
{
"author": "dtcxzyw",
"body": "@bongjunj Feel free to ping me if you find new InstCombine miscompilation bugs without involving undef values/NaN payloads."
},
{
"author": "dtcxzyw",
"body": "https://github.com/llvm/llvm-project/blob/eac2c182c6f852fc187af9952250a43d6fb17b28/llvm/lib/Analysis/InstructionSimplify.cpp#L1098-L1109\r\n\r\nWe cannot do this simplification when threading udiv over selects.\r\n "
}
]
}
| true | null |
118725
|
https://github.com/llvm/llvm-project/issues/118725
|
crash
|
e3352904309a539eddcf3ddd9fb11ca2aef29d65
| 2024-12-05T01:14:53 |
[
"llvm/test/Transforms/GlobalOpt"
] |
{
"fix_commit": "5013c81b781eb95af8e429956d63c8f9c16a4647",
"components": [
"Evaluator"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": [
[
125,
133
]
],
"llvm/lib/Transforms/Utils/Evaluator.cpp": [
[
253,
292
],
[
520,
528
],
[
544,
553
]
],
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/include/llvm/IR/Instruction.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": [
"setVal"
],
"llvm/lib/Transforms/Utils/Evaluator.cpp": [
"Evaluator::EvaluateBlock",
"Evaluator::castCallResultIfNeeded",
"Evaluator::getFormalParams"
],
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit 5013c81b781eb95af8e429956d63c8f9c16a4647
Author: Nikita Popov <[email protected]>
Date: Thu Dec 12 10:44:52 2024 +0100
[GlobalOpt][Evaluator] Don't evaluate calls with signature mismatch (#119548)
The global ctor evaluator tries to evalute function calls where the call
function type and function type do not match, by performing bitcasts.
This currently causes a crash when calling a void function with non-void
return type.
I've opted to remove this functionality entirely rather than fixing this
specific case. With opaque pointers, there shouldn't be a legitimate use
case for this anymore, as we don't need to look through pointer type
casts. Doing other bitcasts is very iffy because it ignores ABI
considerations. We should at least leave adjusting the signatures to
make them line up to InstCombine (which also does some iffy things, but
is at least somewhat more constrained).
Fixes https://github.com/llvm/llvm-project/issues/118725.
diff --git a/llvm/include/llvm/Transforms/Utils/Evaluator.h b/llvm/include/llvm/Transforms/Utils/Evaluator.h
index 5d53773b5d6b..118037625421 100644
--- a/llvm/include/llvm/Transforms/Utils/Evaluator.h
+++ b/llvm/include/llvm/Transforms/Utils/Evaluator.h
@@ -125,9 +125,6 @@ private:
ValueStack.back()[V] = C;
}
- /// Casts call result to a type of bitcast call expression
- Constant *castCallResultIfNeeded(Type *ReturnType, Constant *RV);
-
/// Given call site return callee and list of its formal arguments
Function *getCalleeWithFormalArgs(CallBase &CB,
SmallVectorImpl<Constant *> &Formals);
diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp
index cf1a8b4af112..2af447aadce2 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -253,40 +253,17 @@ Evaluator::getCalleeWithFormalArgs(CallBase &CB,
bool Evaluator::getFormalParams(CallBase &CB, Function *F,
SmallVectorImpl<Constant *> &Formals) {
- if (!F)
- return false;
-
auto *FTy = F->getFunctionType();
- if (FTy->getNumParams() > CB.arg_size()) {
- LLVM_DEBUG(dbgs() << "Too few arguments for function.\n");
+ if (FTy != CB.getFunctionType()) {
+ LLVM_DEBUG(dbgs() << "Signature mismatch.\n");
return false;
}
- auto ArgI = CB.arg_begin();
- for (Type *PTy : FTy->params()) {
- auto *ArgC = ConstantFoldLoadThroughBitcast(getVal(*ArgI), PTy, DL);
- if (!ArgC) {
- LLVM_DEBUG(dbgs() << "Can not convert function argument.\n");
- return false;
- }
- Formals.push_back(ArgC);
- ++ArgI;
- }
+ for (Value *Arg : CB.args())
+ Formals.push_back(getVal(Arg));
return true;
}
-/// If call expression contains bitcast then we may need to cast
-/// evaluated return value to a type of the call expression.
-Constant *Evaluator::castCallResultIfNeeded(Type *ReturnType, Constant *RV) {
- if (!RV || RV->getType() == ReturnType)
- return RV;
-
- RV = ConstantFoldLoadThroughBitcast(RV, ReturnType, DL);
- if (!RV)
- LLVM_DEBUG(dbgs() << "Failed to fold bitcast call expr\n");
- return RV;
-}
-
/// Evaluate all instructions in block BB, returning true if successful, false
/// if we can't evaluate it. NewBB returns the next BB that control flows into,
/// or null upon return. StrippedPointerCastsForAliasAnalysis is set to true if
@@ -520,9 +497,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
if (Callee->isDeclaration()) {
// If this is a function we can constant fold, do it.
if (Constant *C = ConstantFoldCall(&CB, Callee, Formals, TLI)) {
- InstResult = castCallResultIfNeeded(CB.getType(), C);
- if (!InstResult)
- return false;
+ InstResult = C;
LLVM_DEBUG(dbgs() << "Constant folded function call. Result: "
<< *InstResult << "\n");
} else {
@@ -544,10 +519,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
return false;
}
ValueStack.pop_back();
- InstResult = castCallResultIfNeeded(CB.getType(), RetVal);
- if (RetVal && !InstResult)
- return false;
-
+ InstResult = RetVal;
if (InstResult) {
LLVM_DEBUG(dbgs() << "Successfully evaluated function. Result: "
<< *InstResult << "\n\n");
|
[
{
"file": "llvm/test/Transforms/GlobalOpt/evaluate-ret-void-mismatch.ll",
"commands": [
"opt -S -passes=globalopt < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\n; Don't evaluate call with return value type mismatch.\n\[email protected]_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr null }]\n\ndefine void @__cxa_guard_acquire() {\n;\nentry:\n ret void\n}\n\ndefine void @__cxx_global_var_init() {\n;\n %res = call i32 @__cxa_guard_acquire()\n %tobool.not = icmp eq i32 %res, 0\n ret void\n}",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "SIGSEGV with -flto",
"body": "Static linking with -flto on Arch linux with clang 18.1.8\n\nNot able to get a minimal repro at the moment. Other possibly less common options\n\n \"-std=c++20\",\n \"-nostdlib\",\n \"-nostartfiles\",\n \"-fno-exceptions\",\n \"-fno-rtti\",\n\nProgram terminated with signal SIGSEGV, Segmentation fault.\n#0 0x00007ee06170e69c in llvm::ConstantFoldConstant(llvm::Constant const*, llvm::DataLayout const&, llvm::TargetLibraryInfo const*) () from /usr/lib/libLLVM.so.18.1\n#0 0x00007ee06170e69c in llvm::ConstantFoldConstant(llvm::Constant const*, llvm::DataLayout const&, llvm::TargetLibraryInfo const*) () from /usr/lib/libLLVM.so.18.1\n#1 0x00007ee060abea1a in llvm::Evaluator::EvaluateBlock(llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void, true>, false, false>, llvm::BasicBlock*&, bool&) () from /usr/lib/libLLVM.so.18.1\n#2 0x00007ee060ac14e4 in llvm::Evaluator::EvaluateFunction(llvm::Function*, llvm::Constant*&, llvm::SmallVectorImpl<llvm::Constant*> const&) () from /usr/lib/libLLVM.so.18.1\n#3 0x00007ee061307930 in ?? () from /usr/lib/libLLVM.so.18.1\n#4 0x00007ee061308634 in ?? () from /usr/lib/libLLVM.so.18.1\n#5 0x00007ee060aa7649 in llvm::optimizeGlobalCtorsList(llvm::Module&, llvm::function_ref<bool (unsigned int, llvm::Function*)>) () from /usr/lib/libLLVM.so.18.1\n#6 0x00007ee0613135f9 in llvm::GlobalOptPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) () from /usr/lib/libLLVM.so.18.1\n#7 0x00007ee06411d177 in ?? () from /usr/lib/libLLVM.so.18.1\n#8 0x00007ee05fbd767e in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) () from /usr/lib/libLLVM.so.18.1\n#9 0x00007ee061a57995 in ?? () from /usr/lib/libLLVM.so.18.1\n#10 0x00007ee061a591ff in llvm::lto::opt(llvm::lto::Config const&, llvm::TargetMachine*, unsigned int, llvm::Module&, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*, std::vector<unsigned char, std::allocator<unsigned char> > const&) () from /usr/lib/libLLVM.so.18.1\n#11 0x00007ee061a5a582 in llvm::lto::backend(llvm::lto::Config const&, std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream> > > (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) () from /usr/lib/libLLVM.so.18.1\n#12 0x00007ee061a4ed49 in llvm::lto::LTO::runRegularLTO(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream> > > (unsigned int, llvm::Twine const&)>) () from /usr/lib/libLLVM.so.18.1\n#13 0x00007ee061a4f241 in llvm::lto::LTO::run(std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream> > > (unsigned int, llvm::Twine const&)>, std::function<llvm::Expected<std::function<llvm::Expected<std::unique_ptr<llvm::CachedFileStream, std::default_delete<llvm::CachedFileStream> > > (unsigned int, llvm::Twine const&)> > (unsigned int, llvm::StringRef, llvm::Twine const&)>) () from /usr/lib/libLLVM.so.18.1\n#14 0x00007ee0678ce067 in ?? () from /usr/bin/../lib/LLVMgold.so\n#15 0x00007ee0678cfd12 in ?? () from /usr/bin/../lib/LLVMgold.so\n#16 0x000056f827567837 in ?? ()\n#17 0x000056f82756f75f in ?? ()\n#18 0x00007ee067a00e08 in ?? () from /usr/lib/libc.so.6\n#19 0x00007ee067a00ecc in __libc_start_main () from /usr/lib/libc.so.6\n#20 0x000056f82756ea65 in ?? ()\n",
"author": "illiminable",
"labels": [
"incomplete",
"crash",
"LTO"
],
"comments": [
{
"author": "EugeneZelenko",
"body": "Could you please try 19 or `main` branch?"
},
{
"author": "illiminable",
"body": "I don't think 19 is packaged for arch yet. I'll see if I can build trunk later in the week.\n\nIs it possible to just to disable this optimizeGlobalCtorsList or all of globalopt. I looked through --hidden-help and could not see an option like this."
},
{
"author": "ms178",
"body": "@illiminable While it is not packaged by Arch yet, you could try the linked toolchain instead and use it via an environment variable which points llvm to the new path: https://mirrors.edge.kernel.org/pub/tools/llvm/"
},
{
"author": "illiminable",
"body": "OK thanks I'll try. FWIW this is the approximate code pattern. And presumably its trying to optimize the fact that there are N unique symbols that \"register\" assigns true to but then never get used.\n\n```\n// Header File\nclass Functor {\n virtual void execImpl() = 0;\n void exec() { execImpl(); }\n };\n \n class Info {\n Functor* fn = nullptr;\n };\n \n class Registry {\n array<Info, 1024> fns;\n int count = 0;\n \n void register(Info&& f) {\n fns[count++] = f;\n }\n \n void exec() {\n for i in 0..count { fns[i].fn->exec(); }\n }\n };\n \n inline Registry reg;\n \n inline bool register(Functor* fn) {\n reg.register({.fn = fn});\n return true;\n }\n \n \n // REPEAT approx 10 each copies of the below in 10 different .cpp TU's\n class _uniquesymbol_ : public Functor {\n void execImpl() override;\n };\n \n // Instance of the derived functor class\n _uniquesymbol_ _uniquesymbol__instance;\n \n // _uniquesymbol__flag is always true and never used. Theres probably a better\n // way to do this?\n const bool _uniquesymbol__flag = register(&_uniquesymbol__instance);\n \n void _uniquesymbol_::execImpl() {\n // do stuff\n }\n \n // END REPEAT\n \n \n // Usage...\n reg.exec();\n``` \n"
},
{
"author": "illiminable",
"body": "@ms178 The toolchain didn't work because it doesn't contain LLVMgold.so\n\nI was able to build from the 19.1.5 branch in debug and can repro. It's only on one target. This is the assert output\n\nld.gold: /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::ConstantVector; From = llvm::Constant]: Assertion `Val && \"isa<> used on a null pointer\"' failed.\n\nAnd a better symbolized stack\n\n#0 0x00007c11cae473f4 in ?? () from /usr/lib/libc.so.6\n#0 0x00007c11cae473f4 in ?? () from /usr/lib/libc.so.6\n#1 0x00007c11cadee120 in raise () from /usr/lib/libc.so.6\n#2 0x00007c11cadd54c3 in abort () from /usr/lib/libc.so.6\n#3 0x00007c11cadd53df in ?? () from /usr/lib/libc.so.6\n#4 0x00007c11cade6177 in __assert_fail () from /usr/lib/libc.so.6\n#5 0x00007c11c329c245 in llvm::isa_impl_cl<llvm::ConstantVector, llvm::Constant const*>::doit (Val=0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:109\n#6 0x00007c11c329bd99 in llvm::isa_impl_wrap<llvm::ConstantVector, llvm::Constant const*, llvm::Constant const*>::doit (Val=@0x7ffd009f71a0: 0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:137\n#7 0x00007c11c329b45b in llvm::isa_impl_wrap<llvm::ConstantVector, llvm::Constant const* const, llvm::Constant const*>::doit (Val=@0x7ffd009f71f0: 0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:129\n#8 0x00007c11c329a6b6 in llvm::CastIsPossible<llvm::ConstantVector, llvm::Constant const*, void>::isPossible (f=@0x7ffd009f71f0: 0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:257\n#9 0x00007c11c5ccd903 in llvm::CastInfo<llvm::ConstantVector, llvm::Constant const* const, void>::isPossible (f=@0x7ffd009f7248: 0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:509\n#10 0x00007c11c5ccd3d8 in llvm::isa<llvm::ConstantVector, llvm::Constant const*> (Val=@0x7ffd009f7248: 0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:549\n#11 0x00007c11c5f8be6e in (anonymous namespace)::ConstantFoldConstantImpl (C=0x0, DL=..., TLI=0x5d4a86076c38, FoldedOps=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:1078\n#12 0x00007c11c5f8c5d3 in llvm::ConstantFoldConstant (C=0x0, DL=..., TLI=0x5d4a86076c38) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:1163\n#13 0x00007c11c5cb7bdc in llvm::Evaluator::EvaluateBlock (this=0x7ffd009f7930, CurInst=..., NextBB=@0x7ffd009f76e0: 0x0, StrippedPointerCastsForAliasAnalysis=@0x7ffd009f76d0: false) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/Utils/Evaluator.cpp:610\n#14 0x00007c11c5cb7fd8 in llvm::Evaluator::EvaluateFunction (this=0x7ffd009f7930, F=0x5d4a85ccc618, RetVal=@0x7ffd009f78a8: 0x7ffd009f7ae0, ActualArgs=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/Utils/Evaluator.cpp:660\n#15 0x00007c11c4f410a8 in EvaluateStaticConstructor (F=0x5d4a85ccc618, DL=..., TLI=0x5d4a86076c38) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2080\n#16 0x00007c11c4f42bf7 in operator() (__closure=0x7ffd009f7e90, Priority=65535, F=0x5d4a85ccc618) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2524\n#17 0x00007c11c4f43f3b in llvm::function_ref<bool(unsigned int, llvm::Function*)>::callback_fn<optimizeGlobalsInModule(llvm::Module&, const llvm::DataLayout&, llvm::function_ref<llvm::TargetLibraryInfo&(llvm::Function&)>, llvm::function_ref<llvm::TargetTransformInfo&(llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo&(llvm::Function&)>, llvm::function_ref<llvm::DominatorTree&(llvm::Function&)>, llvm::function_ref<void(llvm::Function&)>, llvm::function_ref<void(llvm::Function&)>)::<lambda(uint32_t, llvm::Function*)> >(intptr_t, unsigned int, llvm::Function *) (callable=140724613906064, params#0=65535, params#1=0x5d4a85ccc618) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45\n#18 0x00007c11c5c95103 in llvm::function_ref<bool(unsigned int, llvm::Function*)>::operator() (this=0x7ffd009f7cc0, params#0=65535, params#1=0x5d4a85ccc618) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68\n#19 0x00007c11c5c92754 in llvm::optimizeGlobalCtorsList (M=..., ShouldRemove=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/Utils/CtorUtils.cpp:138\n#20 0x00007c11c4f4309c in optimizeGlobalsInModule(llvm::Module &, const llvm::DataLayout &, llvm::function_ref<llvm::TargetLibraryInfo&(llvm::Function&)>, llvm::function_ref<llvm::TargetTransformInfo&(llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo&(llvm::Function&)>, llvm::function_ref<llvm::DominatorTree&(llvm::Function&)>, llvm::function_ref<void(llvm::Function&)>, llvm::function_ref<void(llvm::Function&)>) (M=..., DL=..., GetTLI=..., GetTTI=..., GetBFI=..., LookupDomTree=..., ChangedCFGCallback=..., DeleteFnCallback=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2520\n#21 0x00007c11c4f435e0 in llvm::GlobalOptPass::run (this=0x5d4a85c13138, M=..., AM=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2583\n#22 0x00007c11c4366477 in llvm::detail::PassModel<llvm::Module, llvm::GlobalOptPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (this=0x5d4a85c13130, IR=..., AM=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90\n#23 0x00007c11c6e2f349 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (this=0x7ffd009f8300, IR=..., AM=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:81\n#24 0x00007c11c3934968 in runNewPMPasses (Conf=..., Mod=..., TM=0x5d4a85edf0b0, OptLevel=3, IsThinLTO=false, ExportSummary=0x5d4a85bc6d18, ImportSummary=0x0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/LTO/LTOBackend.cpp:338\n#25 0x00007c11c3934b94 in llvm::lto::opt (Conf=..., TM=0x5d4a85edf0b0, Task=0, Mod=..., IsThinLTO=false, ExportSummary=0x5d4a85bc6d18, ImportSummary=0x0, CmdArgs=std::vector of length 0, capacity 0) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/LTO/LTOBackend.cpp:363\n#26 0x00007c11c3936054 in llvm::lto::backend (C=..., AddStream=..., ParallelCodeGenParallelismLevel=1, Mod=..., CombinedIndex=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/LTO/LTOBackend.cpp:517\n#27 0x00007c11c38e855d in llvm::lto::LTO::runRegularLTO (this=0x5d4a85bc6710, AddStream=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/LTO/LTO.cpp:1354\n#28 0x00007c11c38e746b in llvm::lto::LTO::run (this=0x5d4a85bc6710, AddStream=..., Cache=...) at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/lib/LTO/LTO.cpp:1186\n#29 0x00007c11c3255536 in runLTO () at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/tools/gold/gold-plugin.cpp:1111\n#30 0x00007c11c3255a0d in allSymbolsReadHook () at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/tools/gold/gold-plugin.cpp:1148\n#31 0x00007c11c3255c19 in all_symbols_read_hook () at /mnt/local/src/third_party/github/llvm/llvm-project/llvm/tools/gold/gold-plugin.cpp:1173\n#32 0x00005d4a6c4d9154 in ?? ()\n#33 0x00005d4a6c5138d0 in ?? ()\n#34 0x00005d4a6c3fc49a in ?? ()\n#35 0x00007c11cadd6e08 in ?? () from /usr/lib/libc.so.6\n#36 0x00007c11cadd6ecc in __libc_start_main () from /usr/lib/libc.so.6\n#37 0x00005d4a6c3ff985 in ?? ()"
},
{
"author": "ms178",
"body": "@illiminable Thanks for letting me know. Unfortunately I am not a developer and cannot help you to debug this problem further."
},
{
"author": "illiminable",
"body": "I debugged a little bit, but I don't fully understand this code.\n\nIn EvaluateBlock the issue is that after the various branches the code falls out to this block at 609 with InstResult still null. All the other branches usually check InstResult and return false. ConstantFoldConstant will assert or crash if the first parameter is null in the call from 610. I also tried just guarding this conditino with !InstResult but that doesn't seem right since it triggers another assert later \"Assertion `R && \"Reference to an uncomputed value!\"'.\n\nhttps://github.com/llvm/llvm-project/blob/llvmorg-19.1.5/llvm/lib/Transforms/Utils/Evaluator.cpp#L610\n\nThe bug only only occurs when the code hits the branch on 556. Strangely the debug log here says both branches of the if are success. I don't know if it's a copy paste error or if maybe the code should just return true after 558, but given the rest of the code this doesn't seem right.\n\nBut returning false in the line 556 branch seems to fix the crash and the resulting program seems to work fine.\n\nhttps://github.com/llvm/llvm-project/blob/llvmorg-19.1.5/llvm/lib/Transforms/Utils/Evaluator.cpp#L556\n\nSomeone who understands the code better should evaluate though.\n"
},
{
"author": "illiminable",
"body": "I used llvm-reduce to reduce the bitcode and when i looked at what was left it was basically __cxa_guard_acquire and I realized that while bootstrapping i defined it with the wrong return type. So since I violated the ABI I guess my fault.\n\nNot sure if there is still an underlying issue here someone wants to fix. ie. would be better to error or ignore than crash. But it seems pretty unlikely someone else will hit at least this specific cause of the problem.\n\nCan probably close if this corner case is not important."
},
{
"author": "nikic",
"body": "Could you please share the reduced bitcode? (Or IR after running it through llvm-dis.)"
},
{
"author": "illiminable",
"body": "[reduced.zip](https://github.com/user-attachments/files/18043521/reduced.zip)\n\nThis is the reduced.bc\n\n"
}
]
}
| true | null |
137582
|
https://github.com/llvm/llvm-project/issues/137582
|
miscompilation
|
4075a3698a3fdda3a77ce2456e3bfefbc0f0c56e
| 2025-04-28T05:48:58 |
[
"llvm/test/Transforms/CorrelatedValuePropagation"
] |
{
"fix_commit": "830cf36bd4c491ef28d9bba74737e324639bb4cd",
"components": [
"IR",
"LazyValueInfo",
"ValueTracking"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": [
[
546,
569
],
[
586,
592
]
],
"llvm/include/llvm/IR/Instruction.h": [
[
585,
590
]
],
"llvm/lib/Analysis/LazyValueInfo.cpp": [
[
1701,
1707
]
],
"llvm/lib/Analysis/ValueTracking.cpp": [
[
7201,
7220
],
[
7287,
7293
]
],
"llvm/lib/IR/Instruction.cpp": [
[
532,
539
],
[
554,
559
]
],
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": [
"isSafeToSpeculativelyExecuteWithVariableReplaced"
],
"llvm/lib/Analysis/LazyValueInfo.cpp": [
"LazyValueInfoImpl::getValueAtUse"
],
"llvm/lib/Analysis/ValueTracking.cpp": [
"llvm::isNotCrossLaneOperation",
"llvm::isSafeToSpeculativelyExecuteWithOpcode"
],
"llvm/lib/IR/Instruction.cpp": [
"Instruction::dropUBImplyingAttrsAndMetadata",
"Instruction::dropUBImplyingAttrsAndUnknownMetadata",
"Instruction::isExact"
],
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit 830cf36bd4c491ef28d9bba74737e324639bb4cd
Author: Yingwei Zheng <[email protected]>
Date: Wed Apr 30 11:53:38 2025 +0800
[LVI][ValueTracking] Take UB-implying attributes into account in `isSafeToSpeculativelyExecute` (#137604)
Closes https://github.com/llvm/llvm-project/issues/137582.
In the original case, LVI uses the edge information in `%entry ->
%if.end` to get a more precise result. However, since the call to `smin`
has an `noundef` return attribute, an immediate UB will be triggered
after optimization.
Currently, `isSafeToSpeculativelyExecuteWithOpcode(%min)` returns true
because
https://github.com/llvm/llvm-project/commit/6a288c1e32351d4be3b7630841af078fa1c3bb8b
only checks whether the function is speculatable. However, it is not
enough in this case.
This patch takes UB-implying attributes into account if
`IgnoreUBImplyingAttrs` is set to false. If it is set to true, the
caller is responsible for correctly propagating UB-implying attributes.
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index f927838c843a..61dbb07e7128 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -539,6 +539,12 @@ bool isNotCrossLaneOperation(const Instruction *I);
/// move the instruction as long as the correct dominance relationships for
/// the operands and users hold.
///
+/// If \p UseVariableInfo is true, the information from non-constant operands
+/// will be taken into account.
+///
+/// If \p IgnoreUBImplyingAttrs is true, UB-implying attributes will be ignored.
+/// The caller is responsible for correctly propagating them after hoisting.
+///
/// This method can return true for instructions that read memory;
/// for such instructions, moving them may change the resulting value.
bool isSafeToSpeculativelyExecute(const Instruction *I,
@@ -546,24 +552,28 @@ bool isSafeToSpeculativelyExecute(const Instruction *I,
AssumptionCache *AC = nullptr,
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr,
- bool UseVariableInfo = true);
+ bool UseVariableInfo = true,
+ bool IgnoreUBImplyingAttrs = true);
inline bool isSafeToSpeculativelyExecute(const Instruction *I,
BasicBlock::iterator CtxI,
AssumptionCache *AC = nullptr,
const DominatorTree *DT = nullptr,
const TargetLibraryInfo *TLI = nullptr,
- bool UseVariableInfo = true) {
+ bool UseVariableInfo = true,
+ bool IgnoreUBImplyingAttrs = true) {
// Take an iterator, and unwrap it into an Instruction *.
- return isSafeToSpeculativelyExecute(I, &*CtxI, AC, DT, TLI, UseVariableInfo);
+ return isSafeToSpeculativelyExecute(I, &*CtxI, AC, DT, TLI, UseVariableInfo,
+ IgnoreUBImplyingAttrs);
}
/// Don't use information from its non-constant operands. This helper is used
/// when its operands are going to be replaced.
-inline bool
-isSafeToSpeculativelyExecuteWithVariableReplaced(const Instruction *I) {
+inline bool isSafeToSpeculativelyExecuteWithVariableReplaced(
+ const Instruction *I, bool IgnoreUBImplyingAttrs = true) {
return isSafeToSpeculativelyExecute(I, nullptr, nullptr, nullptr, nullptr,
- /*UseVariableInfo=*/false);
+ /*UseVariableInfo=*/false,
+ IgnoreUBImplyingAttrs);
}
/// This returns the same result as isSafeToSpeculativelyExecute if Opcode is
@@ -586,7 +596,8 @@ isSafeToSpeculativelyExecuteWithVariableReplaced(const Instruction *I) {
bool isSafeToSpeculativelyExecuteWithOpcode(
unsigned Opcode, const Instruction *Inst, const Instruction *CtxI = nullptr,
AssumptionCache *AC = nullptr, const DominatorTree *DT = nullptr,
- const TargetLibraryInfo *TLI = nullptr, bool UseVariableInfo = true);
+ const TargetLibraryInfo *TLI = nullptr, bool UseVariableInfo = true,
+ bool IgnoreUBImplyingAttrs = true);
/// Returns true if the result or effects of the given instructions \p I
/// depend values not reachable through the def use graph.
diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h
index 900384432d75..d8069b2fb02a 100644
--- a/llvm/include/llvm/IR/Instruction.h
+++ b/llvm/include/llvm/IR/Instruction.h
@@ -585,6 +585,10 @@ public:
/// This should be used when speculating instructions.
void dropUBImplyingAttrsAndMetadata();
+ /// Return true if this instruction has UB-implying attributes
+ /// that can cause immediate undefined behavior.
+ bool hasUBImplyingAttrs() const LLVM_READONLY;
+
/// Determine whether the exact flag is set.
bool isExact() const LLVM_READONLY;
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index e49e004a48a5..2a562484fc37 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1701,7 +1701,8 @@ ValueLatticeElement LazyValueInfoImpl::getValueAtUse(const Use &U) {
// of a cycle, we might end up reasoning about values from different cycle
// iterations (PR60629).
if (!CurrI->hasOneUse() ||
- !isSafeToSpeculativelyExecuteWithVariableReplaced(CurrI))
+ !isSafeToSpeculativelyExecuteWithVariableReplaced(
+ CurrI, /*IgnoreUBImplyingAttrs=*/false))
break;
CurrU = &*CurrI->use_begin();
}
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 1d3f8b7207a6..256e77b40a97 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -7201,20 +7201,19 @@ bool llvm::isNotCrossLaneOperation(const Instruction *I) {
!isa<CallBase, BitCastInst, ExtractElementInst>(I);
}
-bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst,
- const Instruction *CtxI,
- AssumptionCache *AC,
- const DominatorTree *DT,
- const TargetLibraryInfo *TLI,
- bool UseVariableInfo) {
+bool llvm::isSafeToSpeculativelyExecute(
+ const Instruction *Inst, const Instruction *CtxI, AssumptionCache *AC,
+ const DominatorTree *DT, const TargetLibraryInfo *TLI, bool UseVariableInfo,
+ bool IgnoreUBImplyingAttrs) {
return isSafeToSpeculativelyExecuteWithOpcode(Inst->getOpcode(), Inst, CtxI,
- AC, DT, TLI, UseVariableInfo);
+ AC, DT, TLI, UseVariableInfo,
+ IgnoreUBImplyingAttrs);
}
bool llvm::isSafeToSpeculativelyExecuteWithOpcode(
unsigned Opcode, const Instruction *Inst, const Instruction *CtxI,
AssumptionCache *AC, const DominatorTree *DT, const TargetLibraryInfo *TLI,
- bool UseVariableInfo) {
+ bool UseVariableInfo, bool IgnoreUBImplyingAttrs) {
#ifndef NDEBUG
if (Inst->getOpcode() != Opcode) {
// Check that the operands are actually compatible with the Opcode override.
@@ -7287,7 +7286,11 @@ bool llvm::isSafeToSpeculativelyExecuteWithOpcode(
// The called function could have undefined behavior or side-effects, even
// if marked readnone nounwind.
- return Callee && Callee->isSpeculatable();
+ if (!Callee || !Callee->isSpeculatable())
+ return false;
+ // Since the operands may be changed after hoisting, undefined behavior may
+ // be triggered by some UB-implying attributes.
+ return IgnoreUBImplyingAttrs || !CI->hasUBImplyingAttrs();
}
case Instruction::VAArg:
case Instruction::Alloca:
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index e55a4b41e4d0..6f858110fb8c 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -532,8 +532,8 @@ void Instruction::dropUBImplyingAttrsAndUnknownMetadata(
if (!CB)
return;
// For call instructions, we also need to drop parameter and return attributes
- // that are can cause UB if the call is moved to a location where the
- // attribute is not valid.
+ // that can cause UB if the call is moved to a location where the attribute is
+ // not valid.
AttributeList AL = CB->getAttributes();
if (AL.isEmpty())
return;
@@ -554,6 +554,20 @@ void Instruction::dropUBImplyingAttrsAndMetadata() {
dropUBImplyingAttrsAndUnknownMetadata(KnownIDs);
}
+bool Instruction::hasUBImplyingAttrs() const {
+ auto *CB = dyn_cast<CallBase>(this);
+ if (!CB)
+ return false;
+ // For call instructions, we also need to check parameter and return
+ // attributes that can cause UB.
+ for (unsigned ArgNo = 0; ArgNo < CB->arg_size(); ArgNo++)
+ if (CB->isPassingUndefUB(ArgNo))
+ return true;
+ return CB->hasRetAttr(Attribute::NoUndef) ||
+ CB->hasRetAttr(Attribute::Dereferenceable) ||
+ CB->hasRetAttr(Attribute::DereferenceableOrNull);
+}
+
bool Instruction::isExact() const {
return cast<PossiblyExactOperator>(this)->isExact();
}
|
[
{
"file": "llvm/test/Transforms/CorrelatedValuePropagation/pr137582.ll",
"commands": [
"opt < %s -passes=correlated-propagation -S"
],
"tests": [
{
"test_name": "test",
"test_body": "define i8 @test(i16 %x) {\nentry:\n %or = or i16 %x, 1\n %conv = trunc i16 %or to i8\n %min = call noundef i8 @llvm.smin.i8(i8 %conv, i8 0)\n %cond = icmp eq i16 %x, 0\n br i1 %cond, label %if.end, label %if.then\n\nif.then: ; preds = %entry\n br label %if.end\n\nif.end: ; preds = %if.then, %entry\n %res = phi i8 [ %min, %entry ], [ 0, %if.then ]\n ret i8 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.smin.i8(i8, i8) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "[CVP] Miscompilation at -O3",
"body": "Reproducer: https://alive2.llvm.org/ce/z/x4KrLX\n```\n\n----------------------------------------\ndefine i8 @func_124(i16 %.promoted) {\nentry:\n %inc20.i = or i16 %.promoted, 1\n %conv.i.i = trunc i16 %inc20.i to i8\n %narrow.i.i.i = smin i8 %conv.i.i, 0\n assume_welldefined i8 %narrow.i.i.i\n %tobool.not.i46 = icmp eq i16 %.promoted, 0\n br i1 %tobool.not.i46, label %func_127.exit, label %land.rhs.i47\n\nland.rhs.i47:\n br label %func_127.exit\n\nfunc_127.exit:\n %conv5.i.i.pn.in = phi i8 [ %narrow.i.i.i, %entry ], [ 0, %land.rhs.i47 ]\n ret i8 %conv5.i.i.pn.in\n}\n=>\ndefine i8 @func_124(i16 %.promoted) {\nentry:\n %inc20.i = or i16 %.promoted, 1\n %conv.i.i = trunc nsw nuw i16 %inc20.i to i8\n %narrow.i.i.i = smin i8 %conv.i.i, 0\n assume_welldefined i8 %narrow.i.i.i\n %tobool.not.i46 = icmp eq i16 %.promoted, 0\n br i1 %tobool.not.i46, label %func_127.exit, label %land.rhs.i47\n\nland.rhs.i47:\n br label %func_127.exit\n\nfunc_127.exit:\n %conv5.i.i.pn.in = phi i8 [ %narrow.i.i.i, %entry ], [ 0, %land.rhs.i47 ]\n %#range_0_%conv5.i.i.pn.in = !range i8 %conv5.i.i.pn.in, i8 128, i8 1\n ret i8 %#range_0_%conv5.i.i.pn.in\n}\nTransformation doesn't verify!\n\nERROR: Source is more defined than target\n\nExample:\ni16 %.promoted = #x0080 (128)\n\nSource:\ni16 %inc20.i = #x0081 (129)\ni8 %conv.i.i = #x81 (129, -127)\ni8 %narrow.i.i.i = #x81 (129, -127)\ni1 %tobool.not.i46 = #x0 (0)\n >> Jump to %land.rhs.i47\n >> Jump to %func_127.exit\ni8 %conv5.i.i.pn.in = #x00 (0)\n\nTarget:\ni16 %inc20.i = #x0081 (129)\ni8 %conv.i.i = poison\ni8 %narrow.i.i.i = poison\nvoid = UB triggered!\n\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```\n",
"author": "dtcxzyw",
"labels": [
"miscompilation",
"llvm:analysis",
"generated by fuzzer"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Related code: https://github.com/llvm/llvm-project/blob/60b3a5b7e7db40ec74d3c4839a3fae8b73d98851/llvm/lib/Analysis/LazyValueInfo.cpp#L1694-L1705"
}
]
}
| true | null |
108700
|
https://github.com/llvm/llvm-project/issues/108700
|
crash
|
4c6f313cb340c435f47ac032857030768c81c341
| 2024-09-14T13:45:54 |
[
"llvm/test/Transforms/SLPVectorizer"
] |
{
"fix_commit": "f564a48f0ea4d2100c0cadfa6e6f20f97244025e",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/include/llvm/IR/Instruction.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
7481,
7487
],
[
7492,
7506
]
],
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::buildTree_rec"
],
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit f564a48f0ea4d2100c0cadfa6e6f20f97244025e
Author: Alexey Bataev <[email protected]>
Date: Mon Sep 16 09:19:42 2024 -0700
[SLP]Fix PR108700: correctly identify id of the operand node
If the operand node for truncs is not created during construction, but
one of the previous ones is reused instead, need to correctly identify
its index, to correctly emit the code.
Fixes https://github.com/llvm/llvm-project/issues/108700
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5f2bf082fb87..282bb8eac7e2 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7481,7 +7481,16 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
PrevMaxBW),
std::min<unsigned>(DL->getTypeSizeInBits(VL0->getType()),
PrevMinBW));
- ExtraBitWidthNodes.insert(VectorizableTree.size() + 1);
+ }
+ TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
+ ReuseShuffleIndices);
+ LLVM_DEBUG(dbgs() << "SLP: added a vector of casts.\n");
+
+ TE->setOperandsInOrder();
+ for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
+ buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
+ if (ShuffleOrOp == Instruction::Trunc) {
+ ExtraBitWidthNodes.insert(getOperandEntry(TE, 0)->Idx);
} else if (ShuffleOrOp == Instruction::SIToFP ||
ShuffleOrOp == Instruction::UIToFP) {
unsigned NumSignBits =
@@ -7492,15 +7501,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
if (NumSignBits * 2 >=
DL->getTypeSizeInBits(VL0->getOperand(0)->getType()))
- ExtraBitWidthNodes.insert(VectorizableTree.size() + 1);
+ ExtraBitWidthNodes.insert(getOperandEntry(TE, 0)->Idx);
}
- TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
- ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of casts.\n");
-
- TE->setOperandsInOrder();
- for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
- buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
return;
}
case Instruction::ICmp:
|
[
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/minbitwidth-user-not-min.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test(ptr %block, ptr noalias %pixels, i1 %b) {\nentry:\n %0 = load i16, ptr %block, align 2\n %tobool.not.i78 = icmp ult i16 %0, 0\n %conv.i80 = sext i1 true to i8\n %conv1.i81 = trunc i16 %0 to i8\n %retval.0.i82 = select i1 %tobool.not.i78, i8 %conv1.i81, i8 %conv.i80\n store i8 %retval.0.i82, ptr %pixels, align 1\n %arrayidx2 = getelementptr i8, ptr %block, i64 2\n %1 = load i16, ptr %arrayidx2, align 2\n %tobool.not.i73 = icmp ult i16 %1, 0\n %conv.i75 = sext i1 %b to i8\n %conv1.i76 = trunc i16 %1 to i8\n %retval.0.i77 = select i1 %tobool.not.i73, i8 %conv1.i76, i8 %conv.i75\n %arrayidx5 = getelementptr i8, ptr %pixels, i64 1\n store i8 %retval.0.i77, ptr %arrayidx5, align 1\n %arrayidx6 = getelementptr i8, ptr %block, i64 4\n %2 = load i16, ptr %arrayidx6, align 2\n %tobool.not.i68 = icmp ult i16 %2, 0\n %conv.i70 = sext i1 false to i8\n %conv1.i71 = trunc i16 %2 to i8\n %retval.0.i72 = select i1 %tobool.not.i68, i8 %conv1.i71, i8 %conv.i70\n %arrayidx9 = getelementptr i8, ptr %pixels, i64 2\n store i8 %retval.0.i72, ptr %arrayidx9, align 1\n %arrayidx10 = getelementptr i8, ptr %block, i64 6\n %3 = load i16, ptr %arrayidx10, align 2\n %tobool.not.i63 = icmp ult i16 %3, 0\n %conv.i65 = sext i1 false to i8\n %conv1.i66 = trunc i16 %3 to i8\n %retval.0.i67 = select i1 %tobool.not.i63, i8 %conv1.i66, i8 %conv.i65\n %arrayidx13 = getelementptr i8, ptr %pixels, i64 3\n store i8 %retval.0.i67, ptr %arrayidx13, align 1\n ret void\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
},
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/trunc-node-reused.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i16 @test() {\nentry:\n %conv73 = xor i64 0, 0\n %and.i = and i64 0, 0\n %xor2.i = or i64 %and.i, 0\n %sub.i = or i64 %xor2.i, 0\n %xor3.i = xor i64 %sub.i, %conv73\n %and4.i = and i64 %xor3.i, 0\n %cmp.i = icmp slt i64 %and4.i, 0\n %0 = trunc i64 %conv73 to i16\n %1 = or i16 0, %0\n %conv73i = xor i64 0, 0\n %andi.i = and i64 0, 0\n %xor2i.i = or i64 %andi.i, 0\n %subi.i = or i64 %xor2i.i, 0\n %xor3i.i = xor i64 %subi.i, %conv73i\n %and4i.i = and i64 %xor3i.i, 0\n %cmpi.i = icmp slt i64 %and4i.i, 0\n %2 = trunc i64 %conv73i to i16\n %3 = or i16 0, %2\n %4 = select i1 %cmpi.i, i16 0, i16 %3\n %5 = select i1 %cmp.i, i16 0, i16 %1\n %6 = zext i32 0 to i64\n %add.ip = or i64 %6, 0\n %orp = or i64 %add.ip, 0\n %conv72p = shl i64 %orp, 0\n %sextp = ashr i64 %conv72p, 0\n %conv73p = xor i64 %sextp, 0\n %and.ip = and i64 0, 0\n %xor2.ip = or i64 %and.ip, 0\n %sub.ip = or i64 %xor2.ip, 0\n %xor3.ip = xor i64 %sub.ip, %conv73p\n %and4.ip = and i64 %xor3.ip, 0\n %cmp.ip = icmp slt i64 %and4.ip, 0\n %7 = trunc i64 %conv73p to i16\n %8 = or i16 0, %7\n %9 = select i1 %cmp.ip, i16 0, i16 %8\n %conv76i = and i16 %4, %5\n %conv76p = and i16 %conv76i, %9\n %10 = zext i32 0 to i64\n %add.ip1 = or i64 %10, 0\n %orp1 = or i64 %add.ip1, 0\n %conv72p1 = shl i64 %orp1, 0\n %sextp1 = ashr i64 %conv72p1, 0\n %conv73p1 = xor i64 %sextp1, 0\n %and.ip1 = and i64 0, 0\n %xor2.ip1 = or i64 %and.ip1, 0\n %sub.ip1 = or i64 %xor2.ip1, 0\n %xor3.ip1 = xor i64 %sub.ip1, %conv73p1\n %and4.ip1 = and i64 %xor3.ip1, 0\n %cmp.ip1 = icmp slt i64 %and4.ip1, 0\n %11 = trunc i64 %conv73p1 to i16\n %12 = or i16 0, %11\n %13 = select i1 %cmp.ip1, i16 0, i16 %12\n %conv76p2 = and i16 %conv76p, %13\n ret i16 %conv76p2\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "[SLPVectorizer] Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.",
"body": "Reproducer: https://godbolt.org/z/8Es17cqcW\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i16 @main() {\r\nentry:\r\n %conv73.i.peel.i.i.i.i.i = xor i64 0, 0\r\n %and.i.i.peel.i.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.peel.i.i.i.i.i = or i64 %and.i.i.peel.i.i.i.i.i, 0\r\n %sub.i.i.peel.i.i.i.i.i = or i64 %xor2.i.i.peel.i.i.i.i.i, 0\r\n %xor3.i.i.peel.i.i.i.i.i = xor i64 %sub.i.i.peel.i.i.i.i.i, %conv73.i.peel.i.i.i.i.i\r\n %and4.i.i.peel.i.i.i.i.i = and i64 %xor3.i.i.peel.i.i.i.i.i, 0\r\n %cmp.i.i.peel.i.i.i.i.i = icmp slt i64 %and4.i.i.peel.i.i.i.i.i, 0\r\n %0 = trunc i64 %conv73.i.peel.i.i.i.i.i to i16\r\n %1 = or i16 0, %0\r\n %conv73.i.i.i.i.i.i = xor i64 0, 0\r\n %and.i.i.i.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.i.i.i.i.i = or i64 %and.i.i.i.i.i.i.i, 0\r\n %sub.i.i.i.i.i.i.i = or i64 %xor2.i.i.i.i.i.i.i, 0\r\n %xor3.i.i.i.i.i.i.i = xor i64 %sub.i.i.i.i.i.i.i, %conv73.i.i.i.i.i.i\r\n %and4.i.i.i.i.i.i.i = and i64 %xor3.i.i.i.i.i.i.i, 0\r\n %cmp.i.i.i.i.i.i.i = icmp slt i64 %and4.i.i.i.i.i.i.i, 0\r\n %2 = trunc i64 %conv73.i.i.i.i.i.i to i16\r\n %3 = or i16 0, %2\r\n %4 = select i1 %cmp.i.i.i.i.i.i.i, i16 0, i16 %3\r\n %5 = select i1 %cmp.i.i.peel.i.i.i.i.i, i16 0, i16 %1\r\n %6 = zext i32 0 to i64\r\n %add.i.i.peel.i369.i.i.i.i = or i64 %6, 0\r\n %or.i.peel.i371.i.i.i.i = or i64 %add.i.i.peel.i369.i.i.i.i, 0\r\n %conv72.i.peel.i372.i.i.i.i = shl i64 %or.i.peel.i371.i.i.i.i, 0\r\n %sext.i.peel.i373.i.i.i.i = ashr i64 %conv72.i.peel.i372.i.i.i.i, 0\r\n %conv73.i.peel.i374.i.i.i.i = xor i64 %sext.i.peel.i373.i.i.i.i, 0\r\n %and.i.i.peel.i376.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.peel.i377.i.i.i.i = or i64 %and.i.i.peel.i376.i.i.i.i, 0\r\n %sub.i.i.peel.i378.i.i.i.i = or i64 %xor2.i.i.peel.i377.i.i.i.i, 0\r\n %xor3.i.i.peel.i379.i.i.i.i = xor i64 %sub.i.i.peel.i378.i.i.i.i, %conv73.i.peel.i374.i.i.i.i\r\n %and4.i.i.peel.i380.i.i.i.i = and i64 %xor3.i.i.peel.i379.i.i.i.i, 0\r\n %cmp.i.i.peel.i381.i.i.i.i = icmp slt i64 %and4.i.i.peel.i380.i.i.i.i, 0\r\n %7 = trunc i64 %conv73.i.peel.i374.i.i.i.i to i16\r\n %8 = or i16 0, %7\r\n %9 = select i1 %cmp.i.i.peel.i381.i.i.i.i, i16 0, i16 %8\r\n %conv76.i.i.i.i.i.i = and i16 %4, %5\r\n %conv76.i.peel.i384.i.i.i.i = and i16 %conv76.i.i.i.i.i.i, %9\r\n %10 = zext i32 0 to i64\r\n %add.i.i.peel.i417.i.i.i.i = or i64 %10, 0\r\n %or.i.peel.i419.i.i.i.i = or i64 %add.i.i.peel.i417.i.i.i.i, 0\r\n %conv72.i.peel.i420.i.i.i.i = shl i64 %or.i.peel.i419.i.i.i.i, 0\r\n %sext.i.peel.i421.i.i.i.i = ashr i64 %conv72.i.peel.i420.i.i.i.i, 0\r\n %conv73.i.peel.i422.i.i.i.i = xor i64 %sext.i.peel.i421.i.i.i.i, 0\r\n %and.i.i.peel.i424.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.peel.i425.i.i.i.i = or i64 %and.i.i.peel.i424.i.i.i.i, 0\r\n %sub.i.i.peel.i426.i.i.i.i = or i64 %xor2.i.i.peel.i425.i.i.i.i, 0\r\n %xor3.i.i.peel.i427.i.i.i.i = xor i64 %sub.i.i.peel.i426.i.i.i.i, %conv73.i.peel.i422.i.i.i.i\r\n %and4.i.i.peel.i428.i.i.i.i = and i64 %xor3.i.i.peel.i427.i.i.i.i, 0\r\n %cmp.i.i.peel.i429.i.i.i.i = icmp slt i64 %and4.i.i.peel.i428.i.i.i.i, 0\r\n %11 = trunc i64 %conv73.i.peel.i422.i.i.i.i to i16\r\n %12 = or i16 0, %11\r\n %13 = select i1 %cmp.i.i.peel.i429.i.i.i.i, i16 0, i16 %12\r\n %conv76.i.peel.i432.i.i.i.i = and i16 %conv76.i.peel.i384.i.i.i.i, %13\r\n ret i16 %conv76.i.peel.i432.i.i.i.i\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3180: llvm::slpvectorizer::BoUpSLP::ValueList& llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int): Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S --passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x0000000005016bb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5016bb8)\r\n #1 0x00000000050142fc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007955e2242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007955e22969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007955e2242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007955e22287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007955e222871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007955e2239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000406f2b8 llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x406f2b8)\r\n #9 0x00000000040f675e llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&)::'lambda0'(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>)::operator()(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>) const SLPVectorizer.cpp:0:0\r\n#10 0x00000000040f74aa llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40f74aa)\r\n#11 0x0000000004114641 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4114641)\r\n#12 0x00000000041198c8 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000411bfe1 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x411bfe1)\r\n#14 0x0000000004120876 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#15 0x0000000004124e16 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4124e16)\r\n#16 0x000000000412b2e1 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000412bf6b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x412bf6b)\r\n#18 0x0000000002f0034e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f0034e)\r\n#19 0x0000000004e18ff8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e18ff8)\r\n#20 0x0000000000e06a0e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe06a0e)\r\n#21 0x0000000004e17a1e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e17a1e)\r\n#22 0x0000000000e0621e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe0621e)\r\n#23 0x0000000004e17450 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e17450)\r\n#24 0x00000000008fce52 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce52)\r\n#25 0x00000000008efcdc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8efcdc)\r\n#26 0x00007955e2229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007955e2229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008e77ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e77ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```",
"author": "dtcxzyw",
"labels": [
"llvm:SLPVectorizer",
"crash-on-valid"
],
"comments": []
}
| true | null |
82243
|
https://github.com/llvm/llvm-project/issues/82243
|
miscompilation
|
fcd6549e5801de938935b93fd2d13020b42eebdb
| 2024-02-19T12:48:24 |
[
"llvm/test/Transforms/IndVarSimplify"
] |
{
"fix_commit": "4db93e5d56440be44d8ad2036e2579208c82ad37",
"components": [
"ScalarEvolution",
"SimplifyIndVar"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/include/llvm/IR/Instruction.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": [
[
258,
263
]
],
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [
[
771,
776
]
],
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [
[
1131,
1137
],
[
1731,
1737
],
[
1825,
1835
],
[
1996,
2006
],
[
2024,
2030
]
],
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [
"SCEVExpander::hoistIVInc"
],
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [
"WidenIV::createWideIV",
"WidenIV::widenIVUse"
],
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit 4db93e5d56440be44d8ad2036e2579208c82ad37
Author: Florian Hahn <[email protected]>
Date: Tue Feb 20 14:03:25 2024 +0000
[IndVars] Recompute flags if needed in widenIVUse of IV increment. (#82352)
widenIVUse may hoist a wide induction increment and introduce new uses,
but does not recompute the wrap flags. In some cases this can make the
new uses of the wide IV inc more poisonous.
Update the code to recompute flags if needed when hoisting an IV. If
both the narrow and wide IV increment's flags match and we can re-use
the flags from the increments, there's no need to recompute the flags,
as the replacement won't make the new uses of the wide IV's increment
more poisonous.
Note that this also updates a stale comment which claimed that the widen
increment is only used if it dominates the new use.
The helper should also be used to guard the code added in da437330be,
which I am planning on doing separately once the helper lands.
Fixes https://github.com/llvm/llvm-project/issues/82243.
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index 035705b7f4b7..fa10443f14bb 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -258,6 +258,14 @@ public:
bool hoistIVInc(Instruction *IncV, Instruction *InsertPos,
bool RecomputePoisonFlags = false);
+ /// Return true if both increments directly increment the corresponding IV PHI
+ /// nodes and have the same opcode. It is not safe to re-use the flags from
+ /// the original increment, if it is more complex and SCEV expansion may have
+ /// yielded a more simplified wider increment.
+ static bool canReuseFlagsFromOriginalIVInc(PHINode *OrigPhi, PHINode *WidePhi,
+ Instruction *OrigInc,
+ Instruction *WideInc);
+
/// replace congruent phis with their most canonical representative. Return
/// the number of phis eliminated.
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 3a28909473d9..fbe1dba5b8d4 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -771,6 +771,15 @@ bool SCEVExpander::hoistIVInc(Instruction *IncV, Instruction *InsertPos,
return true;
}
+bool SCEVExpander::canReuseFlagsFromOriginalIVInc(PHINode *OrigPhi,
+ PHINode *WidePhi,
+ Instruction *OrigInc,
+ Instruction *WideInc) {
+ return match(OrigInc, m_c_BinOp(m_Specific(OrigPhi), m_Value())) &&
+ match(WideInc, m_c_BinOp(m_Specific(WidePhi), m_Value())) &&
+ OrigInc->getOpcode() == WideInc->getOpcode();
+}
+
/// Determine if this cyclic phi is in a form that would have been generated by
/// LSR. We don't care if the phi was actually expanded in this pass, as long
/// as it is in a low-cost form, for example, no implied multiplication. This
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 5aa6df49e7f6..66bba1ca2f1d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1131,7 +1131,8 @@ protected:
const SCEV *getSCEVByOpCode(const SCEV *LHS, const SCEV *RHS,
unsigned OpCode) const;
- Instruction *widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter);
+ Instruction *widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter,
+ PHINode *OrigPhi, PHINode *WidePhi);
bool widenLoopCompare(NarrowIVDefUse DU);
bool widenWithVariantUse(NarrowIVDefUse DU);
@@ -1731,7 +1732,9 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
/// Determine whether an individual user of the narrow IV can be widened. If so,
/// return the wide clone of the user.
-Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU, SCEVExpander &Rewriter) {
+Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU,
+ SCEVExpander &Rewriter, PHINode *OrigPhi,
+ PHINode *WidePhi) {
assert(ExtendKindMap.count(DU.NarrowDef) &&
"Should already know the kind of extension used to widen NarrowDef");
@@ -1825,11 +1828,18 @@ Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU, SCEVExpander &Rewri
if (!WideAddRec.first)
return nullptr;
- // Reuse the IV increment that SCEVExpander created as long as it dominates
- // NarrowUse.
+ // Reuse the IV increment that SCEVExpander created. Recompute flags, unless
+ // the flags for both increments agree and it is safe to use the ones from
+ // the original inc. In that case, the new use of the wide increment won't
+ // be more poisonous.
+ bool NeedToRecomputeFlags =
+ !SCEVExpander::canReuseFlagsFromOriginalIVInc(OrigPhi, WidePhi,
+ DU.NarrowUse, WideInc) ||
+ DU.NarrowUse->hasNoUnsignedWrap() != WideInc->hasNoUnsignedWrap() ||
+ DU.NarrowUse->hasNoSignedWrap() != WideInc->hasNoSignedWrap();
Instruction *WideUse = nullptr;
if (WideAddRec.first == WideIncExpr &&
- Rewriter.hoistIVInc(WideInc, DU.NarrowUse))
+ Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags))
WideUse = WideInc;
else {
WideUse = cloneIVUser(DU, WideAddRec.first);
@@ -1996,11 +2006,9 @@ PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) {
// the same opcode. It is not safe to re-use the flags from the original
// increment, if it is more complex and SCEV expansion may have yielded a
// more simplified wider increment.
- bool MatchingOps =
- match(OrigInc, m_c_BinOp(m_Specific(OrigPhi), m_Value())) &&
- match(WideInc, m_c_BinOp(m_Specific(WidePhi), m_Value())) &&
- OrigInc->getOpcode() == WideInc->getOpcode();
- if (MatchingOps && isa<OverflowingBinaryOperator>(OrigInc) &&
+ if (SCEVExpander::canReuseFlagsFromOriginalIVInc(OrigPhi, WidePhi,
+ OrigInc, WideInc) &&
+ isa<OverflowingBinaryOperator>(OrigInc) &&
isa<OverflowingBinaryOperator>(WideInc)) {
WideInc->setHasNoUnsignedWrap(WideInc->hasNoUnsignedWrap() ||
OrigInc->hasNoUnsignedWrap());
@@ -2024,7 +2032,7 @@ PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) {
// Process a def-use edge. This may replace the use, so don't hold a
// use_iterator across it.
- Instruction *WideUse = widenIVUse(DU, Rewriter);
+ Instruction *WideUse = widenIVUse(DU, Rewriter, OrigPhi, WidePhi);
// Follow all def-use edges from the previous narrow use.
if (WideUse)
|
[
{
"file": "llvm/test/Transforms/IndVarSimplify/hoist-wide-inc-for-narrow-use-recompute-flags.ll",
"commands": [
"opt -p indvars -S %s"
],
"tests": [
{
"test_name": "test_pr82243",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_pr82243(ptr %f) {\nentry:\n br label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %outer.latch ]\n %iv.sext = sext i32 %iv to i64\n %gep.iv.ext = getelementptr i32, ptr %f, i64 %iv.sext\n store i32 1, ptr %gep.iv.ext, align 4\n %sub = add i32 %iv, -1\n %shl = shl i32 123, %sub\n %gep.shl = getelementptr i32, ptr %f, i32 %shl\n br label %inner.header\n\ninner.header: ; preds = %inner.latch, %outer.header\n store i32 0, ptr %gep.shl, align 4\n br i1 false, label %inner.latch, label %exit\n\ninner.latch: ; preds = %inner.header\n br i1 false, label %inner.header, label %outer.latch\n\nouter.latch: ; preds = %inner.latch\n %iv.next = add i32 %iv, -1\n br label %outer.header\n\nexit: ; preds = %inner.header\n ret void\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "Wrong code at -Os on x86-64_gnu-linux (recent regression)",
"body": "Clang at -Os produced the wrong code.\r\n\r\nBisected to dce77a357948709e335910ddc07f9c3f2eb2ac4b, which was committed by @fhahn \r\n\r\nCompiler explorer: https://godbolt.org/z/fTrenPK4h\r\n\r\n```console\r\n% cat reduced.c\r\nint printf(const char *, ...);\r\nint a, b, c, d, e;\r\nint f[9];\r\nint g(int i) {\r\n c = 1 << i;\r\n if (b & c)\r\n return 4;\r\n return 0;\r\n}\r\nint j(int i) {\r\n int h = g(i);\r\n return h;\r\n}\r\nint k() {\r\n d = 6;\r\n for (; d; d--) {\r\n e = 0;\r\n for (; e <= 6; e++) {\r\n f[j(d - 1)] = f[d];\r\n for (; e + d;)\r\n return 0;\r\n }\r\n }\r\n return 0;\r\n}\r\nint main() {\r\n k();\r\n printf(\"%d\\n\", a);\r\n}\r\n%\r\n% clang -O3 reduced.c && ./a.out\r\n0\r\n% clang -Os reduced.c && ./a.out\r\n\r\n%\r\n```",
"author": "shao-hua-li",
"labels": [
"miscompilation",
"llvm:SCEV"
],
"comments": [
{
"author": "fhahn",
"body": "The issue is that IndVars doesn't drop poison-generating flags when hoisting the IV to introduce a new use of the widened IV. working on a fix"
},
{
"author": "fhahn",
"body": "Should be fixed, thanks again as always @shao-hua-li "
},
{
"author": "shao-hua-li",
"body": "You're welcome @fhahn "
}
]
}
| true | null |
116553
|
https://github.com/llvm/llvm-project/issues/116553
|
miscompilation
|
c25e09e238c6f872a116d10bbefba0beff145a57
| 2024-11-17T18:49:16 |
[
"llvm/test/Transforms/ConstraintElimination"
] |
{
"fix_commit": "52361d0368b79841be12156bf03cf8c1851e5df7",
"components": [
"ConstraintElimination"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/include/llvm/IR/Instruction.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [
[
1034,
1042
],
[
1044,
1051
]
],
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null,
"llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/include/llvm/Transforms/Utils/Evaluator.h": null,
"llvm/lib/Transforms/Utils/Evaluator.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/IR/Instruction.cpp": null,
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [
"State::addInfoForInductions"
],
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null,
"llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null,
"llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null,
"llvm/lib/Analysis/VectorUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/Scalar/LoopFuse.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/IPO/GlobalOpt.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null
}
}
|
commit 52361d0368b79841be12156bf03cf8c1851e5df7
Author: Yingwei Zheng <[email protected]>
Date: Mon Nov 18 23:41:04 2024 +0800
[ConstraintElim] Bail out on non-dedicated exits when adding exiting conditions (#116627)
This patch bails out non-dedicated exits to avoid adding exiting
conditions to invalid context.
Closes https://github.com/llvm/llvm-project/issues/116553.
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index d2e532d29d07..64433cb9216c 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1034,9 +1034,9 @@ void State::addInfoForInductions(BasicBlock &BB) {
DTN, CmpInst::ICMP_SLT, PN, B,
ConditionTy(CmpInst::ICMP_SLE, StartValue, B)));
- // Try to add condition from header to the exit blocks. When exiting either
- // with EQ or NE in the header, we know that the induction value must be u<=
- // B, as other exits may only exit earlier.
+ // Try to add condition from header to the dedicated exit blocks. When exiting
+ // either with EQ or NE in the header, we know that the induction value must
+ // be u<= B, as other exits may only exit earlier.
assert(!StepOffset.isNegative() && "induction must be increasing");
assert((Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE) &&
"unsupported predicate");
@@ -1044,8 +1044,11 @@ void State::addInfoForInductions(BasicBlock &BB) {
SmallVector<BasicBlock *> ExitBBs;
L->getExitBlocks(ExitBBs);
for (BasicBlock *EB : ExitBBs) {
- WorkList.emplace_back(FactOrCheck::getConditionFact(
- DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
+ // Bail out on non-dedicated exits.
+ if (DT.dominates(&BB, EB)) {
+ WorkList.emplace_back(FactOrCheck::getConditionFact(
+ DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond));
+ }
}
}
|
[
{
"file": "llvm/test/Transforms/ConstraintElimination/induction-condition-in-loop-exit.ll",
"commands": [
"opt -p constraint-elimination -S %s"
],
"tests": [
{
"test_name": "test_non_dedicated_exit",
"test_body": "define i1 @test_non_dedicated_exit(i16 %n) {\nentry:\n %cond = icmp slt i16 %n, 1\n br i1 %cond, label %exit, label %loop.preheader\n\nloop.preheader: ; preds = %entry\n %sub = add nsw i16 %n, -1\n %ext = zext nneg i16 %sub to i32\n br label %loop\n\nloop: ; preds = %loop.latch, %loop.preheader\n %indvar = phi i32 [ %indvar.inc, %loop.latch ], [ 0, %loop.preheader ]\n %exitcond = icmp eq i32 %indvar, %ext\n br i1 %exitcond, label %exit, label %loop.latch\n\nloop.latch: ; preds = %loop\n %indvar.inc = add nuw nsw i32 %indvar, 1\n br label %loop\n\nexit: ; preds = %loop, %entry\n %cmp = icmp sgt i16 %n, 0\n ret i1 %cmp\n}\n",
"additional_args": null,
"lli_expected_out": null
}
]
}
] |
{
"title": "[clang] Miscompile at O3 with SIGKILL",
"body": "When I compiled this code with O3, it triggered SIGKILL. With O0/1/2, it returned 0.\r\n\r\nBisected to https://github.com/llvm/llvm-project/commit/5b927130b0e15a442a6ed171f43a612e6a40bbcd, which was committed by @fhahn \r\n\r\nCompiler Explorer: https://godbolt.org/z/q9j75feYG\r\n\r\nCode:\r\n```c\r\nint printf(const char *, ...);\r\nint a, c, d;\r\nint *b;\r\nchar e;\r\nshort f;\r\nint g(int i) {\r\n if (i <= 0)\r\n return 1;\r\n int h = 0;\r\n for (; h < i - 1; h++) {\r\n for (; d - h - 1;)\r\n if (c)\r\n b[d] = e = 1;\r\n if (e)\r\n break;\r\n }\r\n return 0;\r\n}\r\nvoid j() { g(f); }\r\nint main(int i, char *k[]) {\r\n j();\r\n while (0 < f)\r\n ;\r\n printf(\"%X\\n\", a);\r\n}\r\n```",
"author": "cardigan1008",
"labels": [
"miscompilation",
"confirmed",
"llvm:transforms"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reproducer: https://alive2.llvm.org/ce/z/fLN5gw\r\n```\r\n; bin/opt -passes=constraint-elimination test.ll -S\r\ndefine i1 @test(i16 %n) {\r\nentry:\r\n %cond = icmp slt i16 %n, 1\r\n br i1 %cond, label %exit, label %loop.preheader\r\n\r\nloop.preheader:\r\n %sub = add nsw i16 %n, -1\r\n %ext = zext nneg i16 %sub to i32\r\n br label %loop\r\n\r\nloop:\r\n %indvar = phi i32 [ %indvar.inc, %loop.latch ], [ 0, %loop.preheader ]\r\n %12 = icmp eq i32 %indvar, %ext\r\n br i1 %12, label %exit, label %loop.latch\r\n\r\nloop.latch:\r\n %indvar.inc = add nuw nsw i32 %indvar, 1\r\n br label %loop\r\n\r\nexit:\r\n %cmp = icmp sgt i16 %n, 0\r\n ret i1 %cmp\r\n}\r\n\r\n```\r\nI will post a fix later.\r\n"
}
]
}
| true | null |
122584
|
https://github.com/llvm/llvm-project/issues/122584
|
crash
|
34ba84fe90b3e369c03e695a395ec632ef60e23d
| 2025-01-11T08:32:25 |
[
"llvm/test/Transforms/SLPVectorizer"
] | {"fix_commit":"af524de1fa94e4b4cee8b745d1b68f4ea0090759","components":["SLPVectorizer"],"bug_locatio(...TRUNCATED) | "commit af524de1fa94e4b4cee8b745d1b68f4ea0090759\nAuthor: Alexey Bataev <[email protected]>\nDate(...TRUNCATED) | [{"file":"llvm/test/Transforms/SLPVectorizer/AArch64/vectorizable-selects-uniform-cmps.ll","commands(...TRUNCATED) | {"title":"clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `I1 == PoisonMaskE(...TRUNCATED) | true | null |
142447
|
https://github.com/llvm/llvm-project/issues/142447
|
crash
|
4b2cb118bc5825c309724d536053c6f9817e2eb9
| 2025-06-02T17:50:28 |
[
"llvm/test/Transforms/InstSimplify"
] | {"fix_commit":"d9a5f7b118bfc9ab4b7325fae25073729d8e08be","components":["IR"],"bug_location_lineno":{(...TRUNCATED) | "commit d9a5f7b118bfc9ab4b7325fae25073729d8e08be\nAuthor: Yingwei Zheng <[email protected]>\nDat(...TRUNCATED) | [{"file":"llvm/test/Transforms/InstSimplify/compare.ll","commands":["opt < %s -passes=instcombine<no(...TRUNCATED) | {"title":"[InstCombine] ICmp i1 X, C not simplified as expected. with opt \"-passes=lto<O3>\"","body(...TRUNCATED) | true | null |
118030
|
https://github.com/llvm/llvm-project/issues/118030
|
crash
|
6f4b4f41ca41d7d0b44a32d9968aef7667c68184
| 2024-11-28T19:14:48 |
[
"llvm/test/Transforms/SLPVectorizer"
] | {"fix_commit":"f4974e09312afc9549fcfc0304b738d235da9eca","components":["SLPVectorizer"],"bug_locatio(...TRUNCATED) | "commit f4974e09312afc9549fcfc0304b738d235da9eca\nAuthor: Alexey Bataev <[email protected]>\nDate(...TRUNCATED) | [{"file":"llvm/test/Transforms/SLPVectorizer/X86/ashr-node-with-poison.ll","commands":["opt -S --pas(...TRUNCATED) | {"title":"clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `isa<To>(Val) && \(...TRUNCATED) | true | null |
LLVM APR Benchmark: A Large-Scale Automated Program Repair Benchmark of Real-World LLVM Middle-End Bugs
GitHub (We only accept pull requests from GitHub)
Motivation
The compiler is a critical infrastructure in the software development. The LLVM compiler infrastructure is widely used in both academia and industry. However, due to its inherent complexity, the LLVM compiler still contains many bugs that can be triggered in edge cases. As one of the LLVM maintainers, my job is to provide the minimal reproducible test cases for issues from fuzzers/ downstream users, and fix these bugs (or assign them to the right person). However, the process is time-consuming and boring. Thanks to the recent advances in compiler testing, we can automatically generate interesting test cases that trigger bugs and automatically reduce the tests to minimal ones. If we can also perform bug localization and repair automatically, it will significantly reduce the workload of us maintainers! Recently, LLM-based automated program repair (APR) techniques have been proposed. We have seen some successful cases in APR benchmarks like Defects4J and SWE-bench. But I believe that fixing LLVM bugs is more challenging than existing benchmarks due to its large C/C++ codebase, complex logic, long history, and the need for domain-specific knowledge. Therefore, I build this benchmark to see if we can automatically repair real-world LLVM bugs with the help of large language models and APR techniques. I hope this benchmark can help both SE researchers and LLVM community to understand how APR techniques work on a large-scale, real-world C/C++ project.
Dataset Description
In this benchmark, we only focus on three kinds of bugs in the LLVM middle-end:
- Crash: the compiler terminates exceptionally or hits an assertion failure (LLVM is built with
-DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ABI_BREAKING_CHECKS=WITH_ASSERTS
). - Miscompilation: the compiler generates incorrect program from a well-defined source code.
- Hang: the compiler runs into an infinite loop or fails to reach a fixpoint.
All bugs can be triggered with an opt
command and a small piece of LLVM textual IR.
This dataset collects some fixed LLVM middle-end bugs from GitHub issues since 2024-01-01. Each issue contains issue description, test cases, a reference patch, and some hints. All issues are checked against the following criteria:
- At least one of the given test cases can be used to reproduce the bug at a specific commit (
base_commit
). For most of the miscompilation bugs, thesrc
andtgt
functions will be checked with alive2, an automatic refinement verification tool for LLVM. If miscompilation happens,alive-tv
will provide a counterexample. The remaining miscompilation bugs will be checked bylli
. opt
passes all the given tests after fixing the bug with the given reference patch (patch
).opt
passes all regression tests at a specific commit (hints.fix_commit
).
Take Issue121459 as an example:
{
// Identifier of the bug. It can be an issue number, a pull request number,
// or a commit hash.
"bug_id": "121459",
// Points to issue/PR/commit url
"issue_url": "https://github.com/llvm/llvm-project/issues/121459",
// Bug type: crash/miscompilation/hang
"bug_type": "miscompilation",
// Fixes should be applied at the base commit
"base_commit": "68d265666e708bad1c63b419b6275aaba1a7dcd2",
// Knowledge cutoff date. It is not allowed to use the web knowledge base
// after this date or use a large language model trained with newer
// information. Please check the "Rules" section for exemptions.
"knowledge_cutoff": "2025-01-02T09:03:32Z",
// Regression test directories
"lit_test_dir": [
"llvm/test/Transforms/InstCombine"
],
// Bug localization hints at different granularity levels.
// Note that this information is provided in a best-effort way.
// They are not guaranteed to be available or accurate.
"hints": {
"fix_commit": "a4d92400a6db9566d84cb4b900149e36e117f452",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [
[
2782,
2787
],
[
2838,
2843
],
[
2847,
2852
]
]
},
"bug_location_funcname": {
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [
"foldGEPOfPhi"
]
}
},
// A reference patch extracted from hints.fix_commit
"patch": "<omitted>",
// Minimal reproducible tests
"tests": [
{
"file": "llvm/test/Transforms/InstCombine/opaque-ptr.ll",
"commands": [
"opt -S -passes='instcombine<no-verify-fixpoint>' < %s"
],
"tests": [
{
"test_name": "gep_of_phi_of_gep_different_type",
"test_body": "<omitted>"
},
{
"test_name": "gep_of_phi_of_gep_flags2",
"test_body": "<omitted>"
},
{
"test_name": "gep_of_phi_of_gep_flags1",
"test_body": "<omitted>"
}
]
}
],
// Issue description
"issue": {
"title": "[InstCombine] GEPNoWrapFlags is propagated incorrectly",
"body": "<omitted>",
"author": "dtcxzyw",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": []
},
"verified": true
}
As of May 19, 2025, this benchmark contains 295 issues. You can run python3 scripts/dataset_summary.py
locally to obtain the latest statistics.
Total issues: 295
Verified issues: 295 (100.00%)
Bug type summary:
miscompilation: 106
crash: 181
hang: 8
Bug component summary (Total = 50):
SLPVectorizer: 73
LoopVectorize: 71
InstCombine: 54
ScalarEvolution: 15
VectorCombine: 11
ValueTracking: 8
IR: 6
ConstraintElimination: 5
InstructionSimplify: 5
SimplifyIndVar: 4
Local: 4
LoopAccessAnalysis: 3
LoopPeel: 3
MemCpyOptimizer: 3
DeadStoreElimination: 3
MemorySSAUpdater: 3
...
Label summary:
crash: 111
miscompilation: 108
vectorizers: 81
llvm:SLPVectorizer: 73
crash-on-valid: 61
llvm:instcombine: 57
llvm:transforms: 40
llvm:analysis: 22
release:backport: 16
llvm:SCEV: 16
generated by fuzzer: 13
confirmed: 9
llvm:crash: 8
regression: 7
llvm:hang: 6
...
Changed files count summary:
Average: 1.17
Max: 5
Min: 1
Median: 1
Inserted lines summary:
Average: 10.71
Max: 164
Min: 0
Median: 6
Deleted lines summary:
Average: 5.55
Max: 169
Min: 0
Median: 2
Test count summary:
Average: 3.59
Max: 107
Min: 1
Median: 1
Patch summary:
Single file fix: 264 (89.49%)
Single func fix: 227 (76.95%)
Single hunk fix: 168 (56.95%)
You can see from the statistics that more than half of the bugs can be fixed with a single hunk. So I believe most of bugs can be fixed with the aid of LLM-based APR techniques :)
Getting Started
Prerequisites
- A C++17 compatible compiler
- ninja
- ccache
- Pre-built LLVM core libraries
- alive-tv
You can follow the Dockerfile to setup the environment.
Installation
git clone https://github.com/dtcxzyw/llvm-apr-benchmark.git
cd llvm-apr-benchmark
pip3 install -r requirements.txt
mkdir -p work && cd work
git clone https://github.com/llvm/llvm-project.git
Please set the following environment variables:
export LAB_LLVM_DIR=<path-to-llvm-src>
export LAB_LLVM_BUILD_DIR=<path-to-llvm-build-dir>
export LAB_LLVM_ALIVE_TV=<path-to-alive-tv>
export LAB_DATASET_DIR=<path-to-llvm-apr-benchmark>/dataset
export LAB_FIX_DIR=<path-to-llvm-apr-benchmark>/examples/fixes
Usage
This benchmark provides two helper modules to allow researchers to easily interact with LLVM and this benchmark.
To use these two helpers:
sys.path.append(os.path.join(os.path.dirname(os.environ["LAB_DATASET_DIR"]), "scripts"))
import llvm_helper
from lab_env import Environment as Env
# Environment variables
llvm_helper.llvm_dir # os.environ["LAB_LLVM_DIR"]
llvm_helper.llvm_build_dir # os.environ["LAB_LLVM_BUILD_DIR"]
llvm_helper.llvm_alive_tv # os.environ["LAB_LLVM_ALIVE_TV"]
llvm_helper.dataset_dir # os.environ["LAB_DATASET_DIR"]
# Execute git commands on the llvm source tree
source_code = llvm_helper.git_execute(['show', f'{commit}:{file_path}'])
# Get information of first failed test from the result of Environment.check_fast/check_full
res, log = env.check_fast()
if isinstance(log, list):
test = llvm_helper.get_first_failed_test(log)
env = Env(
# Load an issue from dataset/{issue_id}.json
issue_id,
# The knowledge cutoff date of LLM
base_model_knowledge_cutoff = "2024-01-01Z",
# Max concurrent jobs for build/test
max_build_jobs=None,
max_test_jobs=None,
)
# If any external knowledge is used, please call this function.
env.use_knowledge(url = "<url>", date = "<date>")
# Reset the source tree to the base commit. Please call it before each attempt.
env.reset()
# Build llvm
res, log = env.build()
# Provide a certificate with the patch and verification result
certificate = env.dump()
# Perform build + test
res, log = env.check_fast()
# Perform build + test + lit regression test
res, log = env.check_full()
# Issue information (always available)
bug_type = env.get_bug_type()
base_commit = env.get_base_commit()
tests = env.get_tests()
# Hints (optional)
fix_commit = env.get_hint_fix_commit()
components = env.get_hint_components()
files = env.get_hint_files()
functions = env.get_hint_bug_functions()
linenos = env.get_hint_line_level_bug_locations()
# Issue description (optional)
issue = env.get_hint_issue()
# Collect instructions and intrinsics from the given LLVM IR.
# Then it will retrieve descriptions from llvm/docs/LangRef.dst.
# It is useful for LLMs to understand new flags/attributes/metadata.
keywords = env.get_ir_keywords(llvm_ir)
desc = env.get_langref_desc(keywords)
Here is a simple repair loop:
env = Env(...)
# System prompts and user prompts
messages = []
while True:
# Reset the LLVM source code tree
env.reset()
# Get information from env
...
# Chat with LLM
...
# Modify the source code in place
...
res, log = env.check_full()
if res:
# The bug is fixed successfully
cert = json.dumps(env.dump(log = messages), indent=2)
print(cert)
break
# Append the feedback into user prompts for the next iteration
messages.append(construct_user_prompt_from_feedback(log))
I have drafted a poor baseline which is powered by DeepSeek-R1. This baseline implementation is only for reference purposes since I am neither an expert in LLM nor APR.
Rules
To claim that your APR tool successfully fixes a bug, please obey the following rules:
- Knowledge allowed to use:
- Any static content/ dynamic feedback provided by
lab_env.Environment
- Any content in the LLVM source tree before the base commit
- Large language model trained with dataset before the knowledge cutoff date
- Any other content on the web created before the knowledge cutoff date
- Any static content/ dynamic feedback provided by
opt
with this patch passes both the given tests and the regression testsuite.
License
This project is licensed under the Apache License 2.0. Please see the LICENSE for details.
Please cite this work with the following BibTex entry:
@misc{llvm-apr-benchmark,
title = {LLVM APR Benchmark: A Large-Scale Automated Program Repair Benchmark of Real-World LLVM Middle-End Bugs},
url = {https://github.com/dtcxzyw/llvm-apr-benchmark},
author = {Yingwei Zheng},
year = {2025},
}
- Downloads last month
- 1,541