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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [ [ 102, 107 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ [ 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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ [ 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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7481, 7487 ], [ 7492, 7506 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": [ "SCEVExpander::hoistIVInc" ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [ "WidenIV::createWideIV", "WidenIV::widenIVUse" ], "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ "State::addInfoForInductions" ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.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_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 14935, 14942 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::processBuildVector" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit af524de1fa94e4b4cee8b745d1b68f4ea0090759 Author: Alexey Bataev <[email protected]> Date: Mon Jan 13 06:48:56 2025 -0800 [SLP]Do not include subvectors for fully matched buildvectors If the buildvector node fully matched another node, need to exclude subvectors, when building final shuffle, just a shuffle of the original node must be emitted. Fixes #122584 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index e3487b501534..df46c69ff3ab 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14935,8 +14935,8 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Type *ScalarTy, } } ShuffleBuilder.add(*FrontTE, Mask); - Res = ShuffleBuilder.finalize(E->getCommonMask(), SubVectors, - SubVectorsMask); + // Full matched entry found, no need to insert subvectors. + Res = ShuffleBuilder.finalize(E->getCommonMask(), {}, {}); return Res; } if (!Resized) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/AArch64/vectorizable-selects-uniform-cmps.ll", "commands": [ "opt -passes=slp-vectorizer -S %s", "opt -aa-pipeline=basic-aa -passes='slp-vectorizer' -S %s" ], "tests": [ { "test_name": "select_uniform_ugt_16xi8", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-ios5.0.0\"\n\ndefine void @select_uniform_ugt_16xi8(ptr %ptr, i8 %x) {\nentry:\n %l.0 = load i8, ptr %ptr, align 1\n %cmp.0 = icmp ugt i8 %l.0, -1\n %s.0 = select i1 %cmp.0, i8 %l.0, i8 %x\n store i8 %s.0, ptr %ptr, align 2\n %gep.1 = getelementptr inbounds i8, ptr %ptr, i8 1\n %l.1 = load i8, ptr %gep.1, align 1\n %cmp.1 = icmp ugt i8 %l.1, -1\n %s.1 = select i1 %cmp.1, i8 %l.1, i8 %x\n store i8 %s.1, ptr %gep.1, align 2\n %gep.2 = getelementptr inbounds i8, ptr %ptr, i8 2\n %l.2 = load i8, ptr %gep.2, align 1\n %cmp.2 = icmp ugt i8 %l.2, -1\n %s.2 = select i1 %cmp.2, i8 %l.2, i8 %x\n store i8 %s.2, ptr %gep.2, align 2\n %gep.3 = getelementptr inbounds i8, ptr %ptr, i8 3\n %l.3 = load i8, ptr %gep.3, align 1\n %cmp.3 = icmp ugt i8 %l.3, -1\n %s.3 = select i1 %cmp.3, i8 %l.3, i8 %x\n store i8 %s.3, ptr %gep.3, align 2\n %gep.4 = getelementptr inbounds i8, ptr %ptr, i8 4\n %l.4 = load i8, ptr %gep.4, align 1\n %cmp.4 = icmp ugt i8 %l.4, -1\n %s.4 = select i1 %cmp.4, i8 %l.4, i8 %x\n store i8 %s.4, ptr %gep.4, align 2\n %gep.5 = getelementptr inbounds i8, ptr %ptr, i8 5\n %l.5 = load i8, ptr %gep.5, align 1\n %cmp.5 = icmp ugt i8 %l.5, -1\n %s.5 = select i1 %cmp.5, i8 %l.5, i8 %x\n store i8 %s.5, ptr %gep.5, align 2\n %gep.6 = getelementptr inbounds i8, ptr %ptr, i8 6\n %l.6 = load i8, ptr %gep.6, align 1\n %cmp.6 = icmp ugt i8 %l.6, -1\n %s.6 = select i1 %cmp.6, i8 %l.6, i8 %x\n store i8 %s.6, ptr %gep.6, align 2\n %gep.7 = getelementptr inbounds i8, ptr %ptr, i8 7\n %l.7 = load i8, ptr %gep.7, align 1\n %cmp.7 = icmp ugt i8 %l.7, -1\n %s.7 = select i1 %cmp.7, i8 %l.7, i8 %x\n store i8 %s.7, ptr %gep.7, align 2\n %gep.8 = getelementptr inbounds i8, ptr %ptr, i8 8\n %l.8 = load i8, ptr %gep.8, align 1\n %cmp.8 = icmp ugt i8 %l.8, -1\n %s.8 = select i1 %cmp.8, i8 %l.0, i8 %x\n store i8 %s.0, ptr %gep.8, align 2\n %gep.9 = getelementptr inbounds i8, ptr %ptr, i8 9\n %l.9 = load i8, ptr %gep.9, align 1\n %cmp.9 = icmp ugt i8 %l.9, -1\n %s.9 = select i1 %cmp.9, i8 %l.9, i8 %x\n store i8 %s.9, ptr %gep.9, align 2\n %gep.10 = getelementptr inbounds i8, ptr %ptr, i8 10\n %l.10 = load i8, ptr %gep.10, align 1\n %cmp.10 = icmp ugt i8 %l.10, -1\n %s.10 = select i1 %cmp.10, i8 %l.10, i8 %x\n store i8 %s.10, ptr %gep.10, align 2\n %gep.11 = getelementptr inbounds i8, ptr %ptr, i8 11\n %l.11 = load i8, ptr %gep.11, align 1\n %cmp.11 = icmp ugt i8 %l.11, -1\n %s.11 = select i1 %cmp.11, i8 %l.11, i8 %x\n store i8 %s.11, ptr %gep.11, align 2\n %gep.12 = getelementptr inbounds i8, ptr %ptr, i8 12\n %l.12 = load i8, ptr %gep.12, align 1\n %cmp.12 = icmp ugt i8 %l.12, -1\n %s.12 = select i1 %cmp.12, i8 %l.12, i8 %x\n store i8 %s.12, ptr %gep.12, align 2\n %gep.13 = getelementptr inbounds i8, ptr %ptr, i8 13\n %l.13 = load i8, ptr %gep.13, align 1\n %cmp.13 = icmp ugt i8 %l.13, -1\n %s.13 = select i1 %cmp.13, i8 %l.13, i8 %x\n store i8 %s.13, ptr %gep.13, align 2\n %gep.14 = getelementptr inbounds i8, ptr %ptr, i8 14\n %l.14 = load i8, ptr %gep.14, align 1\n %cmp.14 = icmp ugt i8 %l.14, -1\n %s.14 = select i1 %cmp.14, i8 %l.14, i8 %x\n store i8 %s.14, ptr %gep.14, align 2\n %gep.15 = getelementptr inbounds i8, ptr %ptr, i8 15\n %l.15 = load i8, ptr %gep.15, align 1\n %cmp.15 = icmp ugt i8 %l.15, -1\n %s.15 = select i1 %cmp.15, i8 %l.15, i8 %x\n store i8 %s.15, ptr %gep.15, align 2\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/full-matched-bv-with-subvectors.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-9999 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(i64 %l.549) {\nentry:\n %conv3 = sext i32 0 to i64\n br label %if.then19\n\np: ; preds = %if.end29, %if.end25\n %l.0 = phi i64 [ %xor, %if.end29 ], [ %l.5493, %if.end25 ]\n %m.0 = phi i64 [ %not21, %if.end29 ], [ %m.550, %if.end25 ]\n br i1 false, label %s, label %q\n\nq: ; preds = %land.lhs.true, %p\n %xor39 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %l.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %m.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n br i1 false, label %lor.lhs.false, label %r\n\nlor.lhs.false: ; preds = %q\n br i1 false, label %land.lhs.true, label %s\n\nr: ; preds = %if.then19, %q\n %xor38 = phi i64 [ %xor39, %q ], [ %xor, %if.then19 ]\n %j.0 = phi i64 [ %conv3, %q ], [ %not21, %if.then19 ]\n %l.2 = phi i64 [ %l.1, %q ], [ %l.549, %if.then19 ]\n %m.2 = phi i64 [ %m.1, %q ], [ %m.550, %if.then19 ]\n br i1 false, label %s, label %land.lhs.true\n\nland.lhs.true: ; preds = %r, %lor.lhs.false\n %xor37 = phi i64 [ %xor38, %r ], [ 0, %lor.lhs.false ]\n %j.1 = phi i64 [ %j.0, %r ], [ 0, %lor.lhs.false ]\n %l.3 = phi i64 [ %l.2, %r ], [ 0, %lor.lhs.false ]\n %m.3 = phi i64 [ %m.2, %r ], [ 0, %lor.lhs.false ]\n br i1 false, label %q, label %s\n\ns: ; preds = %land.lhs.true, %r, %lor.lhs.false, %p\n %xor36 = phi i64 [ %xor37, %land.lhs.true ], [ %xor38, %r ], [ %xor39, %lor.lhs.false ], [ %l.0, %p ]\n %j.2 = phi i64 [ %j.1, %land.lhs.true ], [ %j.0, %r ], [ %conv3, %lor.lhs.false ], [ %m.0, %p ]\n %l.4 = phi i64 [ %l.3, %land.lhs.true ], [ %l.2, %r ], [ %l.1, %lor.lhs.false ], [ %l.0, %p ]\n %m.4 = phi i64 [ %m.3, %land.lhs.true ], [ %m.2, %r ], [ %m.1, %lor.lhs.false ], [ %m.0, %p ]\n br label %if.then19\n\nif.then19: ; preds = %s, %entry\n %m.550 = phi i64 [ 0, %entry ], [ %m.4, %s ]\n %l.5493 = phi i64 [ 0, %entry ], [ %l.4, %s ]\n %xor = xor i64 0, 0\n %not21 = xor i64 0, 0\n br i1 false, label %r, label %if.end25\n\nif.end25: ; preds = %if.then19\n br i1 false, label %if.end29, label %p\n\nif.end29: ; preds = %if.end25\n br label %p\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/vWPhsMfoz\n\n```\n[510] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 24bd9bc0b59d51c82e9a4d84c21d86d58d0ef6ce)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[511] % \n[511] % clangtk -O2 small.c\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10936: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250111-clangtk-m64-Os-build-025751/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250111-clangtk-m64-Os-build-025751/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-2771d7.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000562bd646d500 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4576500)\n #1 0x0000562bd646a91f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x457391f)\n #2 0x0000562bd646aa75 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007f13d1771520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007f13d17c5a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\n #5 0x00007f13d1771476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007f13d17577f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007f13d175771b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007f13d1768e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000562bd7f25a4f llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x602ea4f)\n#10 0x0000562bd7f9164b llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x609a64b)\n#11 0x0000562bd7f92881 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x609b881)\n#12 0x0000562bd7faaa12 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60b3a12)\n#13 0x0000562bd7fb43e8 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60bd3e8)\n#14 0x0000562bd7fb92b0 bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#15 0x0000562bd7fbabe9 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60c3be9)\n#16 0x0000562bd7fc268e 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\n#17 0x0000562bd7fc31d1 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60cc1d1)\n#18 0x0000562bd79d6826 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5adf826)\n#19 0x0000562bd5de82ef llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ef12ef)\n#20 0x0000562bd37a5226 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18ae226)\n#21 0x0000562bd5de664b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3eef64b)\n#22 0x0000562bd37a3b36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18acb36)\n#23 0x0000562bd5de724d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ef024d)\n#24 0x0000562bd67194c7 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#25 0x0000562bd671d213 clang::emitBackendOutput(clang::CompilerInstance&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4826213)\n#26 0x0000562bd6df1805 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4efa805)\n#27 0x0000562bd8a8c2cc clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6b952cc)\n#28 0x0000562bd70d6ca9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x51dfca9)\n#29 0x0000562bd7054ad5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x515dad5)\n#30 0x0000562bd71bbf73 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x52c4f73)\n#31 0x0000562bd334425f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x144d25f)\n#32 0x0000562bd333ab2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x0000562bd333efe7 clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1447fe7)\n#34 0x0000562bd322eb3b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1337b3b)\n#35 0x00007f13d1758d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#36 0x00007f13d1758e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#37 0x0000562bd333a255 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1443255)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 24bd9bc0b59d51c82e9a4d84c21d86d58d0ef6ce)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-929da7.c\nclangtk: note: diagnostic msg: /tmp/small-929da7.sh\nclangtk: note: diagnostic msg: \n\n********************\n[512] % \n[512] % cat small.c\nint a, b, d, e, f, i, n;\nlong c, g, h;\nunsigned o;\nint main() {\n unsigned long j;\n long l, m;\n if (0) {\n k:\n h = ~g;\n l = g;\n m = j;\n i = d;\n p:\n b = g = i;\n if (d) {\n q:\n j = a;\n if (i || i >= a)\n r:\n if (f && h > a)\n goto q;\n goto s;\n }\n g = l;\n j = m;\n s:;\n }\n if (c) {\n n = j % -1;\n o = b;\n if (n) {\n g = d ^ j;\n j = ~(1 / o);\n if (!(n - 1))\n goto r;\n if (e)\n goto p;\n }\n goto k;\n }\n}\n```", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/MzcesqWz1\n```\n; bin/opt -passes=slp-vectorizer reduced.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i64 %l.549) {\nentry:\n %conv3 = sext i32 0 to i64\n br label %if.then19\n\np: ; preds = %if.end29, %if.end25\n %l.0 = phi i64 [ %xor, %if.end29 ], [ %l.5493, %if.end25 ]\n %m.0 = phi i64 [ %not21, %if.end29 ], [ %m.550, %if.end25 ]\n br i1 false, label %s, label %q\n\nq: ; preds = %land.lhs.true, %p\n %xor39 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %l.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %m.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n br i1 false, label %lor.lhs.false, label %r\n\nlor.lhs.false: ; preds = %q\n br i1 false, label %land.lhs.true, label %s\n\nr: ; preds = %if.then19, %q\n %xor38 = phi i64 [ %xor39, %q ], [ %xor, %if.then19 ]\n %j.0 = phi i64 [ %conv3, %q ], [ %not21, %if.then19 ]\n %l.2 = phi i64 [ %l.1, %q ], [ %l.549, %if.then19 ]\n %m.2 = phi i64 [ %m.1, %q ], [ %m.550, %if.then19 ]\n br i1 false, label %s, label %land.lhs.true\n\nland.lhs.true: ; preds = %r, %lor.lhs.false\n %xor37 = phi i64 [ %xor38, %r ], [ 0, %lor.lhs.false ]\n %j.1 = phi i64 [ %j.0, %r ], [ 0, %lor.lhs.false ]\n %l.3 = phi i64 [ %l.2, %r ], [ 0, %lor.lhs.false ]\n %m.3 = phi i64 [ %m.2, %r ], [ 0, %lor.lhs.false ]\n br i1 false, label %q, label %s\n\ns: ; preds = %land.lhs.true, %r, %lor.lhs.false, %p\n %xor36 = phi i64 [ %xor37, %land.lhs.true ], [ %xor38, %r ], [ %xor39, %lor.lhs.false ], [ %l.0, %p ]\n %j.2 = phi i64 [ %j.1, %land.lhs.true ], [ %j.0, %r ], [ %conv3, %lor.lhs.false ], [ %m.0, %p ]\n %l.4 = phi i64 [ %l.3, %land.lhs.true ], [ %l.2, %r ], [ %l.1, %lor.lhs.false ], [ %l.0, %p ]\n %m.4 = phi i64 [ %m.3, %land.lhs.true ], [ %m.2, %r ], [ %m.1, %lor.lhs.false ], [ %m.0, %p ]\n br label %if.then19\n\nif.then19: ; preds = %s, %entry\n %m.550 = phi i64 [ 0, %entry ], [ %m.4, %s ]\n %l.5493 = phi i64 [ 0, %entry ], [ %l.4, %s ]\n %xor = xor i64 0, 0\n %not21 = xor i64 0, 0\n br i1 false, label %r, label %if.end25\n\nif.end25: ; preds = %if.then19\n br i1 false, label %if.end29, label %p\n\nif.end29: ; preds = %if.end25\n br label %p\n}\n\n```" } ] }
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": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": [ [ 1149, 1158 ] ], "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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": [ "llvm::ConstantFoldCompareInstruction" ], "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit d9a5f7b118bfc9ab4b7325fae25073729d8e08be Author: Yingwei Zheng <[email protected]> Date: Tue Jun 3 19:51:21 2025 +0800 [ConstantFold] Constant fold icmp of boolean scalable vectors (#142528) Closes https://github.com/llvm/llvm-project/issues/142447. diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 7e5fda229b85..b9db402fe956 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1149,10 +1149,10 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, } // If the comparison is a comparison between two i1's, simplify it. - if (C1->getType()->isIntegerTy(1)) { + if (C1->getType()->isIntOrIntVectorTy(1)) { switch (Predicate) { case ICmpInst::ICMP_EQ: - if (isa<ConstantInt>(C2)) + if (isa<ConstantExpr>(C1)) return ConstantExpr::getXor(C1, ConstantExpr::getNot(C2)); return ConstantExpr::getXor(ConstantExpr::getNot(C1), C2); case ICmpInst::ICMP_NE:
[ { "file": "llvm/test/Transforms/InstSimplify/compare.ll", "commands": [ "opt < %s -passes=instcombine<no-verify-fixpoint> -S" ], "tests": [ { "test_name": "icmp_ne_i1_vec_constant_expr", "test_body": "target datalayout = \"p:32:32-p1:64:64\"\n\ndefine <vscale x 8 x i1> @icmp_ne_i1_vec_constant_expr() {\nentry:\n %cmp = icmp ne <vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0), zeroinitializer\n ret <vscale x 8 x i1> %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmp_eq_i1_vec_constant_expr_commuted", "test_body": "target datalayout = \"p:32:32-p1:64:64\"\n\ndefine <vscale x 8 x i1> @icmp_eq_i1_vec_constant_expr_commuted() {\nentry:\n %cmp = icmp eq <vscale x 8 x i1> zeroinitializer, insertelement (<vscale x 8 x i1> poison, i1 true, i64 0)\n ret <vscale x 8 x i1> %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmp_eq_false_by_trunc", "test_body": "target datalayout = \"p:32:32-p1:64:64\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i1 @icmp_eq_false_by_trunc(i8 %x) {\n %trunc = trunc i8 %x to i1\n %not = xor i1 %trunc, true\n call void @llvm.assume(i1 %not)\n %cmp = icmp eq i8 %x, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] ICmp i1 X, C not simplified as expected. with opt \"-passes=lto<O3>\"", "body": "Full error message:\n```\nICmp i1 X, C not simplified as expected.\nUNREACHABLE executed at /scratch/ewlu/daily-upstream-build/llvm/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7182!\n```\n\nTestcase:\n```llvm ir\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n@a = external global i8\n\ndefine void @c() #0 {\nentry:\n %0 = zext <vscale x 8 x i1> insertelement (<vscale x 8 x i1> poison, i1 true, i64 0) to <vscale x 8 x i32>\n %1 = icmp ne <vscale x 8 x i32> %0, zeroinitializer\n %2 = zext <vscale x 8 x i1> %1 to <vscale x 8 x i8>\n %3 = call i8 @llvm.vector.reduce.xor.nxv8i8(<vscale x 8 x i8> %2)\n store i8 %3, ptr @a, align 1\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)\ndeclare <vscale x 8 x i16> @llvm.masked.gather.nxv8i16.nxv8p0(<vscale x 8 x ptr>, i32 immarg, <vscale x 8 x i1>, <vscale x 8 x i16>) #1\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <vscale x 8 x i32> @llvm.smin.nxv8i32(<vscale x 8 x i32>, <vscale x 8 x i32>) #2\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.vector.reduce.xor.nxv8i8(<vscale x 8 x i8>) #2\n\ndefine i32 @main() {\nentry:\n ret i32 0\n}\n\nattributes #0 = { \"target-features\"=\"+v\" }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(read) }\nattributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```\nThis might not be the fully reduced version. `llvm-reduce` aborted mid reduce for me\n\nCommands/backtrace:\n```\n$ /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt \"-passes=lto<O3>\" reduced.ll\nWARNING: You're attempting to print out a bitcode file.\nThis is inadvisable as it may cause display problems. If\nyou REALLY want to taste LLVM bitcode first-hand, you\ncan force output with the `-f' option.\n\nICmp i1 X, C not simplified as expected.\nUNREACHABLE executed at /scratch/ewlu/daily-upstream-build/llvm/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:7182!\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt -passes=lto<O3> reduced.ll\n1. Running pass \"function<eager-inv>(instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine)\" on module \"reduced.ll\"\n2. Running pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"c\"\n #0 0x000058be7f45a172 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x35a5172)\n #1 0x000058be7f4571df llvm::sys::RunSignalHandlers() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x35a21df)\n #2 0x000058be7f457324 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x000077fe5fe45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x000077fe5fe9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #5 0x000077fe5fe9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #6 0x000077fe5fe9eb2c pthread_kill ./nptl/pthread_kill.c:89:10\n #7 0x000077fe5fe4527e raise ./signal/../sysdeps/posix/raise.c:27:6\n #8 0x000077fe5fe288ff abort ./stdlib/abort.c:81:7\n #9 0x000058be7f38585e (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x34d085e)\n#10 0x000058be7e3f2501 llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x253d501)\n#11 0x000058be7e3464fa llvm::InstCombinerImpl::run() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24914fa)\n#12 0x000058be7e347d90 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0\n#13 0x000058be7e3491e2 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24941e2)\n#14 0x000058be7c9bb605 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xb06605)\n#15 0x000058be7f2430fa llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x338e0fa)\n#16 0x000058be7c9bdc55 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xb08c55)\n#17 0x000058be7f2435e4 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x338e5e4)\n#18 0x000058be7c9b9895 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xb04895)\n#19 0x000058be7f241f6d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x338cf6d)\n#20 0x000058be7c66b241 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) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x7b6241)\n#21 0x000058be7c65cd7c optMain (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x7a7d7c)\n#22 0x000077fe5fe2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\n#23 0x000077fe5fe2a28b call_init ./csu/../csu/libc-start.c:128:20\n#24 0x000077fe5fe2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5\n#25 0x000058be7c6533d5 _start (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x79e3d5)\nAborted (core dumped)\n```\n\nGodbolt: https://godbolt.org/z/5cxdvhhGK\n\nFound via fuzzer (C program before reduction)", "author": "ewlu", "labels": [ "crash-on-valid", "llvm:ir" ], "comments": [] }
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_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 17799, 17804 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::collectValuesToDemote" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit f4974e09312afc9549fcfc0304b738d235da9eca Author: Alexey Bataev <[email protected]> Date: Fri Nov 29 06:20:19 2024 -0800 [SLP] Add a check for poison value in AShrChecker Need to check if the value in AShrChecker is a poison before casting it to instruction to avoid compiler crash Fixes #118030 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 48a8520a966f..7723442bc0fb 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -17799,6 +17799,8 @@ bool BoUpSLP::collectValuesToDemote( // original type and the sign bit of the truncate type are similar. auto AShrChecker = [&](unsigned BitWidth, unsigned OrigBitWidth) { return all_of(E.Scalars, [&](Value *V) { + if (isa<PoisonValue>(V)) + return true; auto *I = cast<Instruction>(V); KnownBits AmtKnownBits = computeKnownBits(I->getOperand(1), *DL); unsigned ShiftedBits = OrigBitWidth - BitWidth;
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/ashr-node-with-poison.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(ptr %n, i32 %conv57, i1 %tobool5.not, i64 %bf.load14) {\n;\nentry:\n br i1 false, label %entry.if.end54_crit_edge, label %while.cond\n\nentry.if.end54_crit_edge:\n br label %if.end54\n\ntthread-pre-split:\n br label %t\n\nt:\n %w.2 = phi i32 [ 1, %tthread-pre-split ], [ 0, %if.end83 ]\n br label %if.end7\n\nt.u_crit_edge:\n br label %if.end7\n\nif.end7:\n %w.4 = phi i32 [ %w.2, %t ], [ %w.2, %t.u_crit_edge ], [ %bf.cast25, %while.body ]\n %a.4 = phi i32 [ 0, %t ], [ %conv57, %t.u_crit_edge ], [ %bf.cast2910, %while.body ]\n %b.4 = phi i32 [ 0, %t ], [ 0, %t.u_crit_edge ], [ %bf.cast2910, %while.body ]\n %c.4 = phi i32 [ 0, %t ], [ 1, %t.u_crit_edge ], [ poison, %while.body ]\n br label %v\n\nwhile.cond:\n %bf.load66.pre.pre1135 = phi i64 [ 0, %entry ], [ %spec.select, %if.end42 ]\n br i1 %tobool5.not, label %if.end54, label %while.body\n\nwhile.body:\n %bf.ashr24 = ashr i64 %bf.load14, 33\n %bf.cast25 = trunc nsw i64 %bf.ashr24 to i32\n %bf.ashr28 = lshr i64 %bf.load14, 1\n %bf.cast2910 = trunc i64 %bf.ashr28 to i32\n br label %if.end7\n\nif.end36:\n br label %v\n\nv:\n %c.7 = phi i32 [ %c.4, %if.end7 ], [ 0, %if.end36 ]\n br i1 true, label %if.end42, label %v.if.end83_crit_edge\n\nv.if.end83_crit_edge:\n br label %if.end83\n\nif.end42:\n %tobool43.not = icmp eq i32 %b.4, 0\n %narrow = select i1 %tobool43.not, i32 0, i32 %w.4\n %spec.select = zext i32 %narrow to i64\n %bf.value48 = zext i32 %a.4 to i64\n store i64 %bf.value48, ptr %n, align 8\n store i32 %c.7, ptr %n, align 4\n br label %while.cond\n\nif.end54:\n %bf.load66.pre.pre113125 = phi i64 [ %bf.load66.pre.pre1135, %while.cond ], [ poison, %entry.if.end54_crit_edge ]\n %0 = icmp eq i64 %bf.load66.pre.pre113125, 0\n br i1 %0, label %if.end83, label %ai.if.end76_crit_edge\n\nai.if.end76_crit_edge:\n br label %if.end83\n\nif.end83:\n br label %t\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/cb67rEodY\n\n```\n[516] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 5208bc3694473f9378fc0d98eeee63e5ad5c5f04)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 11.8\n[517] % \n[517] % clangtk -O2 -w small.c\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20241125-clangtk-m64-O3-fpointer-tbaa-build-014338/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241125-clangtk-m64-O3-fpointer-tbaa-build-014338/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -w -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-99895f.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000562e34749b50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x455db50)\n #1 0x0000562e34746f5f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x455af5f)\n #2 0x0000562e347470b5 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007f99ac5bf520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007f99ac613a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\n #5 0x00007f99ac5bf476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007f99ac5a57f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007f99ac5a571b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007f99ac5b6e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000562e31712868 (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1526868)\n#10 0x0000562e3616cf4e llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda9'(unsigned int, unsigned int)::operator()(unsigned int, unsigned int) const::'lambda'(llvm::Value*)::operator()(llvm::Value*) const SLPVectorizer.cpp:0:0\n#11 0x0000562e3616d208 bool llvm::function_ref<bool (unsigned int, unsigned int)>::callback_fn<llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda9'(unsigned int, unsigned int)>(long, unsigned int, unsigned int) SLPVectorizer.cpp:0:0\n#12 0x0000562e361c72e9 llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda6'(unsigned int&, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>, llvm::function_ref<bool (unsigned int, unsigned int)>)::operator()(unsigned int&, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>, llvm::function_ref<bool (unsigned int, unsigned int)>) const SLPVectorizer.cpp:0:0\n#13 0x0000562e361c6065 llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5fda065)\n#14 0x0000562e361c6d09 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes()::'lambda0'(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool, unsigned int, unsigned int, bool, bool)::operator()(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool, unsigned int, unsigned int, bool, bool) const SLPVectorizer.cpp:0:0\n#15 0x0000562e361db4e3 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5fef4e3)\n#16 0x0000562e3623dc1e llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6051c1e)\n#17 0x0000562e362427c0 bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x0000562e36244162 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6058162)\n#19 0x0000562e3624bc96 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\n#20 0x0000562e3624c802 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6060802)\n#21 0x0000562e35c92cf6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5aa6cf6)\n#22 0x0000562e340cd78f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ee178f)\n#23 0x0000562e31add026 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18f1026)\n#24 0x0000562e340cbb1b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3edfb1b)\n#25 0x0000562e31adb986 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18ef986)\n#26 0x0000562e340cc67d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ee067d)\n#27 0x0000562e349f1d16 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#28 0x0000562e349f566c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x480966c)\n#29 0x0000562e350be425 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4ed2425)\n#30 0x0000562e36cf2c7c clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6b06c7c)\n#31 0x0000562e3539f2c9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x51b32c9)\n#32 0x0000562e353190f5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x512d0f5)\n#33 0x0000562e354836b3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x52976b3)\n#34 0x0000562e316862d1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x149a2d1)\n#35 0x0000562e3167cc8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#36 0x0000562e31681067 clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1495067)\n#37 0x0000562e31579a7b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x138da7b)\n#38 0x00007f99ac5a6d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#39 0x00007f99ac5a6e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#40 0x0000562e3167c3b5 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x14903b5)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 5208bc3694473f9378fc0d98eeee63e5ad5c5f04)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-522eca.c\nclangtk: note: diagnostic msg: /tmp/small-522eca.sh\nclangtk: note: diagnostic msg: \n\n********************\n[518] % \n[518] % cat small.c\nstruct {\n int b : 31;\n int c : 6;\n} f, g, j;\nint d, e, h, i, k, l, m, n, o;\nint main() {\n if (m) {\n short q = d;\n if (d)\n r:\n d = q;\n if (0) {\n s:\n t:\n if (h)\n u:\n o = g.c;\n if (n)\n goto v;\n }\n if (n)\n while (g.c) {\n if (e)\n k;\n int w = j.b, a, b = g.c, c = ~b;\n a = f.b;\n if (l) {\n c = 0 % 0;\n goto u;\n }\n if (a)\n goto s;\n l;\n v:\n if (i)\n goto ae;\n if (b)\n j.b = w;\n f.b = a;\n l = c;\n }\n short p = n;\n if (0) {\n ag:\n h = p;\n if (f.b)\n goto t;\n }\n if (j.b) {\n ae:\n e = 0;\n ai:\n if (q)\n goto r;\n }\n }\n if (j.b)\n goto ai;\n if (d)\n goto ag;\n return 0;\n}\n```", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
137196
https://github.com/llvm/llvm-project/issues/137196
miscompilation
be7cf63b4a402ebc5b1dacc6579a693c92e1328e
2025-04-24T15:32:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "1f69d6354a4b088bda5ee62c31411a75eead8b0c", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ [ 1959, 1967 ], [ 1985, 1991 ], [ 2013, 2025 ] ], "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ "InstCombinerImpl::SimplifyDemandedUseFPClass", "getFPClassConstant" ], "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1f69d6354a4b088bda5ee62c31411a75eead8b0c Author: Yingwei Zheng <[email protected]> Date: Mon Apr 28 17:01:43 2025 +0800 [InstCombine] Preserve the sign bit of NaN in `SimplifyDemandedUseFPClass` (#137287) Alive2: https://alive2.llvm.org/ce/z/uiUzEf Closes https://github.com/llvm/llvm-project/issues/137196. Note: To avoid regression in `ret_nofpclass_nopositives_copysign_nnan_flag`, the second commit takes FMF into account. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 2c8939b5a051..a48854a191ca 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -1959,9 +1959,11 @@ static Constant *getFPClassConstant(Type *Ty, FPClassTest Mask) { } } -Value *InstCombinerImpl::SimplifyDemandedUseFPClass( - Value *V, const FPClassTest DemandedMask, KnownFPClass &Known, - unsigned Depth, Instruction *CxtI) { +Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Value *V, + FPClassTest DemandedMask, + KnownFPClass &Known, + unsigned Depth, + Instruction *CxtI) { assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); Type *VTy = V->getType(); @@ -1985,7 +1987,12 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass( if (!I->hasOneUse()) return nullptr; - // TODO: Should account for nofpclass/FastMathFlags on current instruction + if (auto *FPOp = dyn_cast<FPMathOperator>(I)) { + if (FPOp->hasNoNaNs()) + DemandedMask &= ~fcNan; + if (FPOp->hasNoInfs()) + DemandedMask &= ~fcInf; + } switch (I->getOpcode()) { case Instruction::FNeg: { if (SimplifyDemandedFPClass(I, 0, llvm::fneg(DemandedMask), Known, @@ -2013,13 +2020,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass( if (SimplifyDemandedFPClass(I, 0, DemandedMaskAnySign, Known, Depth + 1)) return I; - if ((DemandedMask & fcPositive) == fcNone) { + if ((DemandedMask & fcNegative) == DemandedMask) { // Roundabout way of replacing with fneg(fabs) I->setOperand(1, ConstantFP::get(VTy, -1.0)); return I; } - if ((DemandedMask & fcNegative) == fcNone) { + if ((DemandedMask & fcPositive) == DemandedMask) { // Roundabout way of replacing with fabs I->setOperand(1, ConstantFP::getZero(VTy)); return I;
[ { "file": "llvm/test/Transforms/InstCombine/simplify-demanded-fpclass.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "ret_nofpclass_nopositives_copysign", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(pinf pzero psub pnorm) float @ret_nofpclass_nopositives_copysign(float %x, float %unknown.sign) {\n %copysign = call float @llvm.copysign.f32(float %x, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_no_negatives__copysign_unknown_select_pinf_rhs", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(ninf nzero nsub nnorm) float @ret_nofpclass_no_negatives__copysign_unknown_select_pinf_rhs(i1 %cond, float %x, float %unknown.sign) {\n %select = select i1 %cond, float %x, float 0x7FF0000000000000\n %copysign = call float @llvm.copysign.f32(float %select, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_nonegatives_copysign", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(ninf nzero nsub nnorm) float @ret_nofpclass_nonegatives_copysign(float %x, float %unknown.sign) {\n %copysign = call float @llvm.copysign.f32(float %x, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_no_negatives_noinf__copysign_unknown_select_pinf_rhs", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(inf nzero nsub nnorm) float @ret_nofpclass_no_negatives_noinf__copysign_unknown_select_pinf_rhs(i1 %cond, float %x, float %unknown.sign) {\n %select = select i1 %cond, float %x, float 0x7FF0000000000000\n %copysign = call float @llvm.copysign.f32(float %select, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_no_positives_noinf__copysign_unknown_select_pinf_rhs", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(inf pzero psub pnorm) float @ret_nofpclass_no_positives_noinf__copysign_unknown_select_pinf_rhs(i1 %cond, float %x, float %unknown.sign) {\n %select = select i1 %cond, float %x, float 0x7FF0000000000000\n %copysign = call float @llvm.copysign.f32(float %select, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_nopositives_nonan_copysign", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(nan pinf pzero psub pnorm) float @ret_nofpclass_nopositives_nonan_copysign(float %x, float %unknown.sign) {\n %copysign = call float @llvm.copysign.f32(float %x, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_no_positives__copysign_unknown_select_pinf_rhs", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(pinf pzero psub pnorm) float @ret_nofpclass_no_positives__copysign_unknown_select_pinf_rhs(i1 %cond, float %x, float %unknown.sign) {\n %select = select i1 %cond, float %x, float 0x7FF0000000000000\n %copysign = call float @llvm.copysign.f32(float %select, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ret_nofpclass_nopositive_finites_copysign_nnan_ninf_flag", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(pzero psub pnorm) float @ret_nofpclass_nopositive_finites_copysign_nnan_ninf_flag(float %x, float %unknown.sign) {\n %copysign = call nnan ninf float @llvm.copysign.f32(float %x, float %unknown.sign)\n ret float %copysign\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "copysign not preserving sign bit of a NaN", "body": "we're optimizing this:\n```llvm\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine nofpclass(ninf nzero nsub nnorm) float @f(float %0) {\n %2 = call float @llvm.copysign.f32(float 0x7FF8000000000000, float %0)\n ret float %2\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```\n\nto:\n```llvm\n; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)\ndefine noundef nofpclass(ninf nzero nsub nnorm) float @f(float %0) local_unnamed_addr #0 {\n ret float 0x7FF8000000000000\n}\n\nattributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }\n```\n\nAlive complains that the optimized code will flip the sign bit of a NaN, while the unoptimized code preserved it as required by LangRef's specification of the copysign semantics:\n> The returned value is completely identical to the first operand except for the sign bit; in particular, if the input is a NaN, then the quiet/signaling bit and payload are perfectly preserved.\n\nIf any of the individual flags in `nofpclass(ninf nzero nsub nnorm)` are removed, then we don't do this transformation. Am I missing something here where these flags, together, mean that it's legal to flip the sign of a NaN? Obviously the transformation is just fine when `nofpclass(nan)` is there\n\nhttps://alive2.llvm.org/ce/z/ja96Yf\n\ncc @dtcxzyw @nunoplopes ", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
126012
https://github.com/llvm/llvm-project/issues/126012
miscompilation
52a02b6d1e0c6b492495ff79a3a06ce93e6180b8
2025-02-06T05:45:23
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "7aed53eb1982113e825534f0f66d0a0e46e7a5ed", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": [ [ 12400, 12405 ] ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::isImpliedViaMerge" ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 7aed53eb1982113e825534f0f66d0a0e46e7a5ed Author: Nikita Popov <[email protected]> Date: Mon Feb 10 10:07:21 2025 +0100 [ScalarEvolution] Handle addrec incoming value in isImpliedViaMerge() (#126236) The code already guards against values coming from a previous iteration using properlyDominates(). However, addrecs are considered to properly dominate the loop they are defined in. Handle this special case separately, by checking for expressions that have computable loop evolution (this should cover cases like a zext of an addrec as well). I considered changing the definition of properlyDominates() instead, but decided against it. The current definition is useful in other context, e.g. when deciding whether an expression is safe to expand in a given block. Fixes https://github.com/llvm/llvm-project/issues/126012. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f89887118d8d..46a5c44f4e41 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -12400,6 +12400,12 @@ bool ScalarEvolution::isImpliedViaMerge(CmpPredicate Pred, const SCEV *LHS, // iteration of a loop. if (!properlyDominates(L, LBB)) return false; + // Addrecs are considered to properly dominate their loop, so are missed + // by the previous check. Discard any values that have computable + // evolution in this loop. + if (auto *Loop = LI.getLoopFor(LBB)) + if (hasComputableLoopEvolution(L, Loop)) + return false; if (!ProvedEasily(L, RHS)) return false; }
[ { "file": "llvm/test/Transforms/IndVarSimplify/pr126012.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test() {\nentry:\n br label %for.preheader\n\nfor.preheader: ; preds = %for.inc, %entry\n %indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]\n %indvar2 = phi i32 [ 1, %entry ], [ %indvar3, %for.inc ]\n %indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %cond1 = icmp eq i32 %indvar3, 0\n br i1 %cond1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.preheader\n %cmp = icmp sgt i32 %indvar2, 0\n %ext = zext i1 %cmp to i32\n br label %for.inc\n\nfor.inc: ; preds = %for.end, %for.preheader\n %phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]\n %inc = add i32 %indvar3, 1\n %exitcond = icmp eq i32 %indvar3, 2\n br i1 %exitcond, label %for.exit, label %for.preheader\n\nfor.exit: ; preds = %for.inc\n ret i32 %indvar1\n}\n", "additional_args": "-src-unroll=4 -tgt-unroll=4", "lli_expected_out": null } ] } ]
{ "title": "[IndVarSimplify] Miscompilation at O2", "body": "Reproducer: https://alive2.llvm.org/ce/z/UTnMBe\n```\n; bin/opt -passes=indvars reduced.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n br label %for.cond1.preheader.i.i\n\nfor.cond1.preheader.i.i: ; preds = %for.inc18.i.i, %entry\n %.pre.i.i = phi i64 [ 0, %entry ], [ %1, %for.inc18.i.i ]\n %j.sroa.0.043.i.i = phi i64 [ 1, %entry ], [ %storemerge42.i.i, %for.inc18.i.i ]\n %storemerge42.i.i = phi i64 [ 0, %entry ], [ %inc22.i.i, %for.inc18.i.i ]\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i\n\nfor.end.i.i: ; preds = %for.cond1.preheader.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0\n %dec.348.i.i = add i64 %.pre.i.i, 1\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0\n br label %for.inc18.i.i\n\nfor.inc18.i.i: ; preds = %for.end.i.i, %for.cond1.preheader.i.i\n %1 = phi i64 [ %spec.select.i.i, %for.end.i.i ], [ 0, %for.cond1.preheader.i.i ]\n %inc22.i.i = add i64 %storemerge42.i.i, 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i\n\ng.exit: ; preds = %for.inc18.i.i\n %conv = trunc i64 %.pre.i.i to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)\n```\nBefore:\n```\nEntering function main\n br label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %j.sroa.0.043.i.i -> i64 1\n phi i64 %storemerge42.i.i -> i64 0\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> T\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 0\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %j.sroa.0.043.i.i -> i64 0\n phi i64 %storemerge42.i.i -> i64 1\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> F\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 1\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 0\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 0\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 2\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %j.sroa.0.043.i.i -> i64 1\n phi i64 %storemerge42.i.i -> i64 2\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 1\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 1\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 1\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 3\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 1\n phi i64 %j.sroa.0.043.i.i -> i64 2\n phi i64 %storemerge42.i.i -> i64 3\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 2\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 2\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 2\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 4\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 2\n phi i64 %j.sroa.0.043.i.i -> i64 3\n phi i64 %storemerge42.i.i -> i64 4\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 3\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 3\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 3\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 5\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 3\n phi i64 %j.sroa.0.043.i.i -> i64 4\n phi i64 %storemerge42.i.i -> i64 5\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 4\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 4\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 4\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 6\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 4\n phi i64 %j.sroa.0.043.i.i -> i64 5\n phi i64 %storemerge42.i.i -> i64 6\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 5\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 5\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 5\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 7\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 5\n phi i64 %j.sroa.0.043.i.i -> i64 6\n phi i64 %storemerge42.i.i -> i64 7\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 6\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 6\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 6\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 8\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 6\n phi i64 %j.sroa.0.043.i.i -> i64 7\n phi i64 %storemerge42.i.i -> i64 8\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 7\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 7\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 7\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 9\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 7\n phi i64 %j.sroa.0.043.i.i -> i64 8\n phi i64 %storemerge42.i.i -> i64 9\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 8\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 8\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 8\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 10\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> T\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %g.exit\n %conv = trunc i64 %.pre.i.i to i32 -> i32 7\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n Printf: 7\n -> i32 2\n ret i32 0\nExiting function main\n```\nAfter:\n```\n; ModuleID = 'reduced.ll'\nsource_filename = \"reduced.ll\"\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n br label %for.cond1.preheader.i.i\n\nfor.cond1.preheader.i.i: ; preds = %for.inc18.i.i, %entry\n %.pre.i.i = phi i64 [ 0, %entry ], [ %0, %for.inc18.i.i ]\n %storemerge42.i.i = phi i64 [ 0, %entry ], [ %inc22.i.i, %for.inc18.i.i ]\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i\n\nfor.end.i.i: ; preds = %for.cond1.preheader.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0\n br label %for.inc18.i.i\n\nfor.inc18.i.i: ; preds = %for.end.i.i, %for.cond1.preheader.i.i\n %0 = phi i64 [ %spec.select.i.i, %for.end.i.i ], [ 0, %for.cond1.preheader.i.i ]\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i\n\ng.exit: ; preds = %for.inc18.i.i\n %.pre.i.i.lcssa = phi i64 [ %.pre.i.i, %for.inc18.i.i ]\n %conv = trunc i64 %.pre.i.i.lcssa to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)\n```\n```\nEntering function main\n br label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %storemerge42.i.i -> i64 0\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> T\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 0\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %storemerge42.i.i -> i64 1\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 1\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 1\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 1\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 2\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 1\n phi i64 %storemerge42.i.i -> i64 2\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 2\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 2\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 2\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 3\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 2\n phi i64 %storemerge42.i.i -> i64 3\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 3\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 3\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 3\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 4\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 3\n phi i64 %storemerge42.i.i -> i64 4\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 4\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 4\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 4\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 5\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 4\n phi i64 %storemerge42.i.i -> i64 5\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 5\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 5\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 5\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 6\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 5\n phi i64 %storemerge42.i.i -> i64 6\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 6\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 6\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 6\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 7\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 6\n phi i64 %storemerge42.i.i -> i64 7\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 7\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 7\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 7\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 8\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 7\n phi i64 %storemerge42.i.i -> i64 8\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 8\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 8\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 8\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 9\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 8\n phi i64 %storemerge42.i.i -> i64 9\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 9\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 9\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 9\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 10\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> T\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %g.exit\n phi i64 %.pre.i.i.lcssa -> i64 8\n %conv = trunc i64 %.pre.i.i.lcssa to i32 -> i32 8\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n Printf: 8\n -> i32 2\n ret i32 0\nExiting function main\n```\nllvm version: 52fc6ffcda0895c0c7b976ad1f5cb5a282b571d2", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://alive2.llvm.org/ce/z/_x96gs\n```\n; bin/opt -passes=indvars reduced.ll -S --debug\ndefine i32 @src() {\nentry:\n br label %for.preheader\n\nfor.preheader:\n %indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]\n %indvar2 = phi i32 [ 1, %entry ], [ %indvar3, %for.inc ]\n %indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %cond1 = icmp eq i32 %indvar3, 0\n br i1 %cond1, label %for.inc, label %for.end\n\nfor.end:\n %cmp = icmp sgt i32 %indvar2, 0\n %ext = zext i1 %cmp to i32\n br label %for.inc\n\nfor.inc:\n %phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]\n %inc = add i32 %indvar3, 1\n %exitcond = icmp eq i32 %indvar3, 2\n br i1 %exitcond, label %for.exit, label %for.preheader\n\nfor.exit:\n ret i32 %indvar1\n}\n\n```\n```\nINDVARS: Eliminated comparison: %cmp = icmp sgt i32 %indvar2, 0\n\ndefine i32 @src() {\nentry:\n br label %for.preheader\n\nfor.preheader: ; preds = %for.inc, %entry\n %indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]\n %indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %cond1 = icmp eq i32 %indvar3, 0\n br i1 %cond1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.preheader\n %ext = zext i1 true to i32\n br label %for.inc\n\nfor.inc: ; preds = %for.end, %for.preheader\n %phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]\n %inc = add nuw nsw i32 %indvar3, 1\n %exitcond = icmp eq i32 %indvar3, 2\n br i1 %exitcond, label %for.exit, label %for.preheader\n\nfor.exit: ; preds = %for.inc\n %indvar1.lcssa = phi i32 [ %indvar1, %for.inc ]\n ret i32 %indvar1.lcssa\n}\n```\n`ScalarEvolution::isImpliedViaMerge(sgt, %indvar2, 0, {0,+,1}<nuw><nsw><%for.preheader>(= %indvar3), 0)` wrongly returns true.\nI can't quite understand why `%indvar3` properly dominates `%for.preheader`: https://github.com/llvm/llvm-project/blob/26ecddb05d13c101ccd840a6710eb5f8b82de841/llvm/lib/Analysis/ScalarEvolution.cpp#L14131-L14141\n\n@nikic @fhahn Can you help fix this issue?\n\n\n" }, { "author": "nikic", "body": "Related previous fix: https://reviews.llvm.org/D101829" } ] }
true
null
129373
https://github.com/llvm/llvm-project/issues/129373
hang
88460137d97c0b8d3742203e0173ab9ed6c5c8a7
2025-03-01T09:39:32
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "5ddf40fa78705384966c22da78e12134df7bd723", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 1579, 1584 ] ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::scalarizeLoadExtract" ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 5ddf40fa78705384966c22da78e12134df7bd723 Author: Simon Pilgrim <[email protected]> Date: Sat Mar 1 16:54:22 2025 +0000 [VectorCombine] scalarizeLoadExtract - don't create scalar loads if any extract is waiting to be erased (#129375) If any extract is waiting to be erased, then bail out as this will distort the cost calculation and possibly lead to infinite loops. Fixes #129373 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index bb4e1c0f67e7..2e8458e2cd03 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1579,6 +1579,11 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) { if (!UI || UI->getParent() != LI->getParent()) return false; + // If any extract is waiting to be erased, then bail out as this will + // distort the cost calculation and possibly lead to infinite loops. + if (UI->use_empty()) + return false; + // Check if any instruction between the load and the extract may modify // memory. if (LastCheckedInst->comesBefore(UI)) {
[ { "file": "llvm/test/Transforms/VectorCombine/X86/load-extractelement-scalarization.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=sse2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=avx2" ], "tests": [ { "test_name": "multiple_extract", "test_body": "define void @multiple_extract(ptr %p) {\n %vp = load ptr, ptr %p, align 8\n %v = load <2 x i32>, ptr %vp, align 16\n %e0 = extractelement <2 x i32> %v, i64 0\n %e1 = extractelement <2 x i32> %v, i64 1\n store i32 %e0, ptr %p, align 4\n %p1 = getelementptr inbounds nuw i8, ptr %p, i64 4\n store i32 %e1, ptr %p1, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "unused_extract", "test_body": "define void @unused_extract(ptr %p) {\n %load = load <4 x float>, ptr %p, align 8\n %shuffle0 = shufflevector <4 x float> zeroinitializer, <4 x float> %load, <4 x i32> <i32 0, i32 4, i32 1, i32 5>\n %shuffle1 = shufflevector <4 x float> %shuffle0, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 poison, i32 poison>\n %extract = extractelement <4 x float> %load, i64 1\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VectorCombine] scalarizeLoadExtract - infinite loop if we scalarize a dead extract waiting to be erased", "body": "Reduced test case:\n\n```ll\ndefine void @infinite_loop(ptr %p0) {\n %load = load <4 x float>, ptr %p0, align 8\n %shuffle0 = shufflevector <4 x float> zeroinitializer, <4 x float> %load, <4 x i32> <i32 0, i32 4, i32 1, i32 5>\n %shuffle1 = shufflevector <4 x float> %shuffle0, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 poison, i32 poison>\n %extract = extractelement <4 x float> %load, i64 1\n ret void\n}\n```\n\nscalarizeLoadExtract iterates across all users of a load, and doesn't account for possible orders in the worklist that prevent unused instructions that use the load from being erased afterward.\n\nFix incoming", "author": "RKSimon", "labels": [ "release:backport", "vectorizers", "hang" ], "comments": [] }
true
null
91691
https://github.com/llvm/llvm-project/issues/91691
miscompilation
1fadb2b0c881ced247931f442fdee6c4ed96dccb
2024-05-10T02:43:43
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "b5f4210e9f51f938ae517f219f04f9ab431a2684", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 3343, 3349 ], [ 3366, 3371 ], [ 3379, 3384 ], [ 3448, 3461 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "foldBitCeil", "isSafeToRemoveBitCeilSelect" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit b5f4210e9f51f938ae517f219f04f9ab431a2684 Author: Yingwei Zheng <[email protected]> Date: Mon May 13 14:27:59 2024 +0800 [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776) See the following case: ``` define i32 @src1(i32 %x) { %dec = sub nuw i32 -2, %x %ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false) %sub = sub nsw i32 32, %ctlz %shl = shl i32 1, %sub %ugt = icmp ult i32 %x, -2 %sel = select i1 %ugt, i32 %shl, i32 1 ret i32 %sel } define i32 @tgt1(i32 %x) { %dec = sub nuw i32 -2, %x %ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false) %sub = sub nsw i32 32, %ctlz %and = and i32 %sub, 31 %shl = shl nuw i32 1, %and ret i32 %shl } ``` `nuw` in `%dec` should be dropped after the select instruction is eliminated. Alive2: https://alive2.llvm.org/ce/z/7S9529 Fixes https://github.com/llvm/llvm-project/issues/91691. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index ee090e012508..a3ddb402bf66 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3343,7 +3343,8 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { // pattern. static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, const APInt *Cond1, Value *CtlzOp, - unsigned BitWidth) { + unsigned BitWidth, + bool &ShouldDropNUW) { // The challenge in recognizing std::bit_ceil(X) is that the operand is used // for the CTLZ proper and select condition, each possibly with some // operation like add and sub. @@ -3366,6 +3367,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, ConstantRange CR = ConstantRange::makeExactICmpRegion( CmpInst::getInversePredicate(Pred), *Cond1); + ShouldDropNUW = false; + // Match the operation that's used to compute CtlzOp from CommonAncestor. If // CtlzOp == CommonAncestor, return true as no operation is needed. If a // match is found, execute the operation on CR, update CR, and return true. @@ -3379,6 +3382,7 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, return true; } if (match(CtlzOp, m_Sub(m_APInt(C), m_Specific(CommonAncestor)))) { + ShouldDropNUW = true; CR = ConstantRange(*C).sub(CR); return true; } @@ -3448,14 +3452,20 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) { Pred = CmpInst::getInversePredicate(Pred); } + bool ShouldDropNUW; + if (!match(FalseVal, m_One()) || !match(TrueVal, m_OneUse(m_Shl(m_One(), m_OneUse(m_Sub(m_SpecificInt(BitWidth), m_Value(Ctlz)))))) || !match(Ctlz, m_Intrinsic<Intrinsic::ctlz>(m_Value(CtlzOp), m_Zero())) || - !isSafeToRemoveBitCeilSelect(Pred, Cond0, Cond1, CtlzOp, BitWidth)) + !isSafeToRemoveBitCeilSelect(Pred, Cond0, Cond1, CtlzOp, BitWidth, + ShouldDropNUW)) return nullptr; + if (ShouldDropNUW) + cast<Instruction>(CtlzOp)->setHasNoUnsignedWrap(false); + // Build 1 << (-CTLZ & (BitWidth-1)). The negation likely corresponds to a // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth // is an integer constant. Masking with BitWidth-1 comes free on some
[ { "file": "llvm/test/Transforms/InstCombine/bit_ceil.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "pr91691", "test_body": "define i32 @pr91691(i32 %0) {\n %2 = sub nuw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "bit_ceil_v4i32", "test_body": "define <4 x i32> @bit_ceil_v4i32(<4 x i32> %x) {\n %dec = add <4 x i32> %x, splat (i32 -1)\n %ctlz = tail call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %dec, i1 false)\n %sub = sub <4 x i32> splat (i32 32), %ctlz\n %shl = shl <4 x i32> splat (i32 1), %sub\n %ugt = icmp ugt <4 x i32> %x, splat (i32 1)\n %sel = select <4 x i1> %ugt, <4 x i32> %shl, <4 x i32> splat (i32 1)\n ret <4 x i32> %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i32> @llvm.ctlz.v4i32(<4 x i32>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr91691_keep_nsw", "test_body": "define i32 @pr91691_keep_nsw(i32 %0) {\n %2 = sub nsw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "instcombine removes a select, making code more poisonous", "body": "https://alive2.llvm.org/ce/z/c__jy8\r\n\r\nthis function:\r\n```llvm\r\ndefine i32 @f(i32 %0) {\r\n %2 = sub nuw i32 -2, %0\r\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\r\n %4 = sub i32 32, %3\r\n %5 = shl i32 1, %4\r\n %6 = icmp ult i32 %0, -2\r\n %7 = select i1 %6, i32 %5, i32 1\r\n ret i32 %7\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nis getting rewritten to not have the select, but the select was blocking a poison value. the bad thing happens when -1 is passed as an argument, see the Alive link for a detailed execution trace\r\n\r\n```llvm\r\ndefine i32 @f(i32 %0) {\r\n %2 = sub nuw i32 -2, %0\r\n %3 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %2, i1 false)\r\n %4 = sub nsw i32 0, %3\r\n %5 = and i32 %4, 31\r\n %6 = shl nuw i32 1, %5\r\n ret i32 %6\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\ncc @nunoplopes ", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
89516
https://github.com/llvm/llvm-project/issues/89516
miscompilation
18bb175428f520aaa4a5e388bd3b680a1a7c60c0
2024-04-20T22:58:16
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "6309440c218778db027306826993e484eab2be17", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 2720, 2726 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "foldSelectWithSRem" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 6309440c218778db027306826993e484eab2be17 Author: Yingwei Zheng <[email protected]> Date: Sun Apr 21 22:41:32 2024 +0800 [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) Fixes #89516 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 0262af28068b..73600206a55c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2720,7 +2720,7 @@ static Instruction *foldSelectWithSRem(SelectInst &SI, InstCombinerImpl &IC, // %cnd = icmp slt i32 %rem, 0 // %add = add i32 %rem, %n // %sel = select i1 %cnd, i32 %add, i32 %rem - if (match(TrueVal, m_Add(m_Value(RemRes), m_Value(Remainder))) && + if (match(TrueVal, m_Add(m_Specific(RemRes), m_Value(Remainder))) && match(RemRes, m_SRem(m_Value(Op), m_Specific(Remainder))) && IC.isKnownToBeAPowerOfTwo(Remainder, /*OrZero*/ true) && FalseVal == RemRes)
[ { "file": "llvm/test/Transforms/InstCombine/select-divrem.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "rem_euclid_pow2_false_arm_folded", "test_body": "define i32 @rem_euclid_pow2_false_arm_folded(i32 %n) {\n %rem = srem i32 %n, 2\n %nonneg = icmp sge i32 %rem, 0\n %res = select i1 %nonneg, i32 %rem, i32 1\n ret i32 %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr89516", "test_body": "define i8 @pr89516(i8 %n, i8 %x) {\n %cond = icmp slt i8 %x, 0\n %pow2 = shl nuw i8 1, %n\n %srem = srem i8 1, %pow2\n %add = add nuw i8 %srem, %pow2\n %res = select i1 %cond, i8 %add, i8 %srem\n ret i8 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "miscompile of vanilla integer code by InstCombine", "body": "https://alive2.llvm.org/ce/z/jRfVLr\r\n\r\nthis function:\r\n```llvm\r\ndefine i8 @f(i8 %0, i8 %1) {\r\n %3 = icmp slt i8 %1, 0\r\n %4 = shl i8 1, %0\r\n %5 = srem i8 1, %4\r\n %6 = add i8 %5, %4\r\n %7 = select i1 %3, i8 %6, i8 %5\r\n ret i8 %7\r\n}\r\n```\r\nis getting mis-optimized to:\r\n```llvm\r\ndefine i8 @f(i8 %0, i8 %1) {\r\n %3 = icmp ne i8 %0, 0\r\n %4 = zext i1 %3 to i8\r\n ret i8 %4\r\n}\r\n```\r\nhere I'll just give Alive's work:\r\n```\r\nExample:\r\ni8 %#0 = #x00 (0)\r\ni8 %#1 = #xff (255, -1)\r\n\r\nSource:\r\ni1 %#3 = #x1 (1)\r\ni8 %#4 = #x01 (1)\r\ni8 %#5 = #x00 (0)\r\ni8 %#6 = #x01 (1)\r\ni8 %#7 = #x01 (1)\r\n\r\nTarget:\r\ni1 %#3 = #x0 (0)\r\ni8 %#4 = #x00 (0)\r\nSource value: #x01 (1)\r\nTarget value: #x00 (0)\r\n```\r\n\r\ncc @nunoplopes @hatsunespica", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
112666
https://github.com/llvm/llvm-project/issues/112666
miscompilation
d6d73ec89e493c69cf24dc3a710d861e2ce08acb
2024-10-17T06:28:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "ff07df6620c32571c7e13ff96ec7976c63ed0ab8", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ [ 333, 338 ] ], "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ "Negator::visitImpl" ], "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit ff07df6620c32571c7e13ff96ec7976c63ed0ab8 Author: Yingwei Zheng <[email protected]> Date: Fri Nov 8 16:20:04 2024 +0800 [InstCombine] Drop nsw in negation of select (#112893) Closes https://github.com/llvm/llvm-project/issues/112666 and https://github.com/llvm/llvm-project/issues/114181. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index 9bd848552615..2210336d92bf 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -333,6 +333,17 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { NewSelect->swapValues(); // Don't swap prof metadata, we didn't change the branch behavior. NewSelect->setName(I->getName() + ".neg"); + // Poison-generating flags should be dropped + Value *TV = NewSelect->getTrueValue(); + Value *FV = NewSelect->getFalseValue(); + if (match(TV, m_Neg(m_Specific(FV)))) + cast<Instruction>(TV)->dropPoisonGeneratingFlags(); + else if (match(FV, m_Neg(m_Specific(TV)))) + cast<Instruction>(FV)->dropPoisonGeneratingFlags(); + else { + cast<Instruction>(TV)->dropPoisonGeneratingFlags(); + cast<Instruction>(FV)->dropPoisonGeneratingFlags(); + } Builder.Insert(NewSelect); return NewSelect; }
[ { "file": "llvm/test/Transforms/InstCombine/sub-of-negatible.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "negate_select_of_op_vs_negated_op_nsw_commuted", "test_body": "define i8 @negate_select_of_op_vs_negated_op_nsw_commuted(i8 %x, i8 %y, i1 %c) {\n %t0 = sub nsw i8 0, %x\n %t1 = select i1 %c, i8 %x, i8 %t0\n %t2 = sub i8 %y, %t1\n ret i8 %t2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "negate_select_of_op_vs_negated_op_nsw", "test_body": "define i8 @negate_select_of_op_vs_negated_op_nsw(i8 %x, i8 %y, i1 %c) {\n %t0 = sub nsw i8 0, %x\n %t1 = select i1 %c, i8 %t0, i8 %x\n %t2 = sub i8 %y, %t1\n ret i8 %t2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dont_negate_ordinary_select", "test_body": "define i8 @dont_negate_ordinary_select(i8 %x, i8 %y, i8 %z, i1 %c) {\n %t0 = select i1 %c, i8 %x, i8 %y\n %t1 = sub i8 %z, %t0\n ret i8 %t1\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "negate_select_of_op_vs_negated_op_nsw_xyyx", "test_body": "define i8 @negate_select_of_op_vs_negated_op_nsw_xyyx(i8 %x, i8 %y, i8 %z, i1 %c) {\n %sub1 = sub nsw i8 %x, %y\n %sub2 = sub nsw i8 %y, %x\n %t1 = select i1 %c, i8 %sub1, i8 %sub2\n %t2 = sub i8 %z, %t1\n ret i8 %t2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "negate_select_of_op_vs_negated_op", "test_body": "declare void @use8(i8)\n\ndefine i8 @negate_select_of_op_vs_negated_op(i8 %x, i8 %y, i1 %c) {\n %t0 = sub i8 0, %x\n call void @use8(i8 %t0)\n %t1 = select i1 %c, i8 %t0, i8 %x, !prof !0\n %t2 = sub i8 %y, %t1\n ret i8 %t2\n}\n\n!0 = !{!\"branch_weights\", i32 40, i32 1}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `nsw` flag should be dropped in Negator", "body": "Reproducer: https://alive2.llvm.org/ce/z/ZFF_QK\r\n```\r\ndefine i8 @src(i8 %x, i8 %y, i1 %c) {\r\n %t0 = sub nsw i8 0, %x\r\n %t1 = select i1 %c, i8 %t0, i8 %x\r\n %t2 = sub i8 %y, %t1\r\n ret i8 %t2\r\n}\r\n\r\ndefine i8 @tgt(i8 %x, i8 %y, i1 %c) {\r\n %t0 = sub nsw i8 0, %x\r\n %1 = select i1 %c, i8 %x, i8 %t0\r\n %t2 = add i8 %1, %y\r\n ret i8 %t2\r\n}\r\n```\r\n```\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni8 %x = #x80 (128, -128)\r\ni8 %y = #x00 (0)\r\ni1 %c = #x0 (0)\r\n\r\nSource:\r\ni8 %t0 = poison\r\ni8 %t1 = #x80 (128, -128)\r\ni8 %t2 = #x80 (128, -128)\r\n\r\nTarget:\r\ni8 %t0 = poison\r\ni8 %#1 = poison\r\ni8 %t2 = poison\r\nSource value: #x80 (128, -128)\r\nTarget value: poison\r\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "AZero13", "body": "Is this an issue in 19.x or just main?" }, { "author": "AZero13", "body": "Confirmed this issue exists in 19.x" } ] }
true
null
140994
https://github.com/llvm/llvm-project/issues/140994
miscompilation
7c080e267722ba14439e2f35789c5c293672ab84
2025-05-22T02:48:33
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "3ec0c5c7fef03985b43432c6b914c289d8a5435e", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 25, 30 ], [ 3879, 3889 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "InstCombinerImpl::visitSelectInst" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 3ec0c5c7fef03985b43432c6b914c289d8a5435e Author: Yingwei Zheng <[email protected]> Date: Sat May 31 16:25:10 2025 +0800 [InstCombine] Propagate FMF from select instead of fcmp (#141010) Previously, https://github.com/llvm/llvm-project/commit/3d6b53980ce4ee855484fc8ae6ac3f99c85e48c3 propagates FMF from fcmp to avoid performance regressions. With the help of https://github.com/llvm/llvm-project/pull/139861, https://github.com/llvm/llvm-project/pull/141015, and https://github.com/llvm/llvm-project/pull/141914, we can still convert SPF into fabs/minnum/maxnum intrinsics even if some flags are missing. This patch propagates FMF from select to address the long-standing issue. Closes https://github.com/llvm/llvm-project/issues/140994. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index a791fc5db669..cca5705f6b58 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -25,6 +25,7 @@ #include "llvm/IR/ConstantRange.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/FMF.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" @@ -3879,11 +3880,16 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { // (X ugt Y) ? X : Y -> (X ole Y) ? Y : X if (FCmp->hasOneUse() && FCmpInst::isUnordered(Pred)) { FCmpInst::Predicate InvPred = FCmp->getInversePredicate(); - // FIXME: The FMF should propagate from the select, not the fcmp. Value *NewCond = Builder.CreateFCmpFMF(InvPred, Cmp0, Cmp1, FCmp, FCmp->getName() + ".inv"); + // Propagate ninf/nnan from fcmp to select. + FastMathFlags FMF = SI.getFastMathFlags(); + if (FCmp->hasNoNaNs()) + FMF.setNoNaNs(true); + if (FCmp->hasNoInfs()) + FMF.setNoInfs(true); Value *NewSel = - Builder.CreateSelectFMF(NewCond, FalseVal, TrueVal, FCmp); + Builder.CreateSelectFMF(NewCond, FalseVal, TrueVal, FMF); return replaceInstUsesWith(SI, NewSel); } }
[ { "file": "llvm/test/Transforms/InstCombine/clamp-to-minmax.ll", "commands": [ "opt < %s -passes=instcombine -S", "opt < %s -passes=instcombine -use-constant-fp-for-fixed-length-splat -use-constant-int-for-fixed-length-splat -S" ], "tests": [ { "test_name": "clamp_negative_same_op", "test_body": "define half @clamp_negative_same_op(half %x) {\n %inner_cmp = fcmp nnan ninf nsz ult half %x, 2.550000e+02\n %inner_sel = select i1 %inner_cmp, half %x, half 2.550000e+02\n %outer_cmp = fcmp nnan ninf nsz ult half %x, 1.000000e+00\n %r = select i1 %outer_cmp, half %inner_sel, half 1.000000e+00\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_unordered_nonstrict_maxmin", "test_body": "define half @clamp_float_fast_unordered_nonstrict_maxmin(half %x) {\n %cmp2 = fcmp nnan ninf nsz ult half %x, 2.550000e+02\n %min = select i1 %cmp2, half %x, half 2.550000e+02\n %cmp1 = fcmp nnan ninf nsz ule half %x, 1.000000e+00\n %r = select i1 %cmp1, half 1.000000e+00, half %min\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_ordered_nonstrict_minmax", "test_body": "define half @clamp_float_fast_ordered_nonstrict_minmax(half %x) {\n %cmp2 = fcmp nnan ninf nsz ogt half %x, 1.000000e+00\n %max = select i1 %cmp2, half %x, half 1.000000e+00\n %cmp1 = fcmp nnan ninf nsz oge half %x, 2.550000e+02\n %r = select i1 %cmp1, half 2.550000e+02, half %max\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_ordered_strict_maxmin", "test_body": "define half @clamp_float_fast_ordered_strict_maxmin(half %x) {\n %cmp2 = fcmp nnan ninf nsz olt half %x, 2.550000e+02\n %min = select i1 %cmp2, half %x, half 2.550000e+02\n %cmp1 = fcmp nnan ninf nsz olt half %x, 1.000000e+00\n %r = select i1 %cmp1, half 1.000000e+00, half %min\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_ordered_strict_minmax", "test_body": "define half @clamp_float_fast_ordered_strict_minmax(half %x) {\n %cmp2 = fcmp nnan ninf nsz ogt half %x, 1.000000e+00\n %max = select i1 %cmp2, half %x, half 1.000000e+00\n %cmp1 = fcmp nnan ninf nsz ogt half %x, 2.550000e+02\n %r = select i1 %cmp1, half 2.550000e+02, half %max\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_ordered_nonstrict_maxmin", "test_body": "define half @clamp_float_fast_ordered_nonstrict_maxmin(half %x) {\n %cmp2 = fcmp nnan ninf nsz olt half %x, 2.550000e+02\n %min = select i1 %cmp2, half %x, half 2.550000e+02\n %cmp1 = fcmp nnan ninf nsz ole half %x, 1.000000e+00\n %r = select i1 %cmp1, half 1.000000e+00, half %min\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_unordered_nonstrict_minmax", "test_body": "define half @clamp_float_fast_unordered_nonstrict_minmax(half %x) {\n %cmp2 = fcmp nnan ninf nsz ugt half %x, 1.000000e+00\n %max = select i1 %cmp2, half %x, half 1.000000e+00\n %cmp1 = fcmp nnan ninf nsz uge half %x, 2.550000e+02\n %r = select i1 %cmp1, half 2.550000e+02, half %max\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_test_1", "test_body": "define half @clamp_test_1(half %x) {\n %inner_cmp = fcmp nnan ninf nsz ult half %x, 2.550000e+02\n %inner_sel = select i1 %inner_cmp, half %x, half 2.550000e+02\n %outer_cmp = fcmp nnan ninf nsz ugt half %x, 1.000000e+00\n %r = select i1 %outer_cmp, half %inner_sel, half 1.000000e+00\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_unordered_strict_maxmin", "test_body": "define half @clamp_float_fast_unordered_strict_maxmin(half %x) {\n %cmp2 = fcmp nnan ninf nsz ult half %x, 2.550000e+02\n %min = select i1 %cmp2, half %x, half 2.550000e+02\n %cmp1 = fcmp nnan ninf nsz ult half %x, 1.000000e+00\n %r = select i1 %cmp1, half 1.000000e+00, half %min\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_negative_wrong_const", "test_body": "define half @clamp_negative_wrong_const(half %x) {\n %inner_cmp = fcmp nnan ninf nsz ult half %x, 2.550000e+02\n %inner_sel = select i1 %inner_cmp, half %x, half 2.550000e+02\n %outer_cmp = fcmp nnan ninf nsz ugt half %x, 5.120000e+02\n %r = select i1 %outer_cmp, half %inner_sel, half 5.120000e+02\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clamp_float_fast_unordered_strict_minmax", "test_body": "define half @clamp_float_fast_unordered_strict_minmax(half %x) {\n %cmp2 = fcmp nnan ninf nsz ugt half %x, 1.000000e+00\n %max = select i1 %cmp2, half %x, half 1.000000e+00\n %cmp1 = fcmp nnan ninf nsz ugt half %x, 2.550000e+02\n %r = select i1 %cmp1, half 2.550000e+02, half %max\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/fcmp-fadd-select.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_fcmp_ugt_fadd_select_fastmath_preserve", "test_body": "define half @test_fcmp_ugt_fadd_select_fastmath_preserve(half %in) {\n %cmp1 = fcmp ugt half %in, 0.000000e+00\n %add = fadd nnan half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_uge_fadd_select_fastmath_preserve", "test_body": "define half @test_fcmp_uge_fadd_select_fastmath_preserve(half %in) {\n %cmp1 = fcmp uge half %in, 0.000000e+00\n %add = fadd nnan half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ugt_fadd_select_neg_constant", "test_body": "define half @test_fcmp_ugt_fadd_select_neg_constant(half %in) {\n %cmp1 = fcmp ugt half %in, -0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ugt_fadd_select_constant_swapped", "test_body": "define half @test_fcmp_ugt_fadd_select_constant_swapped(half %in) {\n %cmp1 = fcmp ugt half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half 1.000000e+00, half %add\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_uge_fadd_select_constant_swapped", "test_body": "define half @test_fcmp_uge_fadd_select_constant_swapped(half %in) {\n %cmp1 = fcmp uge half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half 1.000000e+00, half %add\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ult_fadd_select_fastmath_preserve", "test_body": "define half @test_fcmp_ult_fadd_select_fastmath_preserve(half %in) {\n %cmp1 = fcmp ult half %in, 0.000000e+00\n %add = fadd nnan half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ule_fadd_select_constant_swapped", "test_body": "define half @test_fcmp_ule_fadd_select_constant_swapped(half %in) {\n %cmp1 = fcmp ule half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half 1.000000e+00, half %add\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_uge_fadd_select_neg_constant", "test_body": "define half @test_fcmp_uge_fadd_select_neg_constant(half %in) {\n %cmp1 = fcmp uge half %in, -0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ule_fadd_select_neg_constant", "test_body": "define half @test_fcmp_ule_fadd_select_neg_constant(half %in) {\n %cmp1 = fcmp ule half %in, -0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ult_fadd_select_constant_swapped", "test_body": "define half @test_fcmp_ult_fadd_select_constant_swapped(half %in) {\n %cmp1 = fcmp ult half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half 1.000000e+00, half %add\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_uge_fadd_select_constant", "test_body": "define half @test_fcmp_uge_fadd_select_constant(half %in) {\n %cmp1 = fcmp uge half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ult_fadd_select_neg_constant", "test_body": "define half @test_fcmp_ult_fadd_select_neg_constant(half %in) {\n %cmp1 = fcmp ult half %in, -0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ugt_fadd_select_constant", "test_body": "define half @test_fcmp_ugt_fadd_select_constant(half %in) {\n %cmp1 = fcmp ugt half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ule_fadd_select_constant", "test_body": "define half @test_fcmp_ule_fadd_select_constant(half %in) {\n %cmp1 = fcmp ule half %in, 0.000000e+00\n %add = fadd half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ule_fadd_select_fastmath_preserve", "test_body": "define half @test_fcmp_ule_fadd_select_fastmath_preserve(half %in) {\n %cmp1 = fcmp ule half %in, 0.000000e+00\n %add = fadd nnan half %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, half %add, half 1.000000e+00\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/minmax-fold.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "common_factor_umax_extra_use_both", "test_body": "declare void @extra_use(i32)\n\ndefine i32 @common_factor_umax_extra_use_both(i32 %a, i32 %b, i32 %c) {\n %cmp_bc = icmp ugt i32 %b, %c\n %max_bc = select i1 %cmp_bc, i32 %b, i32 %c\n %cmp_ba = icmp ugt i32 %b, %a\n %max_ba = select i1 %cmp_ba, i32 %b, i32 %a\n %cmp_bc_ba = icmp ugt i32 %max_bc, %max_ba\n %max_abc = select i1 %cmp_bc_ba, i32 %max_bc, i32 %max_ba\n call void @extra_use(i32 %max_bc)\n call void @extra_use(i32 %max_ba)\n ret i32 %max_abc\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_min_of_min", "test_body": "define half @not_min_of_min(i8 %i, half %x) {\n %cmp1 = fcmp nnan ninf nsz ult half %x, 1.000000e+00\n %min1 = select i1 %cmp1, half %x, half 1.000000e+00\n %cmp2 = fcmp nnan ninf nsz ult half %x, 2.000000e+00\n %min2 = select i1 %cmp2, half %x, half 2.000000e+00\n %cmp3 = icmp ult i8 %i, 16\n %r = select i1 %cmp3, half %min1, half %min2\n ret half %r\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/minmax-fp.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "t15", "test_body": "define i8 @t15(half %a) {\n %1 = fcmp nsz ule half %a, 0.000000e+00\n %2 = fptosi half %a to i8\n %3 = select i1 %1, i8 %2, i8 0\n ret i8 %3\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fneg_fmax", "test_body": "define half @fneg_fmax(half %x, half %y) {\n %n1 = fneg half %x\n %n2 = fneg half %y\n %cond = fcmp nnan ogt half %n1, %n2\n %max = select i1 %cond, half %n1, half %n2\n ret half %max\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "t11", "test_body": "define i8 @t11(half %a, half %b) {\n %1 = fcmp nnan ninf nsz ult half %b, %a\n %2 = fptosi half %a to i8\n %3 = fptosi half %b to i8\n %4 = select i1 %1, i8 %3, i8 %2\n ret i8 %4\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fneg_fmin", "test_body": "define double @fneg_fmin(double %x, double %y) {\n %n1 = fneg double %x\n %n2 = fneg double %y\n %cond = fcmp nnan nsz ule double %n1, %n2\n %max = select i1 %cond, double %n1, double %n2\n ret double %max\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "t14_commute", "test_body": "define i8 @t14_commute(half %a) {\n %1 = fcmp ule half %a, 0.000000e+00\n %2 = fptosi half %a to i8\n %3 = select i1 %1, i8 0, i8 %2\n ret i8 %3\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "t9", "test_body": "define i8 @t9(half %a) {\n %1 = fcmp ult half %a, 0.000000e+00\n %2 = fptosi half %a to i8\n %3 = select i1 %1, i8 %2, i8 0\n ret i8 %3\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/unordered-fcmp-select.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "select_min_ugt", "test_body": "define half @select_min_ugt(half %a, half %b) {\n %cmp = fcmp nnan ninf nsz ugt half %a, %b\n %sel = select i1 %cmp, half %b, half %a\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_fcmp_une", "test_body": "define half @select_fcmp_une(half %a, half %b) {\n %cmp = fcmp une half %a, %b\n %sel = select nnan i1 %cmp, half %a, half %b\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_min_uge", "test_body": "define half @select_min_uge(half %a, half %b) {\n %cmp = fcmp nsz uge half %a, %b\n %sel = select nnan ninf nsz i1 %cmp, half %b, half %a\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_max_uge", "test_body": "define half @select_max_uge(half %a, half %b) {\n %cmp = fcmp nnan uge half %a, %b\n %sel = select ninf i1 %cmp, half %a, half %b\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_fcmp_ueq", "test_body": "define half @select_fcmp_ueq(half %a, half %b) {\n %cmp = fcmp ueq half %a, %b\n %sel = select nnan i1 %cmp, half %a, half %b\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_min_ule", "test_body": "define half @select_min_ule(half %a, half %b) {\n %cmp = fcmp ule half %a, %b\n %sel = select ninf i1 %cmp, half %a, half %b\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_max_ugt", "test_body": "define half @select_max_ugt(half %a, half %b) {\n %cmp = fcmp ugt half %a, %b\n %sel = select i1 %cmp, half %a, half %b\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_max_ule", "test_body": "define half @select_max_ule(half %a, half %b) {\n %cmp = fcmp nnan ninf nsz ule half %a, %b\n %sel = select nsz i1 %cmp, half %b, half %a\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_min_ult", "test_body": "define half @select_min_ult(half %a, half %b) {\n %cmp = fcmp nsz ult half %a, %b\n %sel = select nnan ninf nsz i1 %cmp, half %a, half %b\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_max_ult", "test_body": "define half @select_max_ult(half %a, half %b) {\n %cmp = fcmp ult half %a, %b\n %sel = select nnan ninf i1 %cmp, half %b, half %a\n ret half %sel\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `(fcmp une T, F) ? T : F --> T` should not rely on the nsz flag on fcmp", "body": "Reproducer: https://alive2.llvm.org/ce/z/_FgncC\n```\ndefine double @src(double %x, double %y) {\n %cmp = fcmp nsz une double %x, %y\n %cond = select i1 %cmp, double %x, double %y\n ret double %cond\n}\n\ndefine double @tgt(double returned %x, double %y) {\n ret double %x\n}\n```\n```\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\ndouble %x = #x8000000000000000 (-0.0)\ndouble %y = #x0000000000000000 (+0.0)\n\nSource:\ni1 %cmp = #x0 (0)\ndouble %cond = #x0000000000000000 (+0.0)\n\nTarget:\nSource value: #x0000000000000000 (+0.0)\nTarget value: #x8000000000000000 (-0.0)\n```\n`nsz` flag should not be propagated from fcmp into select.\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [] }
true
null
115575
https://github.com/llvm/llvm-project/issues/115575
miscompilation
6fb2a6044f11e251c3847d227049d9dae8b87796
2024-11-09T02:09:23
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 952, 957 ] ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::scalarizeBinopOrCmp" ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb Author: Simon Pilgrim <[email protected]> Date: Sat Nov 9 15:59:52 2024 +0000 [VectorCombine] scalarizeBinopOrCmp - check for out of bounds element indices Fixes #115575 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 04ea12ef0f12..b8754b03c2eb 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -952,6 +952,12 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) { if (!IsConst0 && !IsConst1 && Index0 != Index1) return false; + auto *VecTy0 = cast<VectorType>(Ins0->getType()); + auto *VecTy1 = cast<VectorType>(Ins1->getType()); + if (VecTy0->getElementCount().getKnownMinValue() <= Index0 || + VecTy1->getElementCount().getKnownMinValue() <= Index1) + return false; + // Bail for single insertion if it is a load. // TODO: Handle this once getVectorInstrCost can cost for load/stores. auto *I0 = dyn_cast_or_null<Instruction>(V0);
[ { "file": "llvm/test/Transforms/VectorCombine/X86/pr115575.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64--" ], "tests": [ { "test_name": "PR115575", "test_body": "define <2 x i8> @PR115575(i8 %x) {\n %ins = insertelement <2 x i8> poison, i8 %x, i32 3\n %bo = sdiv <2 x i8> %ins, <i8 5, i8 2>\n ret <2 x i8> %bo\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VectorCombine] UB triggered after optimization", "body": "https://github.com/llvm/llvm-project/blob/c93e001ca695e905cb965b36d63f7a348d1dd809/llvm/lib/Transforms/Vectorize/VectorCombine.cpp#L1013-L1031\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/78CM4x\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i8> @sdiv_constant_op1_not_undef_lane.2(i8 %x) {\r\n#0:\r\n %ins = insertelement <2 x i8> poison, i8 %x, i32 3\r\n %bo = sdiv <2 x i8> %ins, { 5, 2 }\r\n ret <2 x i8> %bo\r\n}\r\n=>\r\ndefine <2 x i8> @sdiv_constant_op1_not_undef_lane.2(i8 %x) {\r\n#0:\r\n %bo.scalar = sdiv i8 %x, poison\r\n %bo = insertelement <2 x i8> poison, i8 %bo.scalar, i64 3\r\n ret <2 x i8> %bo\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni8 %x = poison\r\n\r\nSource:\r\n<2 x i8> %ins = < poison, poison >\r\n<2 x i8> %bo = < poison, poison >\r\n\r\nTarget:\r\ni8 %bo.scalar = UB triggered!\r\n\r\n\r\n\r\n----------------------------------------\r\ndefine <2 x i64> @urem_constant_op1_not_undef_lane.2(i64 %x) {\r\n#0:\r\n %ins = insertelement <2 x i64> poison, i64 %x, i32 4294967295\r\n %bo = urem <2 x i64> %ins, { 5, 2 }\r\n ret <2 x i64> %bo\r\n}\r\n=>\r\ndefine <2 x i64> @urem_constant_op1_not_undef_lane.2(i64 %x) {\r\n#0:\r\n %bo.scalar = urem i64 %x, poison\r\n %bo = insertelement <2 x i64> poison, i64 %bo.scalar, i64 4294967295\r\n ret <2 x i64> %bo\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni64 %x = poison\r\n\r\nSource:\r\n<2 x i64> %ins = < poison, poison >\r\n<2 x i64> %bo = < poison, poison >\r\n\r\nTarget:\r\ni64 %bo.scalar = UB triggered!\r\n\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", "vectorizers" ], "comments": [] }
true
null
102279
https://github.com/llvm/llvm-project/issues/102279
crash
f7e1efe8bcea14686d1c303e058f687b6ca1c79f
2024-08-07T07:28:15
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "441f94f4bdf6e2b9747ec12194c595098d9c3a5b", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 17336, 17362 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 441f94f4bdf6e2b9747ec12194c595098d9c3a5b Author: Alexey Bataev <[email protected]> Date: Wed Aug 7 04:09:55 2024 -0700 [SLP]Fix PR102279: check the tracked values for extractelements, not the original values If the reduced value was replaced by the extractelement instruction during vectorization and we attempt to check if this is so, need to check the tracked value, not the original (deleted) instruction. Otherwise, the compiler may crash Fixes https://github.com/llvm/llvm-project/issues/102279 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c9335b7a89e1..1fee06d145b9 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -17336,27 +17336,23 @@ public: // Try to handle shuffled extractelements. if (S.getOpcode() == Instruction::ExtractElement && !S.isAltShuffle() && I + 1 < E) { - InstructionsState NextS = getSameOpcode(ReducedVals[I + 1], TLI); - if (NextS.getOpcode() == Instruction::ExtractElement && - !NextS.isAltShuffle()) { - SmallVector<Value *> CommonCandidates(Candidates); - for (Value *RV : ReducedVals[I + 1]) { - Value *RdxVal = TrackedVals.find(RV)->second; - // Check if the reduction value was not overriden by the - // extractelement instruction because of the vectorization and - // exclude it, if it is not compatible with other values. - if (auto *Inst = dyn_cast<Instruction>(RdxVal)) - if (!NextS.getOpcode() || !NextS.isOpcodeOrAlt(Inst)) - continue; - CommonCandidates.push_back(RdxVal); - TrackedToOrig.try_emplace(RdxVal, RV); - } - SmallVector<int> Mask; - if (isFixedVectorShuffle(CommonCandidates, Mask)) { - ++I; - Candidates.swap(CommonCandidates); - ShuffledExtracts = true; - } + SmallVector<Value *> CommonCandidates(Candidates); + for (Value *RV : ReducedVals[I + 1]) { + Value *RdxVal = TrackedVals.find(RV)->second; + // Check if the reduction value was not overriden by the + // extractelement instruction because of the vectorization and + // exclude it, if it is not compatible with other values. + auto *Inst = dyn_cast<ExtractElementInst>(RdxVal); + if (!Inst) + continue; + CommonCandidates.push_back(RdxVal); + TrackedToOrig.try_emplace(RdxVal, RV); + } + SmallVector<int> Mask; + if (isFixedVectorShuffle(CommonCandidates, Mask)) { + ++I; + Candidates.swap(CommonCandidates); + ShuffledExtracts = true; } }
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-value-replace-extractelement.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\n %trunc = trunc i64 0 to i32\n %mul = mul i32 0, %trunc\n %mul3 = mul i32 %trunc, %phi\n %mul4 = mul i32 %mul3, %mul\n %mul5 = mul i32 %mul4, %mul\n %trunc6 = trunc i64 0 to i32\n %mul7 = mul i32 0, %trunc6\n %mul8 = mul i32 %mul5, %mul7\n %mul9 = mul i32 %mul8, %mul7\n br label %bb1\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-gather-non-scheduled-extracts.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-sie-ps5 < %s" ], "tests": [ { "test_name": "tes", "test_body": "define void @tes() {\nentry:\n %0 = extractelement <2 x i1> zeroinitializer, i64 0\n %1 = extractelement <2 x i1> zeroinitializer, i64 0\n %2 = fcmp ole <2 x double> zeroinitializer, zeroinitializer\n %3 = extractelement <2 x i1> %2, i64 0\n %4 = extractelement <2 x i1> zeroinitializer, i64 0\n br label %5\n\n5: ; preds = %entry\n %6 = select i1 false, i1 false, i1 false\n %7 = select i1 %6, i1 %0, i1 false\n %8 = select i1 %7, i1 %1, i1 false\n %9 = select i1 %8, i1 false, i1 false\n %10 = select i1 %9, i1 %3, i1 false\n %11 = select i1 %10, i1 %4, i1 false\n br i1 %11, label %12, label %13\n\n12: ; preds = %5\n ret void\n\n13: ; preds = %5\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Crash in getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int)", "body": " To reproduce run the test below with `-passes slp-vectorizer -slp-threshold=-99999`\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\r\n %trunc = trunc i64 0 to i32\r\n %mul = mul i32 0, %trunc\r\n %mul3 = mul i32 %trunc, %phi\r\n %mul4 = mul i32 %mul3, %mul\r\n %mul5 = mul i32 %mul4, %mul\r\n %trunc6 = trunc i64 0 to i32\r\n %mul7 = mul i32 0, %trunc6\r\n %mul8 = mul i32 %mul5, %mul7\r\n %mul9 = mul i32 %mul8, %mul7\r\n br label %bb1\r\n}\r\n\r\n```\r\nReproducer: https://godbolt.org/z/sqEov8n9h\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\r\n #0 0x0000000004f2ff18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f2ff18)\r\n #1 0x0000000004f2d68c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007a3cdfe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000000000403fb8a getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n #4 0x000000000406b0a4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n #5 0x000000000406dab4 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+0x406dab4)\r\n #6 0x00000000040720f8 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40720f8)\r\n #7 0x00000000040763be llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40763be)\r\n #8 0x000000000407c648 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 #9 0x000000000407d11b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x407d11b)\r\n#10 0x0000000002e7f61e 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+0x2e7f61e)\r\n#11 0x0000000004d2d348 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2d348)\r\n#12 0x0000000000de6cce 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+0xde6cce)\r\n#13 0x0000000004d2bd3e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2bd3e)\r\n#14 0x0000000000de731e 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+0xde731e)\r\n#15 0x0000000004d29ea0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d29ea0)\r\n#16 0x00000000008e4312 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+0x8e4312)\r\n#17 0x00000000008d723c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d723c)\r\n#18 0x00007a3cdfe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#19 0x00007a3cdfe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#20 0x00000000008ce6ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce6ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "RKSimon", "body": "CC @alexey-bataev " } ] }
true
null
107139
https://github.com/llvm/llvm-project/issues/107139
crash
5d17293caaf0f62ea94fecc137b9b6f07c659dac
2024-09-03T18:28:59
[ "llvm/test/Transforms/Coroutines" ]
{ "fix_commit": "853bff2122e1f42398587f76234c05d56f16318e", "components": [ "Coroutines" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": [ [ 2080, 2091 ], [ 2105, 2117 ], [ 2200, 2205 ], [ 2211, 2217 ], [ 2223, 2236 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": [ "CoroSplitPass::run", "replacePrepare", "splitCoroutine", "updateCallGraphAfterCoroutineSplit" ], "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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 853bff2122e1f42398587f76234c05d56f16318e Author: Yuxuan Chen <[email protected]> Date: Thu Sep 12 10:45:20 2024 -0700 [Coroutines] properly update CallGraph in CoroSplit (#107935) Fixes https://github.com/llvm/llvm-project/issues/107139. We weren't updating the call graph properly in CoroSplit. This crash is due to the await_suspend() function calling the coroutine, forming a multi-node SCC. The issue bisected to https://github.com/llvm/llvm-project/pull/79712 but I think this is red herring. We haven't been properly updating the call graph. Added an example of such code as a test case. diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index dc3829d7f28e..8ea460badaad 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -2080,12 +2080,13 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones, return Shape; } -static void updateCallGraphAfterCoroutineSplit( +static LazyCallGraph::SCC &updateCallGraphAfterCoroutineSplit( LazyCallGraph::Node &N, const coro::Shape &Shape, const SmallVectorImpl<Function *> &Clones, LazyCallGraph::SCC &C, LazyCallGraph &CG, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, FunctionAnalysisManager &FAM) { + auto *CurrentSCC = &C; if (!Clones.empty()) { switch (Shape.ABI) { case coro::ABI::Switch: @@ -2105,13 +2106,16 @@ static void updateCallGraphAfterCoroutineSplit( } // Let the CGSCC infra handle the changes to the original function. - updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM); + CurrentSCC = &updateCGAndAnalysisManagerForCGSCCPass(CG, *CurrentSCC, N, AM, + UR, FAM); } // Do some cleanup and let the CGSCC infra see if we've cleaned up any edges // to the split functions. postSplitCleanup(N.getFunction()); - updateCGAndAnalysisManagerForFunctionPass(CG, C, N, AM, UR, FAM); + CurrentSCC = &updateCGAndAnalysisManagerForFunctionPass(CG, *CurrentSCC, N, + AM, UR, FAM); + return *CurrentSCC; } /// Replace a call to llvm.coro.prepare.retcon. @@ -2200,6 +2204,7 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C, if (Coroutines.empty() && PrepareFns.empty()) return PreservedAnalyses::all(); + auto *CurrentSCC = &C; // Split all the coroutines. for (LazyCallGraph::Node *N : Coroutines) { Function &F = N->getFunction(); @@ -2211,7 +2216,8 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C, coro::Shape Shape = splitCoroutine(F, Clones, FAM.getResult<TargetIRAnalysis>(F), OptimizeFrame, MaterializableCallback); - updateCallGraphAfterCoroutineSplit(*N, Shape, Clones, C, CG, AM, UR, FAM); + CurrentSCC = &updateCallGraphAfterCoroutineSplit( + *N, Shape, Clones, *CurrentSCC, CG, AM, UR, FAM); auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F); ORE.emit([&]() { @@ -2223,14 +2229,14 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C, if (!Shape.CoroSuspends.empty()) { // Run the CGSCC pipeline on the original and newly split functions. - UR.CWorklist.insert(&C); + UR.CWorklist.insert(CurrentSCC); for (Function *Clone : Clones) UR.CWorklist.insert(CG.lookupSCC(CG.get(*Clone))); } } for (auto *PrepareFn : PrepareFns) { - replaceAllPrepares(PrepareFn, CG, C); + replaceAllPrepares(PrepareFn, CG, *CurrentSCC); } return PreservedAnalyses::none();
[ { "file": "llvm/test/Transforms/Coroutines/gh107139-split-in-scc.ll", "commands": [ "opt < %s -passes='cgscc(coro-split)' -S" ], "tests": [ { "test_name": "<module>", "test_body": "; Verify that we don't crash on mutually recursive coroutines\n\ntarget triple = \"x86_64-redhat-linux-gnu\"\n\ndefine void @foo() presplitcoroutine personality ptr null {\nentry:\n\n %0 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)\n %1 = call ptr @llvm.coro.begin(token %0, ptr null)\n %2 = call token @llvm.coro.save(ptr null)\n %3 = call i8 @llvm.coro.suspend(token none, i1 false)\n %4 = call token @llvm.coro.save(ptr null)\n call void @llvm.coro.await.suspend.void(ptr null, ptr null, ptr @bar)\n ret void\n}\n\ndefine void @bar(ptr %0, ptr %1) {\nentry:\n call void @foo()\n ret void\n}\n\n\ndeclare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #0\ndeclare ptr @llvm.coro.begin(token, ptr writeonly) nounwind\ndeclare token @llvm.coro.save(ptr) nomerge nounwind\ndeclare void @llvm.coro.await.suspend.void(ptr, ptr, ptr)\ndeclare i8 @llvm.coro.suspend(token, i1) nounwind\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "\"Invalidated the current SCC\" assertion failure after #79712", "body": "For the source file in https://gist.github.com/smeenai/fcd14380467e813a28f1ef8c5484b775 (reduced from a large example that uses libunifex; it's probably possible to reduce this further but I'm not at all familiar with coroutines), the following command succeeds with Clang 18 but fails with Clang 19 and trunk:\r\n\r\n```\r\n$ clang -c -o /dev/null coroutine_crash.cpp -std=c++20 -w\r\nclang: llvm/lib/Analysis/CGSCCPassManager.cpp:1167: LazyCallGraph::SCC &updateCGAndAnalysisManagerForPass(llvm::LazyCallGraph &, LazyCallGraph::SCC &, LazyCallGraph::Node &, llvm::CGSCCAnalysisManager &, llvm::CGSCCUpdateResult &, llvm::FunctionAnalysisManager &, bool): Assertion `!UR.InvalidatedSCCs.count(C) && \"Invalidated the current SCC!\"' failed.\r\n```\r\n\r\nI bisected this to #79712. CC @fpasserby, @ChuanqiXu9, and @yuxuanchen1997 ", "author": "smeenai", "labels": [ "crash", "coroutines", "llvm:transforms" ], "comments": [ { "author": "yuxuanchen1997", "body": "I took a look at this and I think it was due to incorrect call graph updates. `updateCGAndAnalysisManagerFor(CGSCC|Function)Pass` seems to return an updated SCC but we discarded the updated SCC.\r\n\r\nSee example usage: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/CGSCCPassManager.cpp#L561-L562\r\nSee implementation: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/CGSCCPassManager.cpp#L1170-L1175\r\n\r\nI have a patch https://github.com/llvm/llvm-project/pull/107935 but still need some time for a test case. " }, { "author": "yuxuanchen1997", "body": "This happens when foo has is not a single node SCC:\r\n```\r\ndefine void @foo() presplitcoroutine personality ptr null {\r\nentry:\r\n %0 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)\r\n %1 = call ptr @llvm.coro.begin(token %0, ptr null)\r\n %2 = call token @llvm.coro.save(ptr null)\r\n %3 = call i8 @llvm.coro.suspend(token none, i1 false)\r\n %4 = call token @llvm.coro.save(ptr null)\r\n call void @llvm.coro.await.suspend.void(ptr null, ptr null, ptr @bar)\r\n ret void\r\n}\r\n\r\ndefine void @bar(ptr %0, ptr %1) {\r\nentry:\r\n call void @foo()\r\n ret void\r\n}\r\n\r\ndeclare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #0\r\ndeclare ptr @llvm.coro.begin(token, ptr writeonly) nounwind\r\ndeclare token @llvm.coro.save(ptr) nomerge nounwind\r\ndeclare void @llvm.coro.await.suspend.void(ptr, ptr, ptr)\r\ndeclare i8 @llvm.coro.suspend(token, i1) nounwind\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }\r\n```\r\n\r\nRepro the crash with `clang -O0 bad.ll`." }, { "author": "yuxuanchen1997", "body": "The 3rd argument to `@llvm.coro.await.suspend` is the `await_suspend` function in C++. This happens when `await_suspend()` calls the same coroutine from its body. " } ] }
true
null
106667
https://github.com/llvm/llvm-project/issues/106667
crash
5500e21942f7047344b6fee62d3e08c0ba2f9182
2024-08-30T05:59:16
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "a4aa6bc8fc2130761b8db5db4748059127662785", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 2864, 2869 ], [ 6964, 6969 ], [ 7095, 7149 ], [ 9362, 9383 ], [ 12521, 12530 ], [ 12532, 12640 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec", "BoUpSLP::getOperandEntry", "BoUpSLP::vectorizeOperand" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a4aa6bc8fc2130761b8db5db4748059127662785 Author: Alexey Bataev <[email protected]> Date: Fri Aug 30 10:17:31 2024 -0700 [SLP]Fix PR106667: carefully look for operand nodes. If the operand node has the same scalars as one of the vectorized nodes, the compiler could miss this and incorrectly request minbitwidth data for the wrong node. It may lead to a compiler crash, because the vectorized node might have different minbw result. Fixes https://github.com/llvm/llvm-project/issues/106667 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4c0a1c4c094b..e9785ef9ded2 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2864,6 +2864,12 @@ private: /// avoid issues with def-use order. Value *vectorizeTree(TreeEntry *E, bool PostponedPHIs); + TreeEntry *getMatchedVectorizedOperand(const TreeEntry *E, unsigned NodeIdx); + const TreeEntry *getMatchedVectorizedOperand(const TreeEntry *E, + unsigned NodeIdx) const { + return const_cast<BoUpSLP *>(this)->getMatchedVectorizedOperand(E, NodeIdx); + } + /// Vectorize a single entry in the tree, the \p Idx-th operand of the entry /// \p E. /// \param PostponedPHIs true, if need to postpone emission of phi nodes to @@ -6964,6 +6970,55 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, } } + // Check if this is a duplicate of another entry. + if (TreeEntry *E = getTreeEntry(S.OpValue)) { + LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.OpValue << ".\n"); + if (!E->isSame(VL)) { + auto It = MultiNodeScalars.find(S.OpValue); + if (It != MultiNodeScalars.end()) { + auto *TEIt = find_if(It->getSecond(), + [&](TreeEntry *ME) { return ME->isSame(VL); }); + if (TEIt != It->getSecond().end()) + E = *TEIt; + else + E = nullptr; + } else { + E = nullptr; + } + } + if (!E) { + if (!doesNotNeedToBeScheduled(S.OpValue)) { + LLVM_DEBUG(dbgs() << "SLP: Gathering due to partial overlap.\n"); + if (TryToFindDuplicates(S)) + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, + ReuseShuffleIndices); + return; + } + SmallPtrSet<const TreeEntry *, 4> Nodes; + Nodes.insert(getTreeEntry(S.OpValue)); + for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue)) + Nodes.insert(E); + SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end()); + if (any_of(Nodes, [&](const TreeEntry *E) { + return all_of(E->Scalars, + [&](Value *V) { return Values.contains(V); }); + })) { + LLVM_DEBUG(dbgs() << "SLP: Gathering due to full overlap.\n"); + if (TryToFindDuplicates(S)) + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, + ReuseShuffleIndices); + return; + } + } else { + // Record the reuse of the tree node. FIXME, currently this is only used + // to properly draw the graph rather than for the actual vectorization. + E->UserTreeIndices.push_back(UserTreeIdx); + LLVM_DEBUG(dbgs() << "SLP: Perfect diamond merge at " << *S.OpValue + << ".\n"); + return; + } + } + // Gather if we hit the RecursionMaxDepth, unless this is a load (or z/sext of // a load), in which case peek through to include it in the tree, without // ballooning over-budget. @@ -7095,55 +7150,6 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, // We now know that this is a vector of instructions of the same type from // the same block. - // Check if this is a duplicate of another entry. - if (TreeEntry *E = getTreeEntry(S.OpValue)) { - LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.OpValue << ".\n"); - if (!E->isSame(VL)) { - auto It = MultiNodeScalars.find(S.OpValue); - if (It != MultiNodeScalars.end()) { - auto *TEIt = find_if(It->getSecond(), - [&](TreeEntry *ME) { return ME->isSame(VL); }); - if (TEIt != It->getSecond().end()) - E = *TEIt; - else - E = nullptr; - } else { - E = nullptr; - } - } - if (!E) { - if (!doesNotNeedToBeScheduled(S.OpValue)) { - LLVM_DEBUG(dbgs() << "SLP: Gathering due to partial overlap.\n"); - if (TryToFindDuplicates(S)) - newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, - ReuseShuffleIndices); - return; - } - SmallPtrSet<const TreeEntry *, 4> Nodes; - Nodes.insert(getTreeEntry(S.OpValue)); - for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue)) - Nodes.insert(E); - SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end()); - if (any_of(Nodes, [&](const TreeEntry *E) { - return all_of(E->Scalars, - [&](Value *V) { return Values.contains(V); }); - })) { - LLVM_DEBUG(dbgs() << "SLP: Gathering due to full overlap.\n"); - if (TryToFindDuplicates(S)) - newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, - ReuseShuffleIndices); - return; - } - } else { - // Record the reuse of the tree node. FIXME, currently this is only used - // to properly draw the graph rather than for the actual vectorization. - E->UserTreeIndices.push_back(UserTreeIdx); - LLVM_DEBUG(dbgs() << "SLP: Perfect diamond merge at " << *S.OpValue - << ".\n"); - return; - } - } - // Check that none of the instructions in the bundle are already in the tree. for (Value *V : VL) { if ((!IsScatterVectorizeUserTE && !isa<Instruction>(V)) || @@ -9362,22 +9368,8 @@ public: const BoUpSLP::TreeEntry *BoUpSLP::getOperandEntry(const TreeEntry *E, unsigned Idx) const { - Value *Op = E->getOperand(Idx).front(); - if (const TreeEntry *TE = getTreeEntry(Op)) { - if (find_if(TE->UserTreeIndices, [&](const EdgeInfo &EI) { - return EI.EdgeIdx == Idx && EI.UserTE == E; - }) != TE->UserTreeIndices.end()) - return TE; - auto MIt = MultiNodeScalars.find(Op); - if (MIt != MultiNodeScalars.end()) { - for (const TreeEntry *TE : MIt->second) { - if (find_if(TE->UserTreeIndices, [&](const EdgeInfo &EI) { - return EI.EdgeIdx == Idx && EI.UserTE == E; - }) != TE->UserTreeIndices.end()) - return TE; - } - } - } + if (const TreeEntry *VE = getMatchedVectorizedOperand(E, Idx)) + return VE; const auto *It = find_if(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) { return TE->isGather() && @@ -12521,10 +12513,9 @@ public: } }; -Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx, - bool PostponedPHIs) { - ValueList &VL = E->getOperand(NodeIdx); - const unsigned VF = VL.size(); +BoUpSLP::TreeEntry *BoUpSLP::getMatchedVectorizedOperand(const TreeEntry *E, + unsigned NodeIdx) { + ArrayRef<Value *> VL = E->getOperand(NodeIdx); InstructionsState S = getSameOpcode(VL, *TLI); // Special processing for GEPs bundle, which may include non-gep values. if (!S.getOpcode() && VL.front()->getType()->isPointerTy()) { @@ -12532,109 +12523,113 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx, if (It != VL.end()) S = getSameOpcode(*It, *TLI); } - if (S.getOpcode()) { - auto CheckSameVE = [&](const TreeEntry *VE) { - return VE->isSame(VL) && - (any_of(VE->UserTreeIndices, - [E, NodeIdx](const EdgeInfo &EI) { - return EI.UserTE == E && EI.EdgeIdx == NodeIdx; - }) || - any_of(VectorizableTree, - [E, NodeIdx, VE](const std::unique_ptr<TreeEntry> &TE) { - return TE->isOperandGatherNode({E, NodeIdx}) && - VE->isSame(TE->Scalars); - })); + if (!S.getOpcode()) + return nullptr; + auto CheckSameVE = [&](const TreeEntry *VE) { + return VE->isSame(VL) && + (any_of(VE->UserTreeIndices, + [E, NodeIdx](const EdgeInfo &EI) { + return EI.UserTE == E && EI.EdgeIdx == NodeIdx; + }) || + any_of(VectorizableTree, + [E, NodeIdx, VE](const std::unique_ptr<TreeEntry> &TE) { + return TE->isOperandGatherNode( + {const_cast<TreeEntry *>(E), NodeIdx}) && + VE->isSame(TE->Scalars); + })); + }; + TreeEntry *VE = getTreeEntry(S.OpValue); + if (VE && CheckSameVE(VE)) + return VE; + auto It = MultiNodeScalars.find(S.OpValue); + if (It != MultiNodeScalars.end()) { + auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) { + return TE != VE && CheckSameVE(TE); + }); + if (I != It->getSecond().end()) + return *I; + } + return nullptr; +} + +Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx, + bool PostponedPHIs) { + ValueList &VL = E->getOperand(NodeIdx); + const unsigned VF = VL.size(); + if (TreeEntry *VE = getMatchedVectorizedOperand(E, NodeIdx)) { + auto FinalShuffle = [&](Value *V, ArrayRef<int> Mask) { + // V may be affected by MinBWs. + // We want ShuffleInstructionBuilder to correctly support REVEC. The key + // factor is the number of elements, not their type. + Type *ScalarTy = cast<VectorType>(V->getType())->getElementType(); + unsigned NumElements = getNumElements(VL.front()->getType()); + ShuffleInstructionBuilder ShuffleBuilder( + NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements) + : ScalarTy, + Builder, *this); + ShuffleBuilder.add(V, Mask); + SmallVector<std::pair<const TreeEntry *, unsigned>> SubVectors( + E->CombinedEntriesWithIndices.size()); + transform(E->CombinedEntriesWithIndices, SubVectors.begin(), + [&](const auto &P) { + return std::make_pair(VectorizableTree[P.first].get(), + P.second); + }); + return ShuffleBuilder.finalize(std::nullopt, SubVectors); }; - TreeEntry *VE = getTreeEntry(S.OpValue); - bool IsSameVE = VE && CheckSameVE(VE); - if (!IsSameVE) { - auto It = MultiNodeScalars.find(S.OpValue); - if (It != MultiNodeScalars.end()) { - auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) { - return TE != VE && CheckSameVE(TE); - }); - if (I != It->getSecond().end()) { - VE = *I; - IsSameVE = true; - } - } - } - if (IsSameVE) { - auto FinalShuffle = [&](Value *V, ArrayRef<int> Mask) { - // V may be affected by MinBWs. - // We want ShuffleInstructionBuilder to correctly support REVEC. The key - // factor is the number of elements, not their type. - Type *ScalarTy = cast<VectorType>(V->getType())->getElementType(); - unsigned NumElements = getNumElements(VL.front()->getType()); - ShuffleInstructionBuilder ShuffleBuilder( - NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements) - : ScalarTy, - Builder, *this); - ShuffleBuilder.add(V, Mask); - SmallVector<std::pair<const TreeEntry *, unsigned>> SubVectors( - E->CombinedEntriesWithIndices.size()); - transform(E->CombinedEntriesWithIndices, SubVectors.begin(), - [&](const auto &P) { - return std::make_pair(VectorizableTree[P.first].get(), - P.second); - }); - return ShuffleBuilder.finalize(std::nullopt, SubVectors); - }; - Value *V = vectorizeTree(VE, PostponedPHIs); - if (VF * getNumElements(VL[0]->getType()) != - cast<FixedVectorType>(V->getType())->getNumElements()) { - if (!VE->ReuseShuffleIndices.empty()) { - // Reshuffle to get only unique values. - // If some of the scalars are duplicated in the vectorization - // tree entry, we do not vectorize them but instead generate a - // mask for the reuses. But if there are several users of the - // same entry, they may have different vectorization factors. - // This is especially important for PHI nodes. In this case, we - // need to adapt the resulting instruction for the user - // vectorization factor and have to reshuffle it again to take - // only unique elements of the vector. Without this code the - // function incorrectly returns reduced vector instruction with - // the same elements, not with the unique ones. - - // block: - // %phi = phi <2 x > { .., %entry} {%shuffle, %block} - // %2 = shuffle <2 x > %phi, poison, <4 x > <1, 1, 0, 0> - // ... (use %2) - // %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0} - // br %block - SmallVector<int> Mask(VF, PoisonMaskElem); - for (auto [I, V] : enumerate(VL)) { - if (isa<PoisonValue>(V)) - continue; - Mask[I] = VE->findLaneForValue(V); - } - V = FinalShuffle(V, Mask); - } else { - assert(VF < cast<FixedVectorType>(V->getType())->getNumElements() && - "Expected vectorization factor less " - "than original vector size."); - SmallVector<int> UniformMask(VF, 0); - std::iota(UniformMask.begin(), UniformMask.end(), 0); - V = FinalShuffle(V, UniformMask); + Value *V = vectorizeTree(VE, PostponedPHIs); + if (VF * getNumElements(VL[0]->getType()) != + cast<FixedVectorType>(V->getType())->getNumElements()) { + if (!VE->ReuseShuffleIndices.empty()) { + // Reshuffle to get only unique values. + // If some of the scalars are duplicated in the vectorization + // tree entry, we do not vectorize them but instead generate a + // mask for the reuses. But if there are several users of the + // same entry, they may have different vectorization factors. + // This is especially important for PHI nodes. In this case, we + // need to adapt the resulting instruction for the user + // vectorization factor and have to reshuffle it again to take + // only unique elements of the vector. Without this code the + // function incorrectly returns reduced vector instruction with + // the same elements, not with the unique ones. + + // block: + // %phi = phi <2 x > { .., %entry} {%shuffle, %block} + // %2 = shuffle <2 x > %phi, poison, <4 x > <1, 1, 0, 0> + // ... (use %2) + // %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0} + // br %block + SmallVector<int> Mask(VF, PoisonMaskElem); + for (auto [I, V] : enumerate(VL)) { + if (isa<PoisonValue>(V)) + continue; + Mask[I] = VE->findLaneForValue(V); } - } - // Need to update the operand gather node, if actually the operand is not a - // vectorized node, but the buildvector/gather node, which matches one of - // the vectorized nodes. - if (find_if(VE->UserTreeIndices, [&](const EdgeInfo &EI) { - return EI.UserTE == E && EI.EdgeIdx == NodeIdx; - }) == VE->UserTreeIndices.end()) { - auto *It = find_if( - VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) { - return TE->isGather() && - TE->UserTreeIndices.front().UserTE == E && - TE->UserTreeIndices.front().EdgeIdx == NodeIdx; - }); - assert(It != VectorizableTree.end() && "Expected gather node operand."); - (*It)->VectorizedValue = V; - } - return V; + V = FinalShuffle(V, Mask); + } else { + assert(VF < cast<FixedVectorType>(V->getType())->getNumElements() && + "Expected vectorization factor less " + "than original vector size."); + SmallVector<int> UniformMask(VF, 0); + std::iota(UniformMask.begin(), UniformMask.end(), 0); + V = FinalShuffle(V, UniformMask); + } + } + // Need to update the operand gather node, if actually the operand is not a + // vectorized node, but the buildvector/gather node, which matches one of + // the vectorized nodes. + if (find_if(VE->UserTreeIndices, [&](const EdgeInfo &EI) { + return EI.UserTE == E && EI.EdgeIdx == NodeIdx; + }) == VE->UserTreeIndices.end()) { + auto *It = + find_if(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) { + return TE->isGather() && TE->UserTreeIndices.front().UserTE == E && + TE->UserTreeIndices.front().EdgeIdx == NodeIdx; + }); + assert(It != VectorizableTree.end() && "Expected gather node operand."); + (*It)->VectorizedValue = V; } + return V; } // Find the corresponding gather entry and vectorize it.
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/multi-nodes-bv-vectorized.ll", "commands": [ "opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %p) {\nentry:\n %conv548.2.i.13 = zext i32 0 to i64\n %and551.2.i.13 = and i64 0, %conv548.2.i.13\n %conv548.3.i.13 = zext i32 0 to i64\n %and551.3.i.13 = and i64 0, %conv548.3.i.13\n %0 = trunc i64 %and551.2.i.13 to i32\n %conv54.2.i.14 = and i32 %0, 0\n %conv548.2.i.14 = zext i32 %conv54.2.i.14 to i64\n %and551.2.i.14 = and i64 %and551.2.i.13, %conv548.2.i.14\n %1 = trunc i64 %and551.3.i.13 to i32\n %conv54.3.i.14 = and i32 %1, 0\n %conv548.3.i.14 = zext i32 %conv54.3.i.14 to i64\n %and551.3.i.14 = and i64 %and551.3.i.13, %conv548.3.i.14\n %and551.2.i.15 = and i64 %and551.2.i.14, 0\n %and551.3.i.15 = and i64 %and551.3.i.14, 0\n %and551.2.i.16 = and i64 %and551.2.i.15, 0\n %and551.3.i.16 = and i64 %and551.3.i.15, 0\n %and551.2.i.17 = and i64 %and551.2.i.16, 0\n %and551.3.i.17 = and i64 %and551.3.i.16, 0\n %and551.2.i.18 = and i64 %and551.2.i.17, 0\n %and551.3.i.18 = and i64 %and551.3.i.17, 0\n %and551.2.i.19 = and i64 %and551.2.i.18, 0\n %and551.3.i.19 = and i64 %and551.3.i.18, 0\n %and551.2.i.20 = and i64 %and551.2.i.19, 0\n %and551.3.i.20 = and i64 %and551.3.i.19, 0\n %and551.2.i.21 = and i64 %and551.2.i.20, 0\n %and551.3.i.21 = and i64 %and551.3.i.20, 0\n %gep1 = getelementptr inbounds i8, ptr %p, i64 16\n %gep2 = getelementptr inbounds i8, ptr %p, i64 24\n store i64 %and551.2.i.21, ptr %gep1, align 16\n store i64 %and551.3.i.21, ptr %gep2, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' failed.", "body": "Reproducer: https://godbolt.org/z/PeoMv3Tsn\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 void @main(ptr %p) {\r\nentry:\r\n %conv548.2.i.13 = zext i32 0 to i64\r\n %and551.2.i.13 = and i64 0, %conv548.2.i.13\r\n %conv548.3.i.13 = zext i32 0 to i64\r\n %and551.3.i.13 = and i64 0, %conv548.3.i.13\r\n %0 = trunc i64 %and551.2.i.13 to i32\r\n %conv54.2.i.14 = and i32 %0, 0\r\n %conv548.2.i.14 = zext i32 %conv54.2.i.14 to i64\r\n %and551.2.i.14 = and i64 %and551.2.i.13, %conv548.2.i.14\r\n %1 = trunc i64 %and551.3.i.13 to i32\r\n %conv54.3.i.14 = and i32 %1, 0\r\n %conv548.3.i.14 = zext i32 %conv54.3.i.14 to i64\r\n %and551.3.i.14 = and i64 %and551.3.i.13, %conv548.3.i.14\r\n %and551.2.i.15 = and i64 %and551.2.i.14, 0\r\n %and551.3.i.15 = and i64 %and551.3.i.14, 0\r\n %and551.2.i.16 = and i64 %and551.2.i.15, 0\r\n %and551.3.i.16 = and i64 %and551.3.i.15, 0\r\n %and551.2.i.17 = and i64 %and551.2.i.16, 0\r\n %and551.3.i.17 = and i64 %and551.3.i.16, 0\r\n %and551.2.i.18 = and i64 %and551.2.i.17, 0\r\n %and551.3.i.18 = and i64 %and551.3.i.17, 0\r\n %and551.2.i.19 = and i64 %and551.2.i.18, 0\r\n %and551.3.i.19 = and i64 %and551.3.i.18, 0\r\n %and551.2.i.20 = and i64 %and551.2.i.19, 0\r\n %and551.3.i.20 = and i64 %and551.3.i.19, 0\r\n %and551.2.i.21 = and i64 %and551.2.i.20, 0\r\n %and551.3.i.21 = and i64 %and551.3.i.20, 0\r\n %gep1 = getelementptr inbounds i8, ptr %p, i64 16\r\n %gep2 = getelementptr inbounds i8, ptr %p, i64 24\r\n store i64 %and551.2.i.21, ptr %gep1, align 16\r\n store i64 %and551.3.i.21, ptr %gep2, align 8\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/IR/Constants.cpp:2202: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' 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. Program arguments: bin/opt -passes=slp-vectorizer reduced.ll -S\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x00007c5d3e8138d2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x2138d2)\r\n #1 0x00007c5d3e81079f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x21079f)\r\n #2 0x00007c5d3e8108e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007c5d3e242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007c5d3e2969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007c5d3e2969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007c5d3e2969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007c5d3e242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007c5d3e2287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007c5d3e22871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007c5d3e239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00007c5d36fb0c4d llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x1b0c4d)\r\n#12 0x00007c5d394573b5 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x573b5)\r\n#13 0x00007c5d395ab173 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ab173)\r\n#14 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#15 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#16 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#17 0x00007c5d395a7cbb llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7cbb)\r\n#18 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#19 0x00007c5d395a7a41 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a41)\r\n#20 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#21 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#22 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#23 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#24 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#25 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#26 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#27 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#28 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#29 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#30 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#31 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#32 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#33 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#34 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#35 0x00007c5d395a8f65 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a8f65)\r\n#36 0x00007c5d395ae278 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ae278)\r\n#37 0x00007c5d395b207c llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1b207c)\r\n#38 0x00007c5d395c7cac llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1c7cac)\r\n#39 0x00007c5d395c9637 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::'lambda'(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&)::operator()(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&) const SLPVectorizer.cpp:0:0\r\n#40 0x00007c5d395cb92c llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cb92c)\r\n#41 0x00007c5d395cc20f llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cc20f)\r\n#42 0x00007c5d395cd30f llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cd30f)\r\n#43 0x00007c5d395cdf86 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cdf86)\r\n#44 0x00007c5d39ed4015 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd4015)\r\n#45 0x00007c5d371546ed llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3546ed)\r\n#46 0x00007c5d3d4d7f35 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd7f35)\r\n#47 0x00007c5d37153256 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x353256)\r\n#48 0x00007c5d3d4d88f5 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd88f5)\r\n#49 0x00007c5d3715121a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35121a)\r\n#50 0x00007c5d3eb12fc7 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) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2cfc7)\r\n#51 0x00007c5d3eb1e962 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38962)\r\n#52 0x00007c5d3e229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#53 0x00007c5d3e229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#54 0x00007c5d3e229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#55 0x00005949b291d095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\ncc @alexey-bataev ", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Related PR: https://github.com/llvm/llvm-project/pull/103216\r\n" } ] }
true
null
89669
https://github.com/llvm/llvm-project/issues/89669
miscompilation
d97cdd7d088b11b45038112a5f7fe5cbf60a6461
2024-04-22T21:27:36
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a1b1c4a6d1d52916c5d885170a5f54632d579cdc", "components": [ "InstCombine", "ValueTracking" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ [ 131, 137 ] ], "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 8042, 8058 ] ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ [ 320, 326 ] ], "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ "llvm::isKnownNegation", "matchMinMax" ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ "Negator::visitImpl" ], "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a1b1c4a6d1d52916c5d885170a5f54632d579cdc Author: Nikita Popov <[email protected]> Date: Wed Apr 24 10:56:26 2024 +0900 [InstCombine] Fix miscompile in negation of select (#89698) Swapping the operands of a select is not valid if one hand is more poisonous that the other, because the negation zero contains poison elements. Fix this by adding an extra parameter to isKnownNegation() to forbid poison elements. I've implemented this using manual checks to avoid needing four variants for the NeedsNSW/AllowPoison combinations. Maybe there is a better way to do this... Fixes https://github.com/llvm/llvm-project/issues/89669. diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index a2fa8f6064e1..571e44cdac26 100644 --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -131,7 +131,8 @@ bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0); /// Currently can recoginze Value pair: /// 1: <X, Y> if X = sub (0, Y) or Y = sub (0, X) /// 2: <X, Y> if X = sub (A, B) and Y = sub (B, A) -bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW = false); +bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW = false, + bool AllowPoison = true); /// Returns true if the give value is known to be non-negative. bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ, diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 21e3f8a4cc52..7501f78ca23b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8042,17 +8042,27 @@ static SelectPatternResult matchMinMax(CmpInst::Predicate Pred, return {SPF_UNKNOWN, SPNB_NA, false}; } -bool llvm::isKnownNegation(const Value *X, const Value *Y, bool NeedNSW) { +bool llvm::isKnownNegation(const Value *X, const Value *Y, bool NeedNSW, + bool AllowPoison) { assert(X && Y && "Invalid operand"); - // X = sub (0, Y) || X = sub nsw (0, Y) - if ((!NeedNSW && match(X, m_Sub(m_ZeroInt(), m_Specific(Y)))) || - (NeedNSW && match(X, m_NSWNeg(m_Specific(Y))))) + auto IsNegationOf = [&](const Value *X, const Value *Y) { + if (!match(X, m_Neg(m_Specific(Y)))) + return false; + + auto *BO = cast<BinaryOperator>(X); + if (NeedNSW && !BO->hasNoSignedWrap()) + return false; + + auto *Zero = cast<Constant>(BO->getOperand(0)); + if (!AllowPoison && !Zero->isNullValue()) + return false; + return true; + }; - // Y = sub (0, X) || Y = sub nsw (0, X) - if ((!NeedNSW && match(Y, m_Sub(m_ZeroInt(), m_Specific(X)))) || - (NeedNSW && match(Y, m_NSWNeg(m_Specific(X))))) + // X = -Y or Y = -X + if (IsNegationOf(X, Y) || IsNegationOf(Y, X)) return true; // X = sub (A, B), Y = sub (B, A) || X = sub nsw (A, B), Y = sub nsw (B, A) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index d697f361dec0..ed2a98ba4ae4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -320,7 +320,8 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { return NegatedPHI; } case Instruction::Select: { - if (isKnownNegation(I->getOperand(1), I->getOperand(2))) { + if (isKnownNegation(I->getOperand(1), I->getOperand(2), /*NeedNSW=*/false, + /*AllowPoison=*/false)) { // Of one hand of select is known to be negation of another hand, // just swap the hands around. auto *NewSelect = cast<SelectInst>(I->clone());
[ { "file": "llvm/test/Transforms/InstCombine/sub-of-negatible.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "negate_select_of_negation_poison", "test_body": "define <2 x i32> @negate_select_of_negation_poison(<2 x i1> %c, <2 x i32> %x) {\n %neg = sub <2 x i32> <i32 0, i32 poison>, %x\n %sel = select <2 x i1> %c, <2 x i32> %neg, <2 x i32> %x\n %neg2 = sub <2 x i32> zeroinitializer, %sel\n ret <2 x i32> %neg2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dont_negate_ordinary_select", "test_body": "define i8 @dont_negate_ordinary_select(i8 %x, i8 %y, i8 %z, i1 %c) {\n %t0 = select i1 %c, i8 %x, i8 %y\n %t1 = sub i8 %z, %t0\n ret i8 %t1\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "miscompile of vector double-negation + select by InstCombine", "body": "https://alive2.llvm.org/ce/z/N1RVAr\r\n\r\nthis:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0) {\r\n %2 = sub <4 x i32> zeroinitializer, %0\r\n %3 = select <4 x i1> <i1 false, i1 true, i1 poison, i1 poison>, <4 x i32> %2, <4 x i32> %0\r\n %4 = sub <4 x i32> zeroinitializer, %3\r\n ret <4 x i32> %4\r\n}\r\n```\r\nis being optimized to:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0) {\r\n ret <4 x i32> %0\r\n}\r\n```\r\nhere's Alive's work explaining why this is wrong:\r\n```\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<4 x i32> %#0 = < #x00000001 (1), poison, poison, poison >\r\n\r\nSource:\r\n<4 x i32> %#2 = < #xffffffff (4294967295, -1), poison, poison, poison >\r\n<4 x i32> %#3 = < #x00000001 (1), poison, poison, poison >\r\n<4 x i32> %#4 = < #xffffffff (4294967295, -1), poison, poison, poison >\r\n\r\nTarget:\r\nSource value: < #xffffffff (4294967295, -1), poison, poison, poison >\r\nTarget value: < #x00000001 (1), poison, poison, poison >\r\n```\r\n\r\ncc @nunoplopes @hatsunespica\r\n\r\n", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "topperc", "body": "I think the problem is this code in Negator::visitImpl.\r\n\r\n```\r\n case Instruction::Select: {\r\n if (isKnownNegation(I->getOperand(1), I->getOperand(2))) { \r\n // Of one hand of select is known to be negation of another hand, \r\n // just swap the hands around. \r\n auto *NewSelect = cast<SelectInst>(I->clone()); \r\n // Just swap the operands of the select. \r\n NewSelect->swapValues(); \r\n // Don't swap prof metadata, we didn't change the branch behavior. \r\n NewSelect->setName(I->getName() + \".neg\"); \r\n Builder.Insert(NewSelect); \r\n return NewSelect; \r\n } \r\n```\r\n\r\nThe IR at the time of that code running was\r\n```\r\n%2 = sub <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, %0\r\n%3 = select <4 x i1> <i1 false, i1 true, i1 poison, i1 poison>, <4 x i32> %2, <4 x i32> %0\r\n%4 = sub <4 x i32> zeroinitializer, %3\r\n```\r\n\r\nSo operand element 0 of %2 is poison. This occurred because element 0 isn't selected so SimplifiedDemandedVectorElts replaced with poison.\r\n\r\nOnce Negator swaps the operands, now element 1 of %2 is never selected so we end up with `sub <4 x i32> poison, %0`\r\n\r\nIt doesn't look like swapping the operands of the select is poison safe.\r\n\r\nCC @nikic " }, { "author": "nikic", "body": "Yeah, that analysis sounds right to me. With that in mind, a more direct test case would be:\r\n```llvm\r\ndefine <2 x i32> @f(<2 x i1> %c, <2 x i32> %x) {\r\n %neg = sub <2 x i32> <i32 0, i32 poison>, %x\r\n %sel = select <2 x i1> %c, <2 x i32> %neg, <2 x i32> %x\r\n %neg2 = sub <2 x i32> zeroinitializer, %sel\r\n ret <2 x i32> %neg2\r\n}\r\n```" }, { "author": "regehr", "body": "off topic but do we want an llvm-reduce pass that shrinks vectors? and maybe also shrinks lane sizes? if so I could work on that sort of thing this summer" }, { "author": "XChy", "body": "> off topic but do we want an llvm-reduce pass that shrinks vectors? and maybe also shrinks lane sizes? if so I could work on that sort of thing this summer\r\n\r\nSounds great to me. I think some SLPVectorizer testcases that involve 16 or even 32 lanes should be further reduced." } ] }
true
null
139060
https://github.com/llvm/llvm-project/issues/139060
crash
c3ca0fb91eaef9133315024550ef7b0ca7b0458a
2025-05-08T10:54:48
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "8c6c525a6bbb34a146a3d1f239757758e2d738e8", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 5571, 5576 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::computePredInstDiscount" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 8c6c525a6bbb34a146a3d1f239757758e2d738e8 Author: Florian Hahn <[email protected]> Date: Fri May 9 20:29:22 2025 +0100 [LV] Don't consider FORs as profitable to scalarize. Fixed-order recurrence phis cannot be scalarized, they will always be widened at the moment. Make sure they are not incorrectly considered profitable to scalarize, similar to 41c1a7be3f1a2556e. Fixes https://github.com/llvm/llvm-project/issues/139060. Fixes https://github.com/llvm/llvm-project/issues/139065. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b06bcbee9fdc..aabb04d03bc8 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5571,6 +5571,10 @@ InstructionCost LoopVectorizationCostModel::computePredInstDiscount( if (ScalarCosts.contains(I)) continue; + // Cannot scalarize fixed-order recurrence phis at the moment. + if (isa<PHINode>(I) && Legal->isFixedOrderRecurrence(cast<PHINode>(I))) + continue; + // Compute the cost of the vector instruction. Note that this cost already // includes the scalarization overhead of the predicated instruction. InstructionCost VectorCost = getInstructionCost(I, VF);
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/fixed-order-recurrence.ll", "commands": [ "opt -passes=loop-vectorize -S -o - %s" ], "tests": [ { "test_name": "test_first_order_recurrence_tried_to_scalarized", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc_linux\"\n\ndefine void @test_first_order_recurrence_tried_to_scalarized(ptr %dst, i1 %c, i32 %x) {\nentry:\n %N = select i1 %c, i32 8, i32 9\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %for = phi i32 [ 4, %entry ], [ %iv, %loop ]\n %iv.next = add nuw nsw i32 %iv, 1\n %sub = sub nsw i32 10, %for\n %gep.dst = getelementptr inbounds nuw i32, ptr %dst, i32 %iv\n store i32 %sub, ptr %gep.dst, align 4\n %ec = icmp eq i32 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Crash at -O2: Assertion `(BestFactor.Width == LegacyVF.Width ... failed", "body": "This code crashes at `-O2`:\n\n```c\nint *a;\nint b;\nvoid c(int d, int *g) {\n int e, f = g[0];\n e = 0;\n for (; e < d; e++) {\n a[e] = f + g[e + 1] - g[e];\n g[e] = f + g[e + 1];\n }\n}\nvoid h(int d, int g) { c(d, &g); }\nvoid i() {\n int j = 0;\n if (b)\n j = 1;\n h(j + 2, 4);\n}\nvoid main() {}\n```\n\nCompiler Explorer: https://godbolt.org/z/b1aTErPW1\n\nBisected to https://github.com/llvm/llvm-project/commit/673a4671f3e8b7158d990f6456428175a6eac38c, which was committed by @nikic \n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7667: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit() || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop) || planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\n```\n\nBacktrace:\n\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"i\"\n #0 0x0000000003f7c0a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f7c0a8)\n #1 0x0000000003f79d34 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f79d34)\n #2 0x0000000003ebebf8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x0000769685242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007696852969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x0000769685242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007696852287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x000076968522871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x0000769685239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000000005af0736 llvm::LoopVectorizationPlanner::computeBestVF() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5af0736)\n#10 0x0000000005b066aa llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b066aa)\n#11 0x0000000005b09280 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b09280)\n#12 0x0000000005b098d3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b098d3)\n#13 0x0000000005669c1e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5669c1e)\n#14 0x000000000391d5f0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x391d5f0)\n#15 0x0000000001200d3e 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/clang+0x1200d3e)\n#16 0x000000000391bec3 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x391bec3)\n#17 0x00000000011ffb8e 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/clang+0x11ffb8e)\n#18 0x000000000391b8d0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x391b8d0)\n#19 0x00000000042309de (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#20 0x0000000004233a61 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4233a61)\n#21 0x000000000491e800 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x491e800)\n#22 0x00000000065f0c0c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x65f0c0c)\n#23 0x000000000491ebe8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x491ebe8)\n#24 0x0000000004c11f15 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c11f15)\n#25 0x0000000004b9131e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b9131e)\n#26 0x0000000004d05d39 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d05d39)\n#27 0x0000000000da788f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda788f)\n#28 0x0000000000d9da5a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#29 0x00000000049854a9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#30 0x0000000003ebf094 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ebf094)\n#31 0x0000000004985abf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#32 0x0000000004947f0d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4947f0d)\n#33 0x0000000004948f9e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4948f9e)\n#34 0x0000000004950df5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4950df5)\n#35 0x0000000000da37f8 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda37f8)\n#36 0x0000000000c28b74 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc28b74)\n#37 0x0000769685229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#38 0x0000769685229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#39 0x0000000000d9d505 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9d505)\n```", "author": "cardigan1008", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "fhahn", "body": "taking a look" } ] }
true
null
134696
https://github.com/llvm/llvm-project/issues/134696
crash
b71123f1272ee081b18b8ced1925d6e9300e7310
2025-04-07T17:26:23
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "995fd47944f471e985e34d7da8c0667059decbac", "components": [ "LoopAccessAnalysis" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": [ [ 1781, 1787 ] ], "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": [ "MemoryDepChecker::couldPreventStoreLoadForward" ], "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 995fd47944f471e985e34d7da8c0667059decbac Author: Florian Hahn <[email protected]> Date: Sat Apr 12 20:05:37 2025 +0100 [LAA] Make sure MaxVF for Store-Load forward safe dep distances is pow2. MaxVF computed in couldPreventStoreLoadFowrard may not be a power of 2, as CommonStride may not be a power-of-2. This can cause crashes after 78777a20. Use bit_floor to make sure it is a suitable power-of-2. Fixes https://github.com/llvm/llvm-project/issues/134696. diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index a37ed5c706bd..0cb1332eb337 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1781,7 +1781,8 @@ bool MemoryDepChecker::couldPreventStoreLoadForward(uint64_t Distance, MaxStoreLoadForwardSafeDistanceInBits && MaxVFWithoutSLForwardIssuesPowerOf2 != VectorizerParams::MaxVectorWidth * TypeByteSize) { - uint64_t MaxVF = MaxVFWithoutSLForwardIssuesPowerOf2 / CommonStride; + uint64_t MaxVF = + bit_floor(MaxVFWithoutSLForwardIssuesPowerOf2 / CommonStride); uint64_t MaxVFInBits = MaxVF * TypeByteSize * 8; MaxStoreLoadForwardSafeDistanceInBits = std::min(MaxStoreLoadForwardSafeDistanceInBits, MaxVFInBits);
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/safe-dep-distance.ll", "commands": [ "opt < %s -passes=loop-vectorize -scalable-vectorization=on -riscv-v-vector-bits-min=-1 -mtriple riscv64-linux-gnu -mattr=+v,+f -S" ], "tests": [ { "test_name": "safe_load_store_distance_not_pow_of_2", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n64-S128\"\ntarget triple = \"riscv64\"\n\n@a = external global [10 x [12 x i16]]\n\ndefine void @safe_load_store_distance_not_pow_of_2(i64 %N) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr [10 x [12 x i16]], ptr @a, i64 0, i64 0, i64 %iv\n %0 = load i16, ptr %gep, align 2\n %gep.off = getelementptr [10 x [12 x i16]], ptr @a, i64 0, i64 8, i64 %iv\n store i16 0, ptr %gep.off, align 2\n %iv.next = add nsw i64 %iv, 3\n %cmp = icmp ult i64 %iv, %N\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize] Assertion `isPowerOf2_32(End.getKnownMinValue()) && \"Expected End to be a power of 2\"' failed.", "body": "Testcase:\n```llvm ir\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n@a = external global [0 x [12 x i16]]\n\ndefine void @b(i64 %0) #0 {\nentry:\n br label %for.cond3.preheader\n\nfor.cond3.preheader: ; preds = %for.cond3.preheader, %entry\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.cond3.preheader ]\n %arrayidx9 = getelementptr [0 x [12 x i16]], ptr @a, i64 0, i64 0, i64 %indvars.iv\n %1 = load i16, ptr %arrayidx9, align 2\n %arrayidx9.2 = getelementptr [0 x [12 x i16]], ptr @a, i64 0, i64 8, i64 %indvars.iv\n store i16 0, ptr %arrayidx9.2, align 2\n %indvars.iv.next = add nsw i64 %indvars.iv, 3\n %cmp = icmp ult i64 %indvars.iv, %0\n br i1 %cmp, label %for.cond3.preheader, label %for.cond.cleanup.loopexit\n\nfor.cond.cleanup.loopexit: ; preds = %for.cond3.preheader\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+v\" }\n```\n\nCommands/backtrace\n```\n$ /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt reduced.ll --passes=loop-vectorize\nWARNING: You're attempting to print out a bitcode file.\nThis is inadvisable as it may cause display problems. If\nyou REALLY want to taste LLVM bitcode first-hand, you\ncan force output with the `-f' option.\n\nopt: /scratch/ewlu/daily-upstream-build/llvm/llvm/lib/Transforms/Vectorize/VPlanHelpers.h:87: llvm::VFRange::VFRange(const llvm::ElementCount&, const llvm::ElementCount&): Assertion `isPowerOf2_32(End.getKnownMinValue()) && \"Expected End to be a power of 2\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt reduced.ll --passes=loop-vectorize\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"b\"\n #0 0x00005c0c5d95b1a2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x349c1a2)\n #1 0x00005c0c5d95820f llvm::sys::RunSignalHandlers() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x349920f)\n #2 0x00005c0c5d958354 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x0000774312045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x000077431209eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #5 0x000077431209eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #6 0x000077431209eb2c pthread_kill ./nptl/pthread_kill.c:89:10\n #7 0x000077431204527e raise ./signal/../sysdeps/posix/raise.c:27:6\n #8 0x00007743120288ff abort ./stdlib/abort.c:81:7\n #9 0x000077431202881b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n#10 0x000077431203b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)\n#11 0x00005c0c5c7b1baf llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x22f2baf)\n#12 0x00005c0c5c7b210d llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x22f310d)\n#13 0x00005c0c5c7b4105 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x22f5105)\n#14 0x00005c0c5c7b7511 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x22f8511)\n#15 0x00005c0c5c7b7ad7 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x22f8ad7)\n#16 0x00005c0c5b484b75 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfc5b75)\n#17 0x00005c0c5d74633a llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x328733a)\n#18 0x00005c0c5b4872b5 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfc82b5)\n#19 0x00005c0c5d744c14 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x3285c14)\n#20 0x00005c0c5b483265 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfc4265)\n#21 0x00005c0c5d74522d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x328622d)\n#22 0x00005c0c5ac19391 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) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x75a391)\n#23 0x00005c0c5ac0aeac optMain (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x74beac)\n#24 0x000077431202a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\n#25 0x000077431202a28b call_init ./csu/../csu/libc-start.c:128:20\n#26 0x000077431202a28b __libc_start_main ./csu/../csu/libc-start.c:347:5\n#27 0x00005c0c5ac014f5 _start (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x7424f5)\nAborted (core dumped)\n```\n\ngodbolt: https://godbolt.org/z/rKd5sx7xW\n\nFound via fuzzer (C program before reduction)", "author": "ewlu", "labels": [ "vectorizers", "crash", "generated by fuzzer" ], "comments": [] }
true
null
128736
https://github.com/llvm/llvm-project/issues/128736
crash
02128342d2818e5a65846fec4179ed5344045102
2025-02-25T16:27:23
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "39bab1de33333ee3c62b586c4e8d26f8c443bc60", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 1389, 1397 ], [ 2849, 2859 ], [ 2915, 2926 ], [ 16466, 16474 ], [ 17075, 17081 ], [ 20449, 20456 ], [ 20678, 20684 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::vectorizeTree", "removeInstructionsAndOperands", "tryToReduce" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 39bab1de33333ee3c62b586c4e8d26f8c443bc60 Author: Alexey Bataev <[email protected]> Date: Wed Feb 26 14:12:05 2025 -0800 [SLP]Check if the operand for removal is the reduction operand, awaiting for the reduction If the operand of the instruction-to-be-removed is a reduction value, which is not reduced yet, and, thus, it has no users, it may be removed during operands analysis. Fixes #128736 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index b25b09306aca..e8c91ebd508c 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1389,9 +1389,10 @@ public: /// Vectorize the tree but with the list of externally used values \p /// ExternallyUsedValues. Values in this MapVector can be replaced but the /// generated extractvalue instructions. - Value * - vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, - Instruction *ReductionRoot = nullptr); + Value *vectorizeTree( + const ExtraValueToDebugLocsMap &ExternallyUsedValues, + Instruction *ReductionRoot = nullptr, + ArrayRef<std::tuple<Value *, unsigned, bool>> VectorValuesAndScales = {}); /// \returns the cost incurred by unwanted spills and fills, caused by /// holding live values over call sites. @@ -2849,11 +2850,13 @@ public: /// Remove instructions from the parent function and clear the operands of \p /// DeadVals instructions, marking for deletion trivially dead operands. template <typename T> - void removeInstructionsAndOperands(ArrayRef<T *> DeadVals) { + void removeInstructionsAndOperands( + ArrayRef<T *> DeadVals, + ArrayRef<std::tuple<Value *, unsigned, bool>> VectorValuesAndScales) { SmallVector<WeakTrackingVH> DeadInsts; for (T *V : DeadVals) { auto *I = cast<Instruction>(V); - DeletedInstructions.insert(I); + eraseInstruction(I); } DenseSet<Value *> Processed; for (T *V : DeadVals) { @@ -2915,12 +2918,17 @@ public: // loop iteration. if (auto *OpI = dyn_cast<Instruction>(OpV)) if (!DeletedInstructions.contains(OpI) && + (!OpI->getType()->isVectorTy() || + none_of(VectorValuesAndScales, + [&](const std::tuple<Value *, unsigned, bool> &V) { + return std::get<0>(V) == OpI; + })) && isInstructionTriviallyDead(OpI, TLI)) DeadInsts.push_back(OpI); } VI->removeFromParent(); - DeletedInstructions.insert(VI); + eraseInstruction(VI); SE->forgetValue(VI); } } @@ -16466,9 +16474,10 @@ Value *BoUpSLP::vectorizeTree() { return vectorizeTree(ExternallyUsedValues); } -Value * -BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, - Instruction *ReductionRoot) { +Value *BoUpSLP::vectorizeTree( + const ExtraValueToDebugLocsMap &ExternallyUsedValues, + Instruction *ReductionRoot, + ArrayRef<std::tuple<Value *, unsigned, bool>> VectorValuesAndScales) { // All blocks must be scheduled before any instructions are inserted. for (auto &BSIter : BlocksSchedules) { scheduleBlock(BSIter.second.get()); @@ -17075,7 +17084,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, // cache correctness. // NOTE: removeInstructionAndOperands only marks the instruction for deletion // - instructions are not deleted until later. - removeInstructionsAndOperands(ArrayRef(RemovedInsts)); + removeInstructionsAndOperands(ArrayRef(RemovedInsts), VectorValuesAndScales); Builder.ClearInsertionPoint(); InstrElementSize.clear(); @@ -20449,8 +20458,8 @@ public: InsertPt = GetCmpForMinMaxReduction(RdxRootInst); // Vectorize a tree. - Value *VectorizedRoot = - V.vectorizeTree(LocalExternallyUsedValues, InsertPt); + Value *VectorizedRoot = V.vectorizeTree( + LocalExternallyUsedValues, InsertPt, VectorValuesAndScales); // Update TrackedToOrig mapping, since the tracked values might be // updated. for (Value *RdxVal : Candidates) { @@ -20678,7 +20687,7 @@ public: Ignore->replaceAllUsesWith(P); } } - V.removeInstructionsAndOperands(RdxOps); + V.removeInstructionsAndOperands(RdxOps, VectorValuesAndScales); } } else if (!CheckForReusedReductionOps) { for (ReductionOpsType &RdxOps : ReductionOps)
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-with-removed-extracts.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=znver2 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(i32 %arg) {\n;\nbb:\n br label %bb1\n\nbb1:\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run opt with the test below using -passes=slp-vectorizer.\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @wombat(i32 %arg) #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n \nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}\n\nattributes #0 = { \"target-cpu\"=\"znver2\" }\n```\n\nReproducer: https://godbolt.org/z/4PPzsMbP3\n\nStack dump:\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:4570: llvm::slpvectorizer::BoUpSLP::~BoUpSLP(): Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\n #0 0x00000000054546a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54546a8)\n #1 0x0000000005452064 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007b5c5f242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007b5c5f2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007b5c5f242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007b5c5f2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007b5c5f22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007b5c5f239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000440d177 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440d177)\n #9 0x00000000044d46ae 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\n#10 0x00000000044d50cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44d50cb)\n#11 0x000000000318a35e 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+0x318a35e)\n#12 0x000000000524e9e0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524e9e0)\n#13 0x0000000000e6f88e 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+0xe6f88e)\n#14 0x000000000524d2fb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524d2fb)\n#15 0x0000000000e6eb7e 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+0xe6eb7e)\n#16 0x000000000524cd00 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524cd00)\n#17 0x0000000000935e7a 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+0x935e7a)\n#18 0x00000000009294ec optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9294ec)\n#19 0x00007b5c5f229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#20 0x00007b5c5f229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#21 0x0000000000920dc5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920dc5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
112350
https://github.com/llvm/llvm-project/issues/112350
miscompilation
35e937b4de1890186347a382f7727ba86441dbda
2024-10-15T12:03:18
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "aad3a1630e385a6834f92a5f1d6045451ba21e4e", "components": [ "ValueTracking" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/include/llvm/IR/Instruction.h": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 8522, 8527 ], [ 8530, 8535 ] ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ "llvm::isKnownInversion" ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit aad3a1630e385a6834f92a5f1d6045451ba21e4e Author: Yingwei Zheng <[email protected]> Date: Thu Oct 17 00:27:21 2024 +0800 [ValueTracking] Respect `samesign` flag in `isKnownInversion` (#112390) In https://github.com/llvm/llvm-project/pull/93591 we introduced `isKnownInversion` and assumes `X` is poison implies `Y` is poison because they share common operands. But after introducing `samesign` this assumption no longer hold if `X` is an icmp has `samesign` flag. Alive2 link: https://alive2.llvm.org/ce/z/rj3EwQ (Please run it locally with this patch and https://github.com/AliveToolkit/alive2/pull/1098). This approach is the most conservative way in my mind to address this problem. If `X` has `samesign` flag, it will check if `Y` also has this flag and make sure constant RHS operands have the same sign. Fixes https://github.com/llvm/llvm-project/issues/112350. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index eb8d17044a17..e9ed8b3c862b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8522,6 +8522,10 @@ bool llvm::isKnownInversion(const Value *X, const Value *Y) { !match(Y, m_c_ICmp(Pred2, m_Specific(A), m_Value(C)))) return false; + // They must both have samesign flag or not. + if (cast<ICmpInst>(X)->hasSameSign() != cast<ICmpInst>(Y)->hasSameSign()) + return false; + if (B == C) return Pred1 == ICmpInst::getInversePredicate(Pred2); @@ -8530,6 +8534,11 @@ bool llvm::isKnownInversion(const Value *X, const Value *Y) { if (!match(B, m_APInt(RHSC1)) || !match(C, m_APInt(RHSC2))) return false; + // Sign bits of two RHSCs should match. + if (cast<ICmpInst>(X)->hasSameSign() && + RHSC1->isNonNegative() != RHSC2->isNonNegative()) + return false; + const auto CR1 = ConstantRange::makeExactICmpRegion(Pred1, *RHSC1); const auto CR2 = ConstantRange::makeExactICmpRegion(Pred2, *RHSC2);
[ { "file": "llvm/test/Transforms/InstCombine/select-cmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_select_inverse_nonconst4", "test_body": "define i1 @test_select_inverse_nonconst4(i64 %x, i64 %y, i64 %z, i1 %cond) {\n %cmp1 = icmp ult i64 %x, %y\n %cmp2 = icmp uge i64 %z, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_both", "test_body": "define i1 @test_select_inverse_samesign_both(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, %y\n %cmp2 = icmp samesign uge i64 %x, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_false_arm_rhsc_same_sign", "test_body": "define i1 @test_select_inverse_samesign_false_arm_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp ult i64 %x, 11\n %cmp2 = icmp samesign ugt i64 %x, 10\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_true_arm", "test_body": "define i1 @test_select_inverse_samesign_true_arm(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, %y\n %cmp2 = icmp uge i64 %x, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_true_arm_rhsc_same_sign", "test_body": "define i1 @test_select_inverse_samesign_true_arm_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, 11\n %cmp2 = icmp ugt i64 %x, 10\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_both_rhsc_diff_sign", "test_body": "define i1 @test_select_inverse_samesign_both_rhsc_diff_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign slt i64 %x, 0\n %cmp2 = icmp samesign sgt i64 %x, -1\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_both_rhsc_same_sign", "test_body": "define i1 @test_select_inverse_samesign_both_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, 11\n %cmp2 = icmp samesign ugt i64 %x, 10\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_select_inverse_samesign_false_arm", "test_body": "define i1 @test_select_inverse_samesign_false_arm(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp ult i64 %x, %y\n %cmp2 = icmp samesign uge i64 %x, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sel_icmp_two_cmp", "test_body": "define i1 @sel_icmp_two_cmp(i1 %c, i32 %a1, i32 %a2, i32 %a3, i32 %a4) {\n %v1 = call i8 @llvm.ucmp.i8.i32(i32 %a1, i32 %a2)\n %v2 = call i8 @llvm.scmp.i8.i32(i32 %a3, i32 %a4)\n %sel = select i1 %c, i8 %v1, i8 %v2\n %cmp = icmp sle i8 %sel, 0\n ret i1 %cmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.scmp.i8.i32(i32, i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.ucmp.i8.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped", "body": "Reproducer:\r\n```\r\ndefine i1 @src(i64 %x, i64 %y, i1 %cond) {\r\n %cmp1 = icmp ult i64 %x, %y\r\n %cmp2 = icmp samesign uge i64 %x, %y\r\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\r\n ret i1 %sel\r\n}\r\n\r\ndefine i1 @tgt(i64 %x, i64 %y, i1 %cond) {\r\n %cmp2 = icmp samesign uge i64 %x, %y\r\n %sel = xor i1 %cond, %cmp2\r\n ret i1 %sel\r\n}\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [ { "author": "antoniofrighetto", "body": "Don't we miss checking the flag in `hasPoisonGeneratingFlags`?" }, { "author": "dtcxzyw", "body": "> Don't we miss checking the flag in `hasPoisonGeneratingFlags`?\r\n\r\nYeah. I am preparing a patch.\r\n" }, { "author": "dtcxzyw", "body": "But adding support in `hasPoisonGeneratingFlags` doesn't address this issue :(\r\n" }, { "author": "antoniofrighetto", "body": "> But adding support in `hasPoisonGeneratingFlags` doesn't address this issue :(\r\n\r\nI assume we may need to `dropPoisonGeneratingFlags` in InstCombineCompares, where needed?" } ] }
true
null
131071
https://github.com/llvm/llvm-project/issues/131071
crash
fecd937910f640663885e0434bfed80cf4574072
2025-03-13T04:07:59
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2e13ec561c8139951e3f0815c35c758a7a3011db", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 7121, 7126 ], [ 9620, 9626 ], [ 9640, 9649 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": [ [ 1532, 1543 ] ], "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": [ [ 494, 501 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ [ 32, 38 ], [ 83, 88 ], [ 106, 111 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": [ [ 68, 79 ] ], "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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationPlanner::buildVPlan", "LoopVectorizationPlanner::planInVPlanNativePath", "LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": [ "LoopVectorizationPlanner::buildVPlans" ], "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::VPInstructionsToVPRecipes", "sinkScalarOperands" ], "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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 2e13ec561c8139951e3f0815c35c758a7a3011db Author: Florian Hahn <[email protected]> Date: Wed Mar 19 21:35:15 2025 +0000 [VPlan] Bail out on non-intrinsic calls in VPlanNativePath. Update initial VPlan-construction in VPlanNativePath in line with the inner loop path, in that it bails out when encountering constructs it cannot handle, like non-intrinsic calls. Fixes https://github.com/llvm/llvm-project/issues/131071. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h index ed3e45dd2c6c..7bbe8669cef6 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h @@ -494,8 +494,10 @@ protected: private: /// Build a VPlan according to the information gathered by Legal. \return a /// VPlan for vectorization factors \p Range.Start and up to \p Range.End - /// exclusive, possibly decreasing \p Range.End. - VPlanPtr buildVPlan(VFRange &Range); + /// exclusive, possibly decreasing \p Range.End. If no VPlan can be built for + /// the input range, set the largest included VF to the maximum VF for which + /// no plan could be built. + VPlanPtr tryToBuildVPlan(VFRange &Range); /// Build a VPlan using VPRecipes according to the information gather by /// Legal. This method is only used for the legacy inner loop vectorizer. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 89337dc38535..61e0d18445b6 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7121,6 +7121,9 @@ LoopVectorizationPlanner::planInVPlanNativePath(ElementCount UserVF) { << "VF " << VF << " to build VPlans.\n"); buildVPlans(VF, VF); + if (VPlans.empty()) + return VectorizationFactor::Disabled(); + // For VPlan build stress testing, we bail out after VPlan construction. if (VPlanBuildStressTest) return VectorizationFactor::Disabled(); @@ -9620,7 +9623,7 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) { return Plan; } -VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) { +VPlanPtr LoopVectorizationPlanner::tryToBuildVPlan(VFRange &Range) { // Outer loop handling: They may require CFG and instruction level // transformations before even evaluating whether vectorization is profitable. // Since we cannot modify the incoming IR, we need to build VPlan upfront in @@ -9640,10 +9643,13 @@ VPlanPtr LoopVectorizationPlanner::buildVPlan(VFRange &Range) { for (ElementCount VF : Range) Plan->addVF(VF); - VPlanTransforms::VPInstructionsToVPRecipes( - Plan, - [this](PHINode *P) { return Legal->getIntOrFpInductionDescriptor(P); }, - *PSE.getSE(), *TLI); + if (!VPlanTransforms::tryToConvertVPInstructionsToVPRecipes( + Plan, + [this](PHINode *P) { + return Legal->getIntOrFpInductionDescriptor(P); + }, + *PSE.getSE(), *TLI)) + return nullptr; // Tail folding is not supported for outer loops, so the induction increment // is guaranteed to not wrap. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index b63cdd04530a..ef82734840ed 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -1532,12 +1532,13 @@ void LoopVectorizationPlanner::buildVPlans(ElementCount MinVF, auto MaxVFTimes2 = MaxVF * 2; for (ElementCount VF = MinVF; ElementCount::isKnownLT(VF, MaxVFTimes2);) { VFRange SubRange = {VF, MaxVFTimes2}; - auto Plan = buildVPlan(SubRange); - VPlanTransforms::optimize(*Plan); - // Update the name of the latch of the top-level vector loop region region - // after optimizations which includes block folding. - Plan->getVectorLoopRegion()->getExiting()->setName("vector.latch"); - VPlans.push_back(std::move(Plan)); + if (auto Plan = tryToBuildVPlan(SubRange)) { + VPlanTransforms::optimize(*Plan); + // Update the name of the latch of the top-level vector loop region region + // after optimizations which includes block folding. + Plan->getVectorLoopRegion()->getExiting()->setName("vector.latch"); + VPlans.push_back(std::move(Plan)); + } VF = SubRange.End; } } diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index e6f788a18805..6c8680ac9661 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -32,7 +32,7 @@ using namespace llvm; -void VPlanTransforms::VPInstructionsToVPRecipes( +bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes( VPlanPtr &Plan, function_ref<const InductionDescriptor *(PHINode *)> GetIntOrFpInductionDescriptor, @@ -83,6 +83,9 @@ void VPlanTransforms::VPInstructionsToVPRecipes( } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) { NewRecipe = new VPWidenGEPRecipe(GEP, Ingredient.operands()); } else if (CallInst *CI = dyn_cast<CallInst>(Inst)) { + Intrinsic::ID VectorID = getVectorIntrinsicIDForCall(CI, &TLI); + if (VectorID == Intrinsic::not_intrinsic) + return false; NewRecipe = new VPWidenIntrinsicRecipe( *CI, getVectorIntrinsicIDForCall(CI, &TLI), {Ingredient.op_begin(), Ingredient.op_end() - 1}, CI->getType(), @@ -106,6 +109,7 @@ void VPlanTransforms::VPInstructionsToVPRecipes( Ingredient.eraseFromParent(); } } + return true; } static bool sinkScalarOperands(VPlan &Plan) { diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h index 2ec07eea1ecc..fe93637ab723 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h @@ -68,12 +68,13 @@ struct VPlanTransforms { bool RequiresScalarEpilogueCheck, bool TailFolded, Loop *TheLoop); /// Replaces the VPInstructions in \p Plan with corresponding - /// widen recipes. - static void - VPInstructionsToVPRecipes(VPlanPtr &Plan, - function_ref<const InductionDescriptor *(PHINode *)> - GetIntOrFpInductionDescriptor, - ScalarEvolution &SE, const TargetLibraryInfo &TLI); + /// widen recipes. Returns false if any VPInstructions could not be converted + /// to a wide recipe if needed. + static bool tryToConvertVPInstructionsToVPRecipes( + VPlanPtr &Plan, + function_ref<const InductionDescriptor *(PHINode *)> + GetIntOrFpInductionDescriptor, + ScalarEvolution &SE, const TargetLibraryInfo &TLI); /// Try to have all users of fixed-order recurrences appear after the recipe /// defining their previous value, by either sinking users or hoisting recipes
[ { "file": "llvm/test/Transforms/LoopVectorize/vplan-widen-call-instruction.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -enable-vplan-native-path -S %s" ], "tests": [ { "test_name": "call_to_non_intrinsic", "test_body": "define void @call_to_non_intrinsic() {\nentry:\n br label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi i64 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]\n br label %inner.header\n\ninner.header: ; preds = %inner.header, %outer.header\n %inner.iv = phi i64 [ 0, %outer.header ], [ %inner.iv.next, %inner.header ]\n call void @use()\n %inner.iv.next = add i64 %inner.iv, 1\n %inner.ec = icmp eq i64 %inner.iv.next, 100\n br i1 %inner.ec, label %outer.latch, label %inner.header\n\nouter.latch: ; preds = %inner.header\n %outer.iv.next = add i64 %outer.iv, 1\n %outer.ec = icmp eq i64 %outer.iv.next, 100\n br i1 %outer.ec, label %exit, label %outer.header, !llvm.loop !0\n\nexit: ; preds = %outer.latch\n ret void\n}\n\ndeclare void @use()\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize] Assertion `ID != Intrinsic::not_intrinsic && \"Not an intrinsic!\"' failed.", "body": "Reproducer: https://godbolt.org/z/n7E1TjTv5\n```\n; bin/opt -passes=loop-vectorize -enable-vplan-native-path reduced.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main() {\nentry:\n br label %for.cond2.preheader.i815\n\nfor.cond2.preheader.i815: ; preds = %for.cond.cleanup8.i835.split.us, %entry\n %I.03.i816 = phi i64 [ %inc20.i839, %for.cond.cleanup8.i835.split.us ], [ 0, %entry ]\n br label %cont.i830.us\n\ncont.i830.us: ; preds = %cont.i830.us, %for.cond2.preheader.i815\n %K.01.i824.us = phi i64 [ 0, %for.cond2.preheader.i815 ], [ %inc.i833.us, %cont.i830.us ]\n call void @use(ptr null, i64 0)\n %inc.i833.us = add i64 %K.01.i824.us, 1\n %exitcond.not.i834.us = icmp eq i64 %inc.i833.us, 0\n br i1 %exitcond.not.i834.us, label %for.cond.cleanup8.i835.split.us, label %cont.i830.us\n\nfor.cond.cleanup8.i835.split.us: ; preds = %cont.i830.us\n %inc20.i839 = add i64 %I.03.i816, 1\n %exitcond5.not.i840 = icmp eq i64 %inc20.i839, 0\n br i1 %exitcond5.not.i840, label %\"_ZZ4mainENK3$_7clEmmmPi.exit.loopexit1081\", label %for.cond2.preheader.i815, !llvm.loop !0\n\n\"_ZZ4mainENK3$_7clEmmmPi.exit.loopexit1081\": ; preds = %for.cond.cleanup8.i835.split.us\n ret i32 0\n}\n\ndeclare void @use(ptr, i64)\n\n!0 = distinct !{!0, !1, !2}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n```\n```\nopt: /root/llvm-project/llvm/lib/Analysis/VectorUtils.cpp:175: bool llvm::isVectorIntrinsicWithOverloadTypeAtArg(llvm::Intrinsic::ID, int, const llvm::TargetTransformInfo*): Assertion `ID != Intrinsic::not_intrinsic && \"Not an intrinsic!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize -enable-vplan-native-path <source>\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\n #0 0x0000000005475858 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5475858)\n #1 0x0000000005473214 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007024fda42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007024fda969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007024fda42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007024fda287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007024fda2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007024fda39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x0000000004bea5d7 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4bea5d7)\n #9 0x00000000045582f0 llvm::VPWidenIntrinsicRecipe::execute(llvm::VPTransformState&) (.part.0) VPlanRecipes.cpp:0:0\n#10 0x0000000004513ea7 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4513ea7)\n#11 0x000000000451e4cf llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x451e4cf)\n#12 0x000000000451f5c0 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x451f5c0)\n#13 0x000000000451f5c0 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x451f5c0)\n#14 0x000000000452b451 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x452b451)\n#15 0x00000000043ddd2f llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43ddd2f)\n#16 0x00000000043f0e36 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f0e36)\n#17 0x00000000043f45e9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f45e9)\n#18 0x00000000043f4c63 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f4c63)\n#19 0x000000000319510e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x319510e)\n#20 0x0000000005270840 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5270840)\n#21 0x0000000000e79f8e 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+0xe79f8e)\n#22 0x000000000526f15b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x526f15b)\n#23 0x0000000000e7910e 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+0xe7910e)\n#24 0x000000000526eb60 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x526eb60)\n#25 0x000000000094151a 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+0x94151a)\n#26 0x0000000000934c6c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x934c6c)\n#27 0x00007024fda29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#28 0x00007024fda29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#29 0x000000000092c755 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92c755)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\nReduced from llvm-test-suite/SingleSource/UnitTests/Vectorizer/VPlanNativePath/outer-loop-vect.cpp with ubsan+https://github.com/llvm/llvm-project/pull/130990 enabled\n\n\n", "author": "dtcxzyw", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "zhangjunphy", "body": "It seems for vplan vectorization, `LoopVectorizationLegality::canVectorize` only checks the loop structure and then skips the check of individual instructions. So the pass later tries to rewirte that call to `@use` and failed." }, { "author": "zhangjunphy", "body": "From the description of `isExplicitVecOuterLoop`. This does not seem to a problem of the LoopVectorization pass.\nWhen `-enable-vplan-native-path` is provided, LLVM only attempts to vectorize outer loops marked with a pragma.\nAnd the programmer is expected to ensure vectorization must be legal for those loops.\nhttps://github.com/llvm/llvm-project/blob/125553a6779ba179a9b4b5212c531da2474258fd/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp#L2183-L2192\n\n=============\nEdited for clarity." }, { "author": "dtcxzyw", "body": "Does ubsan instrumentation break this assumption?\n" }, { "author": "zhangjunphy", "body": "Well, I'm far from familiar with the design of vectorization and this is just my conclusion from reading the code.\n\nFrom what I understand, if the flag `-enable-vplan-native-path` is specified, the IR producer is required to be certain that the loop marked with \"llvm.loop.vectorize.enable\" is actually vectorizable. Otherwise this will cause problems as that flag will cause vectorization to bypass some legality checks and to directly attempt vectorizing the loop. \n\nIn this case, the instrumentation added the \"llvm.loop.vectorize.enable\" metadata to the loop. But there is the call to `@use` which is not vectorizable. And this check is bypassed with `-enable-vplan-native-path`, thus caused the problem." }, { "author": "fhahn", "body": "It is true that the native path somewhat relies on the loops being marked safe for vectorization by the user, we still shouldn't crash. In this particular case we can easily detect that we cannot create a valid VPlan, and bail out. I will prepare a fix." } ] }
true
null
85333
https://github.com/llvm/llvm-project/issues/85333
miscompilation
fa67986d5b309ddd4c2ea74e8a5eeb0559aa8022
2024-03-14T23:23:02
[ "llvm/test/Transforms/GVNSink" ]
{ "fix_commit": "1c979ab7e59feb03c58cac631a93143b0c776c20", "components": [ "GVNSink" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": [ [ 719, 730 ] ], "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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": [ "GVNSink::analyzeInstructionForSinking" ], "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1c979ab7e59feb03c58cac631a93143b0c776c20 Author: AdityaK <[email protected]> Date: Tue Apr 30 11:31:45 2024 -0700 [GVNSink] Fix incorrect codegen with respect to GEPs #85333 (#88440) As mentioned in #68882 and https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699 Gep arithmetic isn't consistent with different types. GVNSink didn't realize this and sank all geps as long as their operands can be wired via PHIs in a post-dominator. Fixes: #85333 diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp index d4907326eb0a..1d2577e1da33 100644 --- a/llvm/lib/Transforms/Scalar/GVNSink.cpp +++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp @@ -719,12 +719,11 @@ GVNSink::analyzeInstructionForSinking(LockstepReverseIterator &LRI, // try and continue making progress. Instruction *I0 = NewInsts[0]; - // If all instructions that are going to participate don't have the same - // number of operands, we can't do any useful PHI analysis for all operands. - auto hasDifferentNumOperands = [&I0](Instruction *I) { - return I->getNumOperands() != I0->getNumOperands(); + auto isNotSameOperation = [&I0](Instruction *I) { + return !I0->isSameOperationAs(I); }; - if (any_of(NewInsts, hasDifferentNumOperands)) + + if (any_of(NewInsts, isNotSameOperation)) return std::nullopt; for (unsigned OpNum = 0, E = I0->getNumOperands(); OpNum != E; ++OpNum) {
[ { "file": "llvm/test/Transforms/GVNSink/different-gep-types.ll", "commands": [ "opt -passes=gvn-sink -S %s" ], "tests": [ { "test_name": "bar", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\n\n%\"struct.std::pair\" = type <{ i32, %struct.substruct, [2 x i8] }>\n%struct.substruct = type { i8, i8 }\n\ndefine void @bar(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) {\nentry:\n %cmp = icmp eq i32 %__n, 1\n br i1 %cmp, label %if.then, label %if.else\n\nif.then: ; preds = %entry\n %0 = load ptr, ptr %__i, align 4\n %incdec.ptr4 = getelementptr inbounds i8, ptr %0, i32 -8\n br label %if.end6\n\nif.else: ; preds = %entry\n %1 = load ptr, ptr %__i, align 4\n %add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %1, i32 %__n\n br label %if.end6\n\nif.end6: ; preds = %if.else, %if.then\n %incdec.ptr.sink = phi ptr [ %incdec.ptr4, %if.then ], [ %add.ptr, %if.else ]\n store ptr %incdec.ptr.sink, ptr %__i, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\n\ndefine void @foo(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) {\nentry:\n %cmp = icmp eq i32 %__n, 1\n br i1 %cmp, label %if.then, label %if.else\n\nif.then: ; preds = %entry\n %0 = load ptr, ptr %__i, align 4\n %incdec.ptr = getelementptr inbounds i8, ptr %0, i32 8\n store ptr %incdec.ptr, ptr %__i, align 4\n br label %if.end6\n\nif.else: ; preds = %entry\n %cmp2 = icmp eq i32 %__n, -1\n br i1 %cmp2, label %if.then3, label %if.else5\n\nif.then3: ; preds = %if.else\n %1 = load ptr, ptr %__i, align 4\n %incdec.ptr4 = getelementptr inbounds i8, ptr %1, i32 -8\n store ptr %incdec.ptr4, ptr %__i, align 4\n br label %if.end6\n\nif.else5: ; preds = %if.else\n %2 = load ptr, ptr %__i, align 4\n %add.ptr = getelementptr inbounds i8, ptr %2, i32 -4\n store ptr %add.ptr, ptr %__i, align 4\n br label %if.end6\n\nif.end6: ; preds = %if.else5, %if.then3, %if.then\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "GVNSink produces incorrect codegen with respect to GEPs", "body": "```llvm\r\ntarget datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\r\ntarget triple = \"thumbv7em-none-unknown-eabi\"\r\n\r\n%\"struct.std::pair\" = type <{ i32, %struct.substruct, [2 x i8] }>\r\n%struct.substruct = type { i8, i8 }\r\n%\"struct.std::random_access_iterator_tag\" = type { i8 }\r\n\r\ndefine linkonce_odr dso_local void @__advance(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) local_unnamed_addr {\r\nentry:\r\n %0 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp = icmp eq i32 %__n, 1\r\n %or.cond = and i1 %0, %cmp\r\n br i1 %or.cond, label %if.then, label %if.else\r\n\r\nif.then: ; preds = %entry\r\n %1 = load ptr, ptr %__i, align 4\r\n %incdec.ptr = getelementptr inbounds i8, ptr %1, i32 8\r\n store ptr %incdec.ptr, ptr %__i, align 4\r\n br label %if.end6\r\n\r\nif.else: ; preds = %entry\r\n %2 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp2 = icmp eq i32 %__n, -1\r\n %or.cond7 = and i1 %2, %cmp2\r\n br i1 %or.cond7, label %if.then3, label %if.else5\r\n\r\nif.then3: ; preds = %if.else\r\n %3 = load ptr, ptr %__i, align 4\r\n %incdec.ptr4 = getelementptr inbounds i8, ptr %3, i32 -8\r\n store ptr %incdec.ptr4, ptr %__i, align 4\r\n br label %if.end6\r\n\r\nif.else5: ; preds = %if.else\r\n %4 = load ptr, ptr %__i, align 4\r\n %add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %4, i32 %__n\r\n store ptr %add.ptr, ptr %__i, align 4\r\n br label %if.end6\r\n\r\nif.end6: ; preds = %if.then3, %if.else5, %if.then\r\n ret void\r\n}\r\n```\r\n\r\nThe above IR when piped through gvn-sink via `./bin/opt < /tmp/repro.ll -passes=gvn-sink -S` produces:\r\n\r\n```llvm\r\n; ModuleID = '<stdin>'\r\nsource_filename = \"<stdin>\"\r\ntarget datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\r\ntarget triple = \"thumbv7em-none-unknown-eabi\"\r\n\r\ndefine linkonce_odr dso_local void @__advance(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) local_unnamed_addr {\r\nentry:\r\n %0 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp = icmp eq i32 %__n, 1\r\n %or.cond = and i1 %0, %cmp\r\n br i1 %or.cond, label %if.then, label %if.else\r\n\r\nif.then: ; preds = %entry\r\n br label %if.end6\r\n\r\nif.else: ; preds = %entry\r\n %1 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp2 = icmp eq i32 %__n, -1\r\n %or.cond7 = and i1 %1, %cmp2\r\n br i1 %or.cond7, label %if.then3, label %if.else5\r\n\r\nif.then3: ; preds = %if.else\r\n br label %if.end6\r\n\r\nif.else5: ; preds = %if.else\r\n br label %if.end6\r\n\r\nif.end6: ; preds = %if.else5, %if.then3, %if.then\r\n %.sink1 = phi i32 [ 8, %if.then ], [ -8, %if.then3 ], [ %__n, %if.else5 ]\r\n %2 = load ptr, ptr %__i, align 4\r\n %incdec.ptr = getelementptr inbounds i8, ptr %2, i32 %.sink1\r\n store ptr %incdec.ptr, ptr %__i, align 4\r\n ret void\r\n}\r\n\r\n; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)\r\ndeclare i1 @llvm.is.constant.i32(i32) #0\r\n\r\nattributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }\r\n```\r\n\r\nThe GEP in the result is incorrect. Prior, the GEPs were\r\n```llvm\r\n %incdec.ptr = getelementptr inbounds i8, ptr %1, i32 8\r\n %incdec.ptr4 = getelementptr inbounds i8, ptr %3, i32 -8\r\n %add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %4, i32 %__n\r\n```\r\nbut now it's\r\n```llvm\r\n%incdec.ptr = getelementptr inbounds i8, ptr %2, i32 %.sink1\r\n```\r\nThis results in an incorrect offset for `%add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %4, i32 %__n` since we'd now just add `%.sink1` bytes (where `%.sink1 = %__n` which is the second argument), whereas before we'd add `%__n * 8` bytes (where 8 is the sizeof `%\"struct.std::pair\"`).\r\n\r\nThe before ASM is:\r\n```asm\r\n__advance:\r\n ldr r2, [r0]\r\n add.w r1, r2, r1, lsl #3\r\n str r1, [r0]\r\n bx lr\r\n```\r\nbut the after asm is:\r\n```asm\r\n__advance:\r\n ldr r2, [r0]\r\n add r1, r2\r\n str r1, [r0]\r\n bx lr\r\n```\r\n\r\nThe GEP should not be a candidate for sinking.", "author": "PiJoules", "labels": [ "bug", "miscompilation", "llvm:GVN" ], "comments": [] }
true
null
128401
https://github.com/llvm/llvm-project/issues/128401
crash
22a5bb32b787443b70476cc1359709b6c888b591
2025-02-23T05:19:16
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "eb14d2a1d48fe76c5faed71a08547135a35ee742", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13320, 13328 ], [ 13874, 13888 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledEntry", "BoUpSLP::isGatherShuffledSingleRegisterEntry" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit eb14d2a1d48fe76c5faed71a08547135a35ee742 Author: Alexey Bataev <[email protected]> Date: Mon Feb 24 06:02:56 2025 -0800 [SLP]Fix check for matched gather node, if it is a subvector node If the gather node is a subvector node, it may match the existing vector/gather node in the graph, but still may require reordering. in this case need to fully check its dependencies to prevent a compiler crash. Fixes #128401 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index bf256d82ae17..5fc5fb10fad5 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13320,9 +13320,16 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( Entries.clear(); // TODO: currently checking only for Scalars in the tree entry, need to count // reused elements too for better cost estimation. - const EdgeInfo &TEUseEI = TE == VectorizableTree.front().get() - ? EdgeInfo(const_cast<TreeEntry *>(TE), 0) - : TE->UserTreeIndex; + auto GetUserEntry = [&](const TreeEntry *TE) { + while (TE->UserTreeIndex && TE->UserTreeIndex.EdgeIdx == UINT_MAX) + TE = TE->UserTreeIndex.UserTE; + if (TE == VectorizableTree.front().get()) + return EdgeInfo(const_cast<TreeEntry *>(TE), 0); + return TE->UserTreeIndex; + }; + const EdgeInfo TEUseEI = GetUserEntry(TE); + if (!TEUseEI) + return std::nullopt; const Instruction *TEInsertPt = &getLastInstructionInBundle(TEUseEI.UserTE); const BasicBlock *TEInsertBlock = nullptr; // Main node of PHI entries keeps the correct order of operands/incoming @@ -13874,15 +13881,13 @@ BoUpSLP::isGatherShuffledEntry( assert(VL.size() % NumParts == 0 && "Number of scalars must be divisible by NumParts."); if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->isGather() && - TE->UserTreeIndex.EdgeIdx == UINT_MAX) { - assert( - (TE->Idx == 0 || - (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || - isSplat(TE->Scalars) || - getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && - "Expected splat or extractelements only node."); + TE->UserTreeIndex.EdgeIdx == UINT_MAX && + (TE->Idx == 0 || + (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || + isSplat(TE->Scalars) || + (TE->hasState() && + getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)))) return {}; - } unsigned SliceSize = getPartNumElems(VL.size(), NumParts); SmallVector<std::optional<TTI::ShuffleKind>> Res; for (unsigned Part : seq<unsigned>(NumParts)) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/bv-matched-node-reorder.ll", "commands": [ "opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\n;\nentry:\n %l2.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %li.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %l1.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %l6.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %end\n\npre:\n br label %end\n\nend:\n %0 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n %1 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %9 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %10 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %11 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %12 = phi i8 [ %l1.i.i.i.i, %entry ], [ %3, %end ]\n %13 = phi i8 [ 0, %entry ], [ %2, %end ]\n %14 = phi i8 [ %l2.i.i.i.i, %entry ], [ %1, %end ]\n %15 = phi i8 [ %li.i.i.i, %entry ], [ %0, %end ]\n %16 = phi i8 [ 0, %entry ], [ %6, %end ]\n %17 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %18 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %19 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %20 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %21 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %22 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %c1.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %c1.i.1.i.i.i = icmp eq i8 %16, 0\n %c1.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %c1.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %c1.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %c1.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %c1.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %c1.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %c1.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `\"Expected splat or extractelements only node.\"' failed.", "body": "Reproducer: https://godbolt.org/z/9jx1xejoe\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.promoted42.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %.promoted.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %.promoted51.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %.promoted56.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %if.end151.1.i.1.i.i.i.i\n\nfor.cond79.preheader.us.preheader.1.i.1.i.i.i.i:\n br label %if.end151.1.i.1.i.i.i.i\n\nif.end151.1.i.1.i.i.i.i:\n %0 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n %1 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %9 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %10 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %11 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %12 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %3, %if.end151.1.i.1.i.i.i.i ]\n %13 = phi i8 [ 0, %entry ], [ %2, %if.end151.1.i.1.i.i.i.i ]\n %14 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %1, %if.end151.1.i.1.i.i.i.i ]\n %15 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %0, %if.end151.1.i.1.i.i.i.i ]\n %16 = phi i8 [ 0, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %17 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %18 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %19 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %20 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %21 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %22 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %cmp258.1.i.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %cmp258.1.i.i.1.i.i.i = icmp eq i8 %16, 0\n %cmp258.1.i.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %cmp258.1.i.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %cmp258.1.i.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %cmp258.1.i.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %cmp258.1.i.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %cmp258.1.i.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %cmp258.1.i.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13878: llvm::SmallVector<std::optional<llvm::TargetTransformInfo::ShuffleKind> > llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<const llvm::slpvectorizer::BoUpSLP::TreeEntry*> >&, unsigned int, bool): Assertion `(TE->Idx == 0 || (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || isSplat(TE->Scalars) || getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && \"Expected splat or extractelements only node.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005447b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5447b18)\n #1 0x00000000054454d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000072c4b8a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000072c4b8a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000072c4b8a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000072c4b8a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000072c4b8a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000072c4b8a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000447b405 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447b405)\n #9 0x000000000447c786 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447c786)\n#10 0x000000000447ec37 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+0x447ec37)\n#11 0x00000000044b3879 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44b3879)\n#12 0x00000000044bd45d llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44bd45d)\n#13 0x00000000044c1701 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c1701)\n#14 0x00000000044c1fab llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#15 0x00000000044c575f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c575f)\n#16 0x00000000044cbef6 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\n#17 0x00000000044cca4b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44cca4b)\n#18 0x0000000003182e1e 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+0x3182e1e)\n#19 0x00000000052431d0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52431d0)\n#20 0x0000000000e6e03e 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+0xe6e03e)\n#21 0x0000000005241aeb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5241aeb)\n#22 0x0000000000e6d34e 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+0xe6d34e)\n#23 0x00000000052414f0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52414f0)\n#24 0x0000000000935a5a 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+0x935a5a)\n#25 0x00000000009290cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290cc)\n#26 0x000072c4b8a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000072c4b8a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x00000000009209a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9209a5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\nllvm version: dbd219aef4be56754c793589c60bd787b7de60c2\n", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer" ], "comments": [] }
true
null
77064
https://github.com/llvm/llvm-project/issues/77064
crash
255f95a40377677dd762df5a1aa65bcbb4f75c79
2024-01-05T09:28:42
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a001e9718fd974859f2797a9f9ed7bf87d364e4f", "components": [ "SimplifyLibCalls" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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": [ [ 3735, 3760 ] ], "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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": [ "LibCallSimplifier::optimizeCall" ], "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a001e9718fd974859f2797a9f9ed7bf87d364e4f Author: Nikita Popov <[email protected]> Date: Fri Jan 5 10:41:44 2024 +0100 [SimplifyLibCalls] Don't try to manually reprocess calls The current code for reprocessing the result of fortified libcall simplifications is not correct, because we might simplify to an argument of the original call, and if that is again a libcall, mistakenly think that this is actually the simplification result. Instead of trying to fix this, simply remove the code entirely, because InstCombine nowadays correctly handles reprocessing of SimplifyLibCall results. Fixes https://github.com/llvm/llvm-project/issues/77064. diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 760a626c8b6f..a7cd68e860e4 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3735,26 +3735,8 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI, IRBuilderBase &Builder) { // Also try to simplify calls to fortified library functions. if (Value *SimplifiedFortifiedCI = - FortifiedSimplifier.optimizeCall(CI, Builder)) { - // Try to further simplify the result. - CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI); - if (SimplifiedCI && SimplifiedCI->getCalledFunction()) { - // Ensure that SimplifiedCI's uses are complete, since some calls have - // their uses analyzed. - replaceAllUsesWith(CI, SimplifiedCI); - - // Set insertion point to SimplifiedCI to guarantee we reach all uses - // we might replace later on. - IRBuilderBase::InsertPointGuard Guard(Builder); - Builder.SetInsertPoint(SimplifiedCI); - if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, Builder)) { - // If we were able to further simplify, remove the now redundant call. - substituteInParent(SimplifiedCI, V); - return V; - } - } + FortifiedSimplifier.optimizeCall(CI, Builder)) return SimplifiedFortifiedCI; - } // Then check for known library functions. if (TLI->getLibFunc(*Callee, Func) && isLibFuncEmittable(M, TLI, Func)) {
[ { "file": "llvm/test/Transforms/InstCombine/pr77064.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "main", "test_body": "define void @main(ptr %ptr) {\n %opendir = call fastcc ptr @opendir(ptr %ptr)\n %memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)\n ret void\n}\n\ndeclare ptr @__memset_chk(ptr, i32, i64, i64)\n\ndeclare fastcc ptr @opendir(ptr)\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SimplifyLibCalls] Calling convention assertion fails", "body": "```llvm\r\n; RUN: opt -S -passes=instcombine\r\ndefine void @main(ptr %ptr) {\r\n %opendir = call fastcc ptr @opendir(ptr %ptr)\r\n %memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)\r\n ret void\r\n}\r\n\r\ndeclare ptr @__memset_chk(ptr, i32, i64, i64)\r\n\r\ndeclare fastcc ptr @opendir(ptr)\r\n```\r\n\r\n> opt: /home/npopov/repos/llvm-project/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:3488: Value *llvm::LibCallSimplifier::optimizeStringMemoryLibCall(CallInst *, IRBuilderBase &): Assertion `(ignoreCallingConv(Func) || TargetLibraryInfoImpl::isCallingConvCCompatible(CI)) && \"Optimizing string/memory libcall would change the calling convention\"' failed.\r\n\r\nEncountered when building openjpeg2.", "author": "nikic", "labels": [ "llvm:crash", "llvm:instcombine" ], "comments": [] }
true
null
133751
https://github.com/llvm/llvm-project/issues/133751
crash
2d7add6e2e56baf46504a8a22dec42b61f63360f
2025-03-31T16:55:56
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "bfd8cc0a3e82c5e6345a66dd5db5242accb6874b", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 8854, 8860 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit bfd8cc0a3e82c5e6345a66dd5db5242accb6874b Author: Alexey Bataev <[email protected]> Date: Mon Mar 31 10:31:18 2025 -0700 [SLP]Fix a check for the whole register use Need to check the value type, not the return type, of the instructions, when doing the analysis for the whole register use to prevent a compiler crash. Fixes #133751 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index a4b0378abc07..0679eac17658 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -8854,7 +8854,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, // FIXME: Reshuffing scalars is not supported yet for non-power-of-2 ops. if ((UserTreeIdx.UserTE && UserTreeIdx.UserTE->hasNonWholeRegisterOrNonPowerOf2Vec(*TTI)) || - !hasFullVectorsOrPowerOf2(*TTI, VL.front()->getType(), VL.size())) { + !hasFullVectorsOrPowerOf2(*TTI, getValueType(VL.front()), + VL.size())) { LLVM_DEBUG(dbgs() << "SLP: Reshuffling scalars not yet supported " "for nodes with padding.\n"); auto Invalid = ScheduleBundle::invalid();
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/cmp-values-non-full-registers.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-grtev4-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nentry:\n br i1 false, label %bb1, label %bb2\n\nbb2:\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %bb1\n\nbb1:\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %bb2 ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %bb2 ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %bb2 ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %bb2 ]\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "SLPVectorizer: \"Reshuffling scalars not yet supported for nodes with padding\" assert", "body": "```\n$ cat /tmp/a.ll\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\"\ntarget triple = \"x86_64-grtev4-linux-gnu\"\n\ndefine void @gsl_matrix_long_double_minmax_index() {\nentry:\n br i1 false, label %cleanup22, label %for.cond6.preheader.us.preheader\n\nfor.cond6.preheader.us.preheader: ; preds = %entry\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %cleanup22\n\ncleanup22: ; preds = %for.cond6.preheader.us.preheader, %entry\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %for.cond6.preheader.us.preheader ]\n ret void\n}\n$ opt -p slp-vectorizer /tmp/a.ll -disable-output\nopt: ../../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3714: TreeEntry *llvm::slpvectorizer::BoUpSLP::newTreeEntry(ArrayRef<Value *>, TreeEntry::EntryState, ScheduleBundle &, const InstructionsState &, const EdgeInfo &, ArrayRef<int>, ArrayRef<unsigned int>): Assertion `(hasFullVectorsOrPowerOf2(*TTI, \ngetValueType(VL.front()), VL.size()) || ReuseShuffleIndices.empty()) && \"Reshuffling scalars not yet supported for nodes with padding\"' failed. \n\n```\n\n@alexey-bataev ", "author": "aeubanks", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
106780
https://github.com/llvm/llvm-project/issues/106780
crash
5aa83eb677d2f8cba0c2ad3dcc14f3f4e80a0bba
2024-08-30T19:02:15
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "654bb4e9f287f9ccb5142d1c62a9ab17c16e29d7", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6817, 6822 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::collectValuesToIgnore" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 654bb4e9f287f9ccb5142d1c62a9ab17c16e29d7 Author: Florian Hahn <[email protected]> Date: Sun Sep 1 20:35:28 2024 +0100 [LV] Don't consider branches leaving loop in collectValuesToIgnore. Branches exiting the loop will remain regardless, so don't consider them in collectValuesToIgnore. This fixes another divergence between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/106780. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index fa05b8dd2242..a8722db654f5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6817,6 +6817,9 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { if (auto *Br = dyn_cast_or_null<BranchInst>(Op)) { BasicBlock *ThenBB = Br->getSuccessor(0); BasicBlock *ElseBB = Br->getSuccessor(1); + // Don't considers branches leaving the loop for simplification. + if (!TheLoop->contains(ThenBB) || !TheLoop->contains(ElseBB)) + continue; bool ThenEmpty = IsEmptyBlock(ThenBB); bool ElseEmpty = IsEmptyBlock(ElseBB); if ((ThenEmpty && ElseEmpty) ||
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll", "commands": [ "opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s" ], "tests": [ { "test_name": "dead_load", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cost_of_exit_branch_and_cond_insts", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.umax.i16(i16, i16) #0\n\ndefine i32 @cost_of_exit_branch_and_cond_insts(ptr %a, ptr %b, i1 %c, i16 %x) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.exiting\n\nthen: ; preds = %loop.header\n %gep = getelementptr inbounds i32, ptr %b, i32 %iv\n store i1 false, ptr %a, align 1\n store i32 0, ptr %gep, align 4\n br label %loop.exiting\n\nloop.exiting: ; preds = %then, %loop.header\n %iv.next = add i32 %iv, 1\n %umax = tail call i16 @llvm.umax.i16(i16 %x, i16 111)\n %umax.ext = zext i16 %umax to i32\n %sub = sub i32 770, %umax.ext\n %ec = icmp slt i32 %iv, %sub\n br i1 %ec, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop.exiting\n br label %loop.header\n\nexit: ; preds = %loop.exiting\n br label %return\n\nreturn: ; preds = %exit\n ret i32 0\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dead_live_out_due_to_scalar_epilogue_required", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i8 @dead_live_out_due_to_scalar_epilogue_required(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %idxprom = sext i32 %iv to i64\n %gep.src = getelementptr i8, ptr %src, i64 %idxprom\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %idxprom\n store i8 0, ptr %gep.dst, align 1\n %iv.next = add i32 %iv, 4\n %cmp = icmp ult i32 %iv, 1001\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n %r = phi i8 [ %l, %loop ]\n ret i8 %r\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using ef7b18a53c0d186dcda1e322be6035407fdedb55\r\n\r\nTestcase:\r\n```c\r\nunsigned short a;\r\nextern int b;\r\nvoid c(_Bool d, int e, long long f[], unsigned short g[][16],\r\n unsigned short h[][16], unsigned short i[][13], short j[][13],\r\n int k[][21], unsigned char l[][21][21], signed char m[][24]) {\r\n for (short n = 0; n < 5; n += -5532)\r\n for (char o = 0; o < 3; o += d)\r\n for (int p = 0; p < -({ g[d][1] > 0115 ? g[d][1] : 0115; }) + 770; p++)\r\n for (_Bool q = 0; q < (_Bool)e; q = 5)\r\n for (_Bool r = 2048749519 ? 8 ? f[d] : 0 : 0; r < 1; r = h)\r\n b = a = 0;\r\n}\r\nvoid hash();\r\nunsigned short a = 6;\r\nlong long f[6];\r\nunsigned short g[6][16];\r\nunsigned short h[1][16];\r\nunsigned short i[1][13];\r\nshort j[1][13];\r\nint k[1][21];\r\nunsigned char l[1][21][21];\r\nsigned char m[1][24];\r\nint main() {\r\n for (long s = 0; s < 6; ++s)\r\n f[s] = 6;\r\n for (long s = 0; s < 16; ++s)\r\n for (long n = 0; n < 16; ++n)\r\n g[s][n] = 7;\r\n c(1, 407418382874, f, g, h, i, j, k, l, m);\r\n hash(a);\r\n}\r\n```\r\nc command:\r\n```\r\n/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -fno-strict-aliasing -march=rv64gcv -flto -O3 -fuse-ld=lld red.c -o rv64gcv.out -w\r\n```\r\n\r\nLLVM IR testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i16 @llvm.umax.i16(i16, i16) #0\r\n\r\ndefine i32 @main(ptr %a) #1 {\r\nentry:\r\n br label %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n\r\nfor.cond22.preheader.us.us76.us.us.us.us.i.1: ; preds = %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1, %entry\r\n %p.072.us.us77.us.us.us.us.i.1 = phi i32 [ %inc.us.us80.us.us.us.us.i.1, %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1 ], [ 0, %entry ]\r\n br i1 false, label %for.body41.lr.ph.us.us.us.us.us.us.us.i.1, label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n\r\nfor.body41.lr.ph.us.us.us.us.us.us.us.i.1: ; preds = %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n store i1 false, ptr %a, align 1\r\n store i32 0, ptr null, align 4\r\n br label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n\r\nfor.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1: ; preds = %for.body41.lr.ph.us.us.us.us.us.us.us.i.1, %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n %inc.us.us80.us.us.us.us.i.1 = add i32 %p.072.us.us77.us.us.us.us.i.1, 1\r\n %narrow.us.us81.us.us.us.us.i.1 = tail call i16 @llvm.umax.i16(i16 0, i16 0)\r\n %spec.select.us.us82.us.us.us.us.i.1 = zext i16 %narrow.us.us81.us.us.us.us.i.1 to i32\r\n %add.us.us83.us.us.us.us.i.1 = sub i32 770, %spec.select.us.us82.us.us.us.us.i.1\r\n %cmp18.us.us84.us.us.us.us.i.1 = icmp slt i32 %p.072.us.us77.us.us.us.us.i.1, %add.us.us83.us.us.us.us.i.1\r\n br i1 %cmp18.us.us84.us.us.us.us.i.1, label %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1, label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge\r\n\r\nfor.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n br label %for.cond.cleanup20.us.us.us.us.i.1\r\n\r\nfor.cond.cleanup20.us.us.us.us.i.1: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge\r\n ret i32 0\r\n\r\nfor.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n br label %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n}\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #1 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7366: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' 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. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x00005e8221f7d690 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301e690)\r\n #1 0x00005e8221f7aa9f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301ba9f)\r\n #2 0x00005e8221f7abf5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000772c88c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000772c88c969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000772c88c969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x0000772c88c969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000772c88c42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x0000772c88c287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x0000772c88c2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000772c88c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005e8220f4a3e0 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1feb3e0)\r\n#12 0x00005e8220f60ffb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2001ffb)\r\n#13 0x00005e8220f64011 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2005011)\r\n#14 0x00005e8220f64687 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2005687)\r\n#15 0x00005e821fdc0fb6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe61fb6)\r\n#16 0x00005e8221d8858f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2958f)\r\n#17 0x00005e821fdc4146 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe65146)\r\n#18 0x00005e8221d8730b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2830b)\r\n#19 0x00005e821fdc03e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe613e6)\r\n#20 0x00005e8221d8534d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2634d)\r\n#21 0x00005e821f5e6ee6 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) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x687ee6)\r\n#22 0x00005e821f5d8c71 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679c71)\r\n#23 0x0000772c88c29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x0000772c88c29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x0000772c88c29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005e821f5cf025 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x670025)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/ej1Gax953\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/106641\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
150479
https://github.com/llvm/llvm-project/issues/150479
crash
8952225d88a5ce58a65c8b8695c610f4499d7181
2025-07-24T17:33:31
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "c9cea24fe68e24750b2d479144f839e1c2ec9d2b", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 6861, 6867 ], [ 15704, 15710 ], [ 15803, 15809 ], [ 15816, 15822 ], [ 16438, 16461 ], [ 16470, 16482 ], [ 16512, 16522 ], [ 16554, 16560 ], [ 16586, 16592 ], [ 21001, 21009 ], [ 21253, 21258 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::computeMinimumValueSizes", "BoUpSLP::getLastInstructionInBundle", "BoUpSLP::getReorderingData", "BoUpSLP::isGatherShuffledSingleRegisterEntry" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit c9cea24fe68e24750b2d479144f839e1c2ec9d2b Author: Alexey Bataev <[email protected]> Date: Thu Jul 24 11:40:26 2025 -0700 [SLP] Check if the user node has state before trying getting main instruction/opcode Need to check if the parent node has state to prevent compiler crashes. Fixes #150479 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 0adad5a90d31..44dc43d5e77c 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6861,7 +6861,7 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom, return std::move(ResOrder); } if (TE.State == TreeEntry::StridedVectorize && !TopToBottom && - (!TE.UserTreeIndex || + (!TE.UserTreeIndex || !TE.UserTreeIndex.UserTE->hasState() || !Instruction::isBinaryOp(TE.UserTreeIndex.UserTE->getOpcode())) && (TE.ReorderIndices.empty() || isReverseOrder(TE.ReorderIndices))) return std::nullopt; @@ -15704,7 +15704,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( const BasicBlock *TEInsertBlock = nullptr; // Main node of PHI entries keeps the correct order of operands/incoming // blocks. - if (auto *PHI = dyn_cast<PHINode>(TEUseEI.UserTE->getMainOp()); + if (auto *PHI = dyn_cast_or_null<PHINode>( + TEUseEI.UserTE->hasState() ? TEUseEI.UserTE->getMainOp() : nullptr); PHI && TEUseEI.UserTE->State != TreeEntry::SplitVectorize) { TEInsertBlock = PHI->getIncomingBlock(TEUseEI.EdgeIdx); TEInsertPt = TEInsertBlock->getTerminator(); @@ -15803,7 +15804,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( "Expected only single user of a gather node."); const EdgeInfo &UseEI = TEPtr->UserTreeIndex; - PHINode *UserPHI = UseEI.UserTE->State != TreeEntry::SplitVectorize + PHINode *UserPHI = (UseEI.UserTE->State != TreeEntry::SplitVectorize && + UseEI.UserTE->hasState()) ? dyn_cast<PHINode>(UseEI.UserTE->getMainOp()) : nullptr; Instruction *InsertPt = @@ -15816,7 +15818,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( TEUseEI.UserTE->isAltShuffle()) && all_of(TEUseEI.UserTE->Scalars, isUsedOutsideBlock)) { if (UseEI.UserTE->State != TreeEntry::Vectorize || - (UseEI.UserTE->getOpcode() == Instruction::PHI && + (UseEI.UserTE->hasState() && + UseEI.UserTE->getOpcode() == Instruction::PHI && !UseEI.UserTE->isAltShuffle()) || !all_of(UseEI.UserTE->Scalars, isUsedOutsideBlock)) continue; @@ -16438,24 +16441,31 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { // Get the basic block this bundle is in. All instructions in the bundle // should be in this block (except for extractelement-like instructions with // constant indices or gathered loads or copyables). - auto *Front = E->getMainOp(); + Instruction *Front; + unsigned Opcode; + if (E->hasState()) { + Front = E->getMainOp(); + Opcode = E->getOpcode(); + } else { + Front = cast<Instruction>(*find_if(E->Scalars, IsaPred<Instruction>)); + Opcode = Front->getOpcode(); + } auto *BB = Front->getParent(); - assert(((GatheredLoadsEntriesFirst.has_value() && - E->getOpcode() == Instruction::Load && E->isGather() && - E->Idx < *GatheredLoadsEntriesFirst) || - E->State == TreeEntry::SplitVectorize || E->hasCopyableElements() || - all_of(E->Scalars, - [=](Value *V) -> bool { - if (E->getOpcode() == Instruction::GetElementPtr && - !isa<GetElementPtrInst>(V)) - return true; - auto *I = dyn_cast<Instruction>(V); - return !I || !E->getMatchingMainOpOrAltOp(I) || - I->getParent() == BB || - isVectorLikeInstWithConstOps(I); - })) && - "Expected gathered loads or GEPs or instructions from same basic " - "block."); + assert( + ((GatheredLoadsEntriesFirst.has_value() && Opcode == Instruction::Load && + E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) || + E->State == TreeEntry::SplitVectorize || E->hasCopyableElements() || + all_of(E->Scalars, + [=](Value *V) -> bool { + if (Opcode == Instruction::GetElementPtr && + !isa<GetElementPtrInst>(V)) + return true; + auto *I = dyn_cast<Instruction>(V); + return !I || !E->getMatchingMainOpOrAltOp(I) || + I->getParent() == BB || isVectorLikeInstWithConstOps(I); + })) && + "Expected gathered loads or GEPs or instructions from same basic " + "block."); auto FindLastInst = [&]() { Instruction *LastInst = Front; @@ -16470,13 +16480,13 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { LastInst = I; continue; } - assert(((E->getOpcode() == Instruction::GetElementPtr && + assert(((Opcode == Instruction::GetElementPtr && !isa<GetElementPtrInst>(I)) || E->State == TreeEntry::SplitVectorize || (isVectorLikeInstWithConstOps(LastInst) && isVectorLikeInstWithConstOps(I)) || (GatheredLoadsEntriesFirst.has_value() && - E->getOpcode() == Instruction::Load && E->isGather() && + Opcode == Instruction::Load && E->isGather() && E->Idx < *GatheredLoadsEntriesFirst)) && "Expected vector-like or non-GEP in GEP node insts only."); if (!DT->isReachableFromEntry(LastInst->getParent())) { @@ -16512,11 +16522,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { FirstInst = I; continue; } - assert(((E->getOpcode() == Instruction::GetElementPtr && - !isa<GetElementPtrInst>(I)) || - (isVectorLikeInstWithConstOps(FirstInst) && - isVectorLikeInstWithConstOps(I))) && - "Expected vector-like or non-GEP in GEP node insts only."); + assert(((Opcode == Instruction::GetElementPtr && + !isa<GetElementPtrInst>(I)) || + (isVectorLikeInstWithConstOps(FirstInst) && + isVectorLikeInstWithConstOps(I))) && + "Expected vector-like or non-GEP in GEP node insts only."); if (!DT->isReachableFromEntry(FirstInst->getParent())) { FirstInst = I; continue; @@ -16554,7 +16564,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { // Set insertpoint for gathered loads to the very first load. if (GatheredLoadsEntriesFirst.has_value() && E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() && - E->getOpcode() == Instruction::Load) { + Opcode == Instruction::Load) { Res = FindFirstInst(); EntryToLastInstruction.try_emplace(E, Res); return *Res; @@ -16586,7 +16596,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { }; const ScheduleBundle *Bundle = FindScheduleBundle(E); if (!E->isGather() && !Bundle) { - if ((E->getOpcode() == Instruction::GetElementPtr && + if ((Opcode == Instruction::GetElementPtr && any_of(E->Scalars, [](Value *V) { return !isa<GetElementPtrInst>(V) && isa<Instruction>(V); @@ -21001,9 +21011,10 @@ void BoUpSLP::computeMinimumValueSizes() { if (!isa<CastInst, BinaryOperator, FreezeInst, PHINode, SelectInst>(U) || isa<SIToFPInst, UIToFPInst>(U) || - !isa<CastInst, BinaryOperator, FreezeInst, PHINode, - SelectInst>(UserTE->getMainOp()) || - isa<SIToFPInst, UIToFPInst>(UserTE->getMainOp())) + (UserTE->hasState() && + (!isa<CastInst, BinaryOperator, FreezeInst, PHINode, + SelectInst>(UserTE->getMainOp()) || + isa<SIToFPInst, UIToFPInst>(UserTE->getMainOp())))) return true; unsigned UserTESz = DL->getTypeSizeInBits( UserTE->Scalars.front()->getType()); @@ -21253,6 +21264,7 @@ void BoUpSLP::computeMinimumValueSizes() { NodeIdx < VectorizableTree.size() && VectorizableTree[NodeIdx]->UserTreeIndex && VectorizableTree[NodeIdx]->UserTreeIndex.EdgeIdx == 0 && + VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->hasState() && VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->getOpcode() == Instruction::Trunc && !VectorizableTree[NodeIdx]->UserTreeIndex.UserTE->isAltShuffle();
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/user-node-no-state.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@g = global [128 x i8] zeroinitializer, align 16\n\ndefine i64 @test() {\n;\nentry:\n %0 = load i64, ptr @g, align 8\n br label %func_154.exit.func_146.exit_crit_edge.i\n\nfunc_154.exit.func_146.exit_crit_edge.i:\n %1 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 80), align 16\n %2 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 88), align 8\n %3 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 32), align 16\n %4 = load i64, ptr @g, align 16\n %5 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 8), align 8\n %6 = load i64, ptr @g, align 16\n %7 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 24), align 8\n %8 = xor i64 %1, %2\n %9 = xor i64 %8, %3\n %10 = xor i64 %9, %4\n %11 = xor i64 %10, %5\n %12 = xor i64 %11, %6\n %13 = xor i64 %12, %7\n %14 = xor i64 %13, %0\n ret i64 %14\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `valid() && \"InstructionsState is invalid.\"' failed.", "body": "Reproducer: https://godbolt.org/z/Pj96ao9TK\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@g = global [128 x i8] zeroinitializer, align 16\n\ndefine i64 @main() {\nentry:\n %0 = load i64, ptr @g, align 8\n br label %func_154.exit.func_146.exit_crit_edge.i\n\nfunc_154.exit.func_146.exit_crit_edge.i: ; preds = %entry\n %1 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 80), align 16\n %2 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 88), align 8\n %3 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 32), align 16\n %4 = load i64, ptr @g, align 16\n %5 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 8), align 8\n %6 = load i64, ptr @g, align 16\n %7 = load i64, ptr getelementptr inbounds nuw (i8, ptr @g, i64 24), align 8\n %8 = xor i64 %1, %2\n %9 = xor i64 %8, %3\n %10 = xor i64 %9, %4\n %11 = xor i64 %10, %5\n %12 = xor i64 %11, %6\n %13 = xor i64 %12, %7\n %14 = xor i64 %13, %0\n ret i64 %14\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:1204: llvm::Instruction* {anonymous}::InstructionsState::getMainOp() const: Assertion `valid() && \"InstructionsState is invalid.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005664458 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5664458)\n #1 0x0000000005661304 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000075a3c1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000075a3c12969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000075a3c1242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000075a3c12287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000075a3c122871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000075a3c1239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000034a0043 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x34a0043)\n #9 0x0000000003513355 llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3513355)\n#10 0x000000000355424e llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::MutableArrayRef<int>, llvm::SmallVectorImpl<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355424e)\n#11 0x0000000003558408 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3558408)\n#12 0x000000000355a2de llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x355a2de)\n#13 0x000000000355c98f 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+0x355c98f)\n#14 0x000000000359597f llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>, llvm::InstructionCost) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359597f)\n#15 0x000000000359ba1b (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#16 0x000000000359ef90 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359ef90)\n#17 0x00000000035a430b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x00000000035a8c0f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35a8c0f)\n#19 0x00000000035aef06 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\n#20 0x00000000035af9eb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x35af9eb)\n#21 0x0000000002dab8ce 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+0x2dab8ce)\n#22 0x0000000005456241 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5456241)\n#23 0x0000000000eb675e 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+0xeb675e)\n#24 0x0000000005456714 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5456714)\n#25 0x0000000000eb6a2e 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+0xeb6a2e)\n#26 0x00000000054542e1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54542e1)\n#27 0x0000000000964bfa 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+0x964bfa)\n#28 0x0000000000958c79 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x958c79)\n#29 0x000075a3c1229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#30 0x000075a3c1229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#31 0x000000000094fd45 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94fd45)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n\nI found this crash when fuzzing the code in https://github.com/llvm/llvm-project/pull/137297.\n", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer" ], "comments": [] }
true
null
105785
https://github.com/llvm/llvm-project/issues/105785
miscompilation
1241c762c165972690c4edfb82ec7421c1e64658
2024-08-23T05:45:52
[ "llvm/test/Transforms/ConstraintElimination" ]
{ "fix_commit": "85b6aac7c25f9d2a976a76045ace1e7afebb5965", "components": [ "ConstraintElimination" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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": [ [ 1464, 1470 ] ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ "checkAndReplaceCmp" ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 3ff9d92aae0945daa85ec6f85f05a3aeaaa9f962 Author: Yingwei Zheng <[email protected]> Date: Fri Aug 23 16:06:00 2024 +0800 [ConstraintElim] Fix miscompilation caused by PR97974 (#105790) Fixes https://github.com/llvm/llvm-project/issues/105785. (cherry picked from commit 85b6aac7c25f9d2a976a76045ace1e7afebb5965) diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index c31173879af1..37022104d0a9 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1464,7 +1464,7 @@ static bool checkAndReplaceCmp(CmpIntrinsic *I, ConstraintInfo &Info, ToRemove.push_back(I); return true; } - if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info)) { + if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info).value_or(false)) { I->replaceAllUsesWith(ConstantInt::get(I->getType(), 0)); ToRemove.push_back(I); return true;
[ { "file": "llvm/test/Transforms/ConstraintElimination/pr105785.ll", "commands": [ "opt -passes=constraint-elimination -S %s" ], "tests": [ { "test_name": "pr105785", "test_body": "define void @pr105785(ptr %p) {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %for.cond1, %entry\n %for.ind = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\n %cmp = icmp eq i32 %for.ind, 0\n br i1 %cmp, label %for.cond1, label %for.end6\n\nfor.cond1: ; preds = %for.body3, %for.cond\n %for.ind2 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\n %cmp2 = icmp ult i32 %for.ind2, 3\n br i1 %cmp2, label %for.body3, label %for.cond\n\nfor.body3: ; preds = %for.cond1\n %scmp = call i32 @llvm.scmp.i32.i32(i32 %for.ind, i32 1)\n store i32 %scmp, ptr %p, align 4\n %inc = add nuw nsw i32 %for.ind2, 1\n br label %for.cond1\n\nfor.end6: ; preds = %for.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.scmp.i32.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": "-src-unroll=4 -tgt-unroll=4", "lli_expected_out": null } ] } ]
{ "title": "[ConstraintElim] Miscompilation with cmp intrinsic", "body": "Reproducer: https://alive2.llvm.org/ce/z/Tvz2NA\r\n```\r\n; bin/opt -passes=constraint-elimination test.ll -S\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.cond, %for.body3\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n %sub.i = tail call range(i32 -1, 2) i32 @llvm.scmp.i32.i32(i32 1, i32 %storemerge)\r\n store i32 %sub.i, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6:\r\n ret void\r\n}\r\n```\r\n\r\n```\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.body3, %for.cond\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n store i32 0, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6: ; preds = %for.cond\r\n ret void\r\n}\r\n```\r\n\r\nThe result of scmp should be 1 instead of 0.\r\n\r\nReduced C reproducer:\r\n```\r\n#include <stdio.h>\r\n#include <stdint.h>\r\n\r\nint builtin_scmp(int d, int e) { return (d > e) - (d < e); }\r\nint32_t f = 0;\r\nint64_t g = 0;\r\nvoid h() {\r\n for (f = 0; f <= 0; f++) {\r\n int i;\r\n for (i = 0; i < 3; i++)\r\n g = builtin_scmp(1, f);\r\n }\r\n}\r\nint main() {\r\n h();\r\n printf(\"%d\\n\", (int)g);\r\n return 0;\r\n}\r\n```\r\n\r\nI will post a fix later.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [] }
true
null
117518
https://github.com/llvm/llvm-project/issues/117518
crash
3de21477c49172081e502b47d608e729915f0914
2024-11-25T05:31:23
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "f953b5eb72df77fc301aac210eab31c6270ff771", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 10875, 10883 ], [ 14372, 14378 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "finalize" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit f953b5eb72df77fc301aac210eab31c6270ff771 Author: Alexey Bataev <[email protected]> Date: Mon Nov 25 08:29:22 2024 -0800 [SLP]Relax assertion about subvectors mask size SubVectorsMask might be less than CommonMask, if the vectors with larger number of elements are permuted or reused elements are used. Need to consider this when estimation/building the vector to avoid compiler crash Fixes #117518 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 73218f377a06..34b80c1e3608 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -10875,9 +10875,10 @@ public: CommonMask[Idx] = Idx; // Add subvectors permutation cost. if (!SubVectorsMask.empty()) { - assert(SubVectorsMask.size() == CommonMask.size() && + assert(SubVectorsMask.size() <= CommonMask.size() && "Expected same size of masks for subvectors and common mask."); - SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end()); + SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem); + copy(SubVectorsMask, SVMask.begin()); for (auto [I1, I2] : zip(SVMask, CommonMask)) { if (I2 != PoisonMaskElem) { assert(I1 == PoisonMaskElem && "Expected unused subvectors mask"); @@ -14372,7 +14373,8 @@ public: if (SubVectorsMask.empty()) { Vec = CreateSubVectors(Vec, CommonMask); } else { - SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end()); + SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem); + copy(SubVectorsMask, SVMask.begin()); for (auto [I1, I2] : zip(SVMask, CommonMask)) { if (I2 != PoisonMaskElem) { assert(I1 == PoisonMaskElem && "Expected unused subvectors mask");
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-of-2-subvectors-insert.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-300 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\n %xor108.i.i.i = xor i64 0, 1\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\n %cond.i1002.1.i.i.i = lshr i64 0, 0\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\n %cond.i1002.3.i.i.i = lshr i64 0, 0\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' failed.", "body": "Reproducer: https://godbolt.org/z/chKcKacPK\r\n```\r\n; bin/opt -passes=slp-vectorizer test.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 void @test() {\r\n %xor108.i.i.i = xor i64 0, 1\r\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\r\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\r\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\r\n %cond.i1002.1.i.i.i = lshr i64 0, 0\r\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\r\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\r\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\r\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\r\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\r\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\r\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\r\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\r\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\r\n %cond.i1002.3.i.i.i = lshr i64 0, 0\r\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\r\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\r\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\r\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\r\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\r\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\r\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\r\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\r\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\r\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\r\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\r\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\r\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\r\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\r\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\r\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\r\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\r\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\r\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\r\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\r\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\r\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\r\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\r\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\r\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\r\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\r\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\r\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\r\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\r\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\r\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\r\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\r\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\r\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\r\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\r\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\r\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\r\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\r\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\r\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\r\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\r\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\r\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\r\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\r\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\r\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\r\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\r\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\r\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\r\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\r\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\r\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\r\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\r\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\r\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\r\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\r\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\r\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10880: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' 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 \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007ac42d642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ac42d6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ac42d642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ac42d6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ac42d62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ac42d639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e9132 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e9132)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 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+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x000000000426d57c llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426d57c)\r\n#13 0x000000000427168f bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427168f)\r\n#14 0x0000000004271fdb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\r\n#15 0x0000000004275785 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4275785)\r\n#16 0x000000000427bf86 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 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce 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+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e 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+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe 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+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a 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+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x00007ac42d629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007ac42d629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
100298
https://github.com/llvm/llvm-project/issues/100298
miscompilation
75642a00e15b722bdfb90726be31f1c8adaeb0c5
2024-07-24T04:19:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "59eae919c938f890e9b9b4be8a3fa3cb1b11ed89", "components": [ "ValueTracking" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/include/llvm/IR/Instruction.h": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 1435, 1441 ], [ 1468, 1474 ], [ 1546, 1552 ], [ 2329, 2335 ], [ 2943, 2949 ], [ 3509, 3515 ], [ 4001, 4007 ], [ 5909, 5918 ] ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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": [ [ 130, 135 ] ], "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ "ComputeNumSignBitsImpl", "computeKnownBitsFromOperator", "computeKnownFPClass", "isKnownNonZeroFromOperator", "isKnownToBeAPowerOfTwo", "isNonEqualPHIs" ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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": [ "getWithCondContext" ], "llvm/lib/Transforms/IPO/DeadArgumentElimination.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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a87fbeb3a77a53ded341277c5b326f7696d47594 Author: Yingwei Zheng <[email protected]> Date: Wed Jul 24 20:06:36 2024 +0800 [ValueTracking] Don't use CondContext in dataflow analysis of phi nodes (#100316) See the following case: ``` define i16 @pr100298() { entry: br label %for.inc for.inc: %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ] %add = add nsw i32 %indvar, 9 %mask = and i32 %add, 65535 %cmp1 = icmp ugt i32 %mask, 5 br i1 %cmp1, label %for.inc, label %for.end for.end: %conv = trunc i32 %add to i16 %cmp2 = icmp ugt i32 %mask, 3 %shl = shl nuw i16 %conv, 14 %res = select i1 %cmp2, i16 %conv, i16 %shl ret i16 %res } ``` When computing knownbits of `%shl` with `%cmp2=false`, we cannot use this condition in the analysis of `%mask (%for.inc -> %for.inc)`. Fixes https://github.com/llvm/llvm-project/issues/100298. (cherry picked from commit 59eae919c938f890e9b9b4be8a3fa3cb1b11ed89) diff --git a/llvm/include/llvm/Analysis/SimplifyQuery.h b/llvm/include/llvm/Analysis/SimplifyQuery.h index a560744f0122..e8f43c8c2e91 100644 --- a/llvm/include/llvm/Analysis/SimplifyQuery.h +++ b/llvm/include/llvm/Analysis/SimplifyQuery.h @@ -130,6 +130,12 @@ struct SimplifyQuery { Copy.CC = &CC; return Copy; } + + SimplifyQuery getWithoutCondContext() const { + SimplifyQuery Copy(*this); + Copy.CC = nullptr; + return Copy; + } }; } // end namespace llvm diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 40fe1ffe13f1..4b77c0046cc7 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1435,7 +1435,7 @@ static void computeKnownBitsFromOperator(const Operator *I, // inferred hold at original context instruction. TODO: It may be // correct to use the original context. IF warranted, explore and // add sufficient tests to cover. - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); RecQ.CxtI = P; computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ); switch (Opcode) { @@ -1468,7 +1468,7 @@ static void computeKnownBitsFromOperator(const Operator *I, // phi. This is important because that is where the value is actually // "evaluated" even though it is used later somewhere else. (see also // D69571). - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); unsigned OpNum = P->getOperand(0) == R ? 0 : 1; Instruction *RInst = P->getIncomingBlock(OpNum)->getTerminator(); @@ -1546,7 +1546,7 @@ static void computeKnownBitsFromOperator(const Operator *I, // phi. This is important because that is where the value is actually // "evaluated" even though it is used later somewhere else. (see also // D69571). - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); RecQ.CxtI = P->getIncomingBlock(u)->getTerminator(); Known2 = KnownBits(BitWidth); @@ -2329,7 +2329,7 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth, // it is an induction variable where in each step its value is a power of // two. auto *PN = cast<PHINode>(I); - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); // Check if it is an induction variable and always power of two. if (isPowerOfTwoRecurrence(PN, OrZero, Depth, RecQ)) @@ -2943,7 +2943,7 @@ static bool isKnownNonZeroFromOperator(const Operator *I, return true; // Check if all incoming values are non-zero using recursion. - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); unsigned NewDepth = std::max(Depth, MaxAnalysisRecursionDepth - 1); return llvm::all_of(PN->operands(), [&](const Use &U) { if (U.get() == PN) @@ -3509,7 +3509,7 @@ static bool isNonEqualPHIs(const PHINode *PN1, const PHINode *PN2, if (UsedFullRecursion) return false; - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); RecQ.CxtI = IncomBB->getTerminator(); if (!isKnownNonEqual(IV1, IV2, DemandedElts, Depth + 1, RecQ)) return false; @@ -4001,7 +4001,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V, // Take the minimum of all incoming values. This can't infinitely loop // because of our depth threshold. - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); Tmp = TyBits; for (unsigned i = 0, e = NumIncomingValues; i != e; ++i) { if (Tmp == 1) return Tmp; @@ -5909,10 +5909,10 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, // Recurse, but cap the recursion to two levels, because we don't want // to waste time spinning around in loops. We need at least depth 2 to // detect known sign bits. - computeKnownFPClass( - IncValue, DemandedElts, InterestedClasses, KnownSrc, - PhiRecursionLimit, - Q.getWithInstruction(P->getIncomingBlock(U)->getTerminator())); + computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc, + PhiRecursionLimit, + Q.getWithoutCondContext().getWithInstruction( + P->getIncomingBlock(U)->getTerminator())); if (First) { Known = KnownSrc;
[ { "file": "llvm/test/Transforms/InstCombine/pr100298.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr100298", "test_body": "define i16 @pr100298() {\nentry:\n br label %for.inc\n\nfor.inc: ; preds = %for.inc, %entry\n %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]\n %add = add nsw i32 %indvar, 9\n %mask = and i32 %add, 65535\n %cmp1 = icmp ugt i32 %mask, 5\n br i1 %cmp1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.inc\n %conv = trunc i32 %add to i16\n %cmp2 = icmp ugt i32 %mask, 3\n %shl = shl nuw i16 %conv, 14\n %res = select i1 %cmp2, i16 %conv, i16 %shl\n ret i16 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Miscompilation at O3", "body": "```\r\n#include \"csmith.h\"\r\nuint32_t a;\r\nint16_t c;\r\nvoid d() {\r\n for (a = -15; a >= 6; a = safe_add_func_uint16_t_u_u(a, 9))\r\n ;\r\n c = safe_lshift_func_int16_t_s_u(safe_lshift_func_uint16_t_u_s(a,14), 0);\r\n}\r\nint main() {\r\n d();\r\n printf(\"%d\\n\", c);\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ gcc -O0 test.c -fsanitize=undefined -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n-16384\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ bin/clang -O3 test.c -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n0\r\n```\r\n\r\nllvm version: 2d6ff0c533aa1b0fe6d91764846f636c4a4e911c", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced testcase: https://alive2.llvm.org/ce/z/9fExrA\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i16 @src() {\r\nentry:\r\n br label %for.inc\r\n\r\nfor.inc:\r\n %storemerge6 = phi i32 [ -15, %entry ], [ %conv1, %for.inc ]\r\n %add.i = add nsw i32 %storemerge6, 9\r\n %conv1 = and i32 %add.i, 65535\r\n %cmp = icmp ugt i32 %conv1, 5\r\n br i1 %cmp, label %for.inc, label %for.end\r\n\r\nfor.end:\r\n %conv2 = trunc nuw nsw i32 %conv1 to i16\r\n %cmp3.i = icmp ugt i32 %conv1, 3\r\n %0 = shl nuw i16 %conv2, 14\r\n %cond.in.i = select i1 %cmp3.i, i16 %conv2, i16 %0\r\n ret i16 %cond.in.i\r\n}\r\n```" } ] }
true
null
101337
https://github.com/llvm/llvm-project/issues/101337
crash
1b936e4812ab395328203f65cacd4ffe02bb318e
2024-07-31T14:11:24
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "cd08fadd03904806fa26a1f117879ddae34fbf67", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 7080, 7086 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationPlanner::cost" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit cd08fadd03904806fa26a1f117879ddae34fbf67 Author: Florian Hahn <[email protected]> Date: Mon Aug 12 14:45:43 2024 +0100 [LV] Include chains feeding inductions in cost precomputation. Include chain of ops feeding inductions in cost precomputation for inductions, not just the induction increment. In VPlan, those instructions will be cleaned up, as both phi and increment are generated by VPWidenIntOrFpInductionRecipe independently. Fixes https://github.com/llvm/llvm-project/issues/101337. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 542d74ef0e1e..41e4b0fcd9b0 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7080,7 +7080,16 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, for (const auto &[IV, IndDesc] : Legal->getInductionVars()) { Instruction *IVInc = cast<Instruction>( IV->getIncomingValueForBlock(OrigLoop->getLoopLatch())); - SmallVector<Instruction *> IVInsts = {IV, IVInc}; + SmallVector<Instruction *> IVInsts = {IVInc}; + for (unsigned I = 0; I != IVInsts.size(); I++) { + for (Value *Op : IVInsts[I]->operands()) { + auto *OpI = dyn_cast<Instruction>(Op); + if (Op == IV || !OpI || !OrigLoop->contains(OpI) || !Op->hasOneUse()) + continue; + IVInsts.push_back(OpI); + } + } + IVInsts.push_back(IV); for (User *U : IV->users()) { auto *CI = cast<Instruction>(U); if (!CostCtx.CM.isOptimizableIVTruncate(CI, VF))
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/induction-costs.ll", "commands": [ "opt -p loop-vectorize -mtriple=x86_64-apple-macosx -S %s" ], "tests": [ { "test_name": "iv_and_step_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i16 @iv_and_step_trunc() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %rec = phi i16 [ 0, %entry ], [ %rec.next, %loop ]\n %iv.next = add i64 %iv, 1\n %0 = trunc i64 %iv to i16\n %1 = trunc i64 %iv.next to i16\n %rec.next = mul i16 %0, %1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %rec\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "wombat2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat2(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc.1, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc.0 = trunc i64 %mul3 to i60\n %trunc.1 = trunc i60 %trunc.0 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "with_dead_use", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @with_dead_use(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n %dead.and = and i32 %trunc, 123\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_scalar_predicated_cost", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @test_scalar_predicated_cost(i64 %x, i64 %y, ptr %A) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %cmp9.not = icmp ule i64 %iv, %y\n br i1 %cmp9.not, label %loop.latch, label %if.then\n\nif.then: ; preds = %loop.header\n %or = or i64 %x, %iv\n %gep = getelementptr i32, ptr %A, i64 %iv\n %t = trunc i64 %or to i32\n store i32 %t, ptr %gep, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %if.then, %loop.header\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 100\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "truncated_ivs_with_wide_and_scalar_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @truncated_ivs_with_wide_and_scalar_uses(i1 %c, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %gep = getelementptr i16, ptr %dst, i32 %iv.32\n %sel = select i1 %c, i16 %iv.16, i16 10\n store i16 %sel, ptr %gep, align 2\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "multiple_truncated_ivs_with_wide_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_truncated_ivs_with_wide_uses(i1 %c, ptr %A, ptr %B) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %sel = select i1 %c, i16 %iv.16, i16 10\n %gep.A = getelementptr i16, ptr %A, i64 %iv\n store i16 %sel, ptr %gep.A, align 2\n %gep.B = getelementptr i32, ptr %B, i64 %iv\n store i32 %iv.32, ptr %gep.B, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "wide_iv_trunc_reuse", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc_reuse(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n store i32 %iv.2, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 0\n %iv.trunc = trunc i64 %iv to i32\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "iv_used_widened_and_truncated", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @iv_used_widened_and_truncated(ptr %dst, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr { i32, [8 x i32] }, ptr %dst, i64 %iv\n %t = trunc i64 %iv to i32\n store i32 %t, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %c = icmp eq i64 %iv, %N\n br i1 %c, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "wombat", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "wide_iv_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc(ptr %dst, i64 %N) {\nentry:\n %cmp = icmp ult i64 %N, 8\n br i1 %cmp, label %loop, label %exit\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %iv.trunc, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop, %entry\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "multiple_pointer_ivs_with_scalar_uses_only", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_pointer_ivs_with_scalar_uses_only(ptr %A, ptr %B) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi i32 [ 100, %entry ], [ %dec, %loop ]\n %iv.2 = phi i32 [ 2048, %entry ], [ %add38, %loop ]\n %ptr.iv.1 = phi ptr [ %A, %entry ], [ %outptr.0, %loop ]\n %ptr.iv.2 = phi ptr [ %B, %entry ], [ %incdec.ptr36, %loop ]\n %ptr.iv.3 = phi ptr [ %B, %entry ], [ %incdec.ptr33, %loop ]\n %incdec.ptr33 = getelementptr i8, ptr %ptr.iv.3, i64 1\n %0 = load i8, ptr %ptr.iv.3, align 1\n %conv34 = zext i8 %0 to i32\n %incdec.ptr36 = getelementptr i8, ptr %ptr.iv.2, i64 1\n %1 = load i8, ptr %ptr.iv.2, align 1\n %conv37 = zext i8 %1 to i32\n %add38 = add i32 %conv34, %conv37\n %shr42 = lshr i32 %iv.2, 1\n %conv43 = trunc i32 %shr42 to i8\n store i8 %conv43, ptr %ptr.iv.1, align 1\n %dec = add i32 %iv.1, 1\n %outptr.0 = getelementptr i8, ptr %ptr.iv.1, i64 2\n %cmp30.not = icmp eq i32 %dec, 0\n br i1 %cmp30.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "To reproduce run opt with \r\n```\r\n-passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\r\n```\r\nwith the following test:\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat(i32 %arg) #0 gc \"statepoint-example\" {\r\nbb:\r\n %mul = mul i32 %arg, 3\r\n %zext = zext i32 %arg to i64\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ %add, %bb1 ], [ 4, %bb ]\r\n %phi2 = phi i32 [ %trunc, %bb1 ], [ %mul, %bb ]\r\n %getelementptr = getelementptr i32, ptr addrspace(1) null, i64 %phi\r\n %and = and i32 %phi2, 0\r\n store i32 0, ptr addrspace(1) %getelementptr, align 4\r\n %mul3 = mul i64 %phi, %zext\r\n %add = add i64 %phi, 1\r\n %icmp = icmp ugt i64 %phi, 65\r\n %trunc = trunc i64 %mul3 to i32\r\n br i1 %icmp, label %bb4, label %bb1\r\n\r\nbb4: ; preds = %bb1\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/nPsP7h51n\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f <source>\r\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\r\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\r\n #0 0x0000000004f053c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f053c8)\r\n #1 0x0000000004f02b3c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007458cc042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007458cc0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007458cc042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007458cc0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007458cc02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007458cc039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003f83f37 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f83f37)\r\n #9 0x0000000003f86659 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86659)\r\n#10 0x0000000003f86cd2 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86cd2)\r\n#11 0x0000000002e596ce llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e596ce)\r\n#12 0x0000000004d02758 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d02758)\r\n#13 0x0000000000de089e 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+0xde089e)\r\n#14 0x0000000004d0114e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d0114e)\r\n#15 0x0000000000de0eee 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+0xde0eee)\r\n#16 0x0000000004cff2b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cff2b0)\r\n#17 0x00000000008e3752 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+0x8e3752)\r\n#18 0x00000000008d667c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d667c)\r\n#19 0x00007458cc029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x00007458cc029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008cdade _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cdade)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "patrick-rivos", "body": "Potentially related: https://github.com/llvm/llvm-project/issues/100591" } ] }
true
null
107569
https://github.com/llvm/llvm-project/issues/107569
crash
b0428870dae980af84e50dfa3ee6ed2165998678
2024-09-06T11:56:19
[ "llvm/test/Transforms/DeadArgElim" ]
{ "fix_commit": "5978bb2936d9a71d8e6891c640a36be760b569d3", "components": [ "DeadArgumentElimination" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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": [ [ 106, 118 ], [ 131, 142 ] ], "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": [ [ 87, 97 ], [ 280, 286 ], [ 496, 502 ], [ 504, 510 ], [ 522, 550 ], [ 555, 562 ], [ 564, 577 ], [ 610, 620 ], [ 628, 646 ], [ 680, 693 ], [ 696, 701 ], [ 710, 716 ], [ 734, 741 ], [ 807, 813 ], [ 1109, 1134 ], [ 1149, 1156 ] ], "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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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": [ "DeadArgumentEliminationPass::isLive", "DeadArgumentEliminationPass::markLive", "DeadArgumentEliminationPass::markValue", "DeadArgumentEliminationPass::propagateVirtMustcallLiveness", "DeadArgumentEliminationPass::removeDeadArgumentsFromCallers", "DeadArgumentEliminationPass::removeDeadStuffFromFunction", "DeadArgumentEliminationPass::run", "DeadArgumentEliminationPass::surveyFunction", "isMustTailCalleeAnalyzable" ], "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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 5978bb2936d9a71d8e6891c640a36be760b569d3 Author: u4f3 <[email protected]> Date: Thu Apr 10 22:08:09 2025 +0800 [DeadArgElim] fix verifier failure when changing musttail's function signature (#127366) This commit is for #107569 and #126817. Stop changing musttail's caller and callee's function signature when calling convention is not swifttailcc nor tailcc. Verifier makes sure musttail's caller and callee shares exactly the same signature, see commit 9ff2eb1 and #54964. Otherwise just make sure the return type is the same and then process musttail like usual calls. close #107569, #126817 diff --git a/llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h b/llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h index 63e1ad043d49..efa9c4bdc496 100644 --- a/llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h +++ b/llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h @@ -106,13 +106,16 @@ public: UseMap Uses; using LiveSet = std::set<RetOrArg>; - using LiveFuncSet = std::set<const Function *>; + using FuncSet = std::set<const Function *>; /// This set contains all values that have been determined to be live. LiveSet LiveValues; - /// This set contains all values that are cannot be changed in any way. - LiveFuncSet LiveFunctions; + /// This set contains all functions that cannot be changed in any way. + FuncSet FrozenFunctions; + + /// This set contains all functions that cannot change return type; + FuncSet FrozenRetTyFunctions; using UseVector = SmallVector<RetOrArg, 5>; @@ -131,12 +134,13 @@ private: void markValue(const RetOrArg &RA, Liveness L, const UseVector &MaybeLiveUses); void markLive(const RetOrArg &RA); - void markLive(const Function &F); + void markFrozen(const Function &F); + void markRetTyFrozen(const Function &F); + bool markFnOrRetTyFrozenOnMusttail(const Function &F); void propagateLiveness(const RetOrArg &RA); bool removeDeadStuffFromFunction(Function *F); bool deleteDeadVarargs(Function &F); bool removeDeadArgumentsFromCallers(Function &F); - void propagateVirtMustcallLiveness(const Module &M); }; } // end namespace llvm diff --git a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp index ed93b4491c50..2e2687a5ff6e 100644 --- a/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -87,11 +87,6 @@ public: virtual bool shouldHackArguments() const { return false; } }; -bool isMustTailCalleeAnalyzable(const CallBase &CB) { - assert(CB.isMustTailCall()); - return CB.getCalledFunction() && !CB.getCalledFunction()->isDeclaration(); -} - } // end anonymous namespace char DAE::ID = 0; @@ -280,7 +275,7 @@ bool DeadArgumentEliminationPass::removeDeadArgumentsFromCallers(Function &F) { // they are fully alive (e.g., called indirectly) and except for the fragile // (variadic) ones. In these cases, we may still be able to improve their // statically known call sites. - if ((F.hasLocalLinkage() && !LiveFunctions.count(&F)) && + if ((F.hasLocalLinkage() && !FrozenFunctions.count(&F)) && !F.getFunctionType()->isVarArg()) return false; @@ -496,7 +491,7 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { // particular register and memory layout. if (F.getAttributes().hasAttrSomewhere(Attribute::InAlloca) || F.getAttributes().hasAttrSomewhere(Attribute::Preallocated)) { - markLive(F); + markFrozen(F); return; } @@ -504,7 +499,7 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { // otherwise rely on the frame layout in a way that this analysis will not // see. if (F.hasFnAttribute(Attribute::Naked)) { - markLive(F); + markFrozen(F); return; } @@ -522,29 +517,17 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { // MaybeLive. Initialized to a list of RetCount empty lists. RetUses MaybeLiveRetUses(RetCount); - bool HasMustTailCalls = false; for (const BasicBlock &BB : F) { - // If we have any returns of `musttail` results - the signature can't - // change - if (const auto *TC = BB.getTerminatingMustTailCall()) { - HasMustTailCalls = true; - // In addition, if the called function is not locally defined (or unknown, - // if this is an indirect call), we can't change the callsite and thus - // can't change this function's signature either. - if (!isMustTailCalleeAnalyzable(*TC)) { - markLive(F); + if (BB.getTerminatingMustTailCall()) { + LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName() + << " has musttail calls\n"); + if (markFnOrRetTyFrozenOnMusttail(F)) return; - } } } - if (HasMustTailCalls) { - LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName() - << " has musttail calls\n"); - } - if (!F.hasLocalLinkage() && (!ShouldHackArguments || F.isIntrinsic())) { - markLive(F); + markFrozen(F); return; } @@ -555,8 +538,6 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { // of them turn out to be live. unsigned NumLiveRetVals = 0; - bool HasMustTailCallers = false; - // Loop all uses of the function. for (const Use &U : F.uses()) { // If the function is PASSED IN as an argument, its address has been @@ -564,14 +545,16 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { const auto *CB = dyn_cast<CallBase>(U.getUser()); if (!CB || !CB->isCallee(&U) || CB->getFunctionType() != F.getFunctionType()) { - markLive(F); + markFrozen(F); return; } - // The number of arguments for `musttail` call must match the number of - // arguments of the caller - if (CB->isMustTailCall()) - HasMustTailCallers = true; + if (CB->isMustTailCall()) { + LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName() + << " has musttail callers\n"); + if (markFnOrRetTyFrozenOnMusttail(F)) + return; + } // If we end up here, we are looking at a direct call to our function. @@ -610,11 +593,6 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { } } - if (HasMustTailCallers) { - LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - " << F.getName() - << " has musttail callers\n"); - } - // Now we've inspected all callers, record the liveness of our return values. for (unsigned Ri = 0; Ri != RetCount; ++Ri) markValue(createRet(&F, Ri), RetValLiveness[Ri], MaybeLiveRetUses[Ri]); @@ -628,19 +606,12 @@ void DeadArgumentEliminationPass::surveyFunction(const Function &F) { for (Function::const_arg_iterator AI = F.arg_begin(), E = F.arg_end(); AI != E; ++AI, ++ArgI) { Liveness Result; - if (F.getFunctionType()->isVarArg() || HasMustTailCallers || - HasMustTailCalls) { + if (F.getFunctionType()->isVarArg()) { // Variadic functions will already have a va_arg function expanded inside // them, making them potentially very sensitive to ABI changes resulting // from removing arguments entirely, so don't. For example AArch64 handles // register and stack HFAs very differently, and this is reflected in the // IR which has already been generated. - // - // `musttail` calls to this function restrict argument removal attempts. - // The signature of the caller must match the signature of the function. - // - // `musttail` calls in this function prevents us from changing its - // signature Result = Live; } else { // See what the effect of this use is (recording any uses that cause @@ -680,14 +651,30 @@ void DeadArgumentEliminationPass::markValue(const RetOrArg &RA, Liveness L, } } +/// Return true if we freeze the whole function. +/// If the calling convention is not swifttailcc or tailcc, the caller and +/// callee of musttail must have exactly the same signature. Otherwise we +/// only needs to guarantee they have the same return type. +bool DeadArgumentEliminationPass::markFnOrRetTyFrozenOnMusttail( + const Function &F) { + if (F.getCallingConv() != CallingConv::SwiftTail || + F.getCallingConv() != CallingConv::Tail) { + markFrozen(F); + return true; + } else { + markRetTyFrozen(F); + return false; + } +} + /// Mark the given Function as alive, meaning that it cannot be changed in any /// way. Additionally, mark any values that are used as this function's /// parameters or by its return values (according to Uses) live as well. -void DeadArgumentEliminationPass::markLive(const Function &F) { - LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - Intrinsically live fn: " +void DeadArgumentEliminationPass::markFrozen(const Function &F) { + LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - frozen fn: " << F.getName() << "\n"); - // Mark the function as live. - LiveFunctions.insert(&F); + // Mark the function as frozen. + FrozenFunctions.insert(&F); // Mark all arguments as live. for (unsigned ArgI = 0, E = F.arg_size(); ArgI != E; ++ArgI) propagateLiveness(createArg(&F, ArgI)); @@ -696,6 +683,12 @@ void DeadArgumentEliminationPass::markLive(const Function &F) { propagateLiveness(createRet(&F, Ri)); } +void DeadArgumentEliminationPass::markRetTyFrozen(const Function &F) { + LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - frozen return type fn: " + << F.getName() << "\n"); + FrozenRetTyFunctions.insert(&F); +} + /// Mark the given return value or argument as live. Additionally, mark any /// values that are used by this value (according to Uses) live as well. void DeadArgumentEliminationPass::markLive(const RetOrArg &RA) { @@ -710,7 +703,7 @@ void DeadArgumentEliminationPass::markLive(const RetOrArg &RA) { } bool DeadArgumentEliminationPass::isLive(const RetOrArg &RA) { - return LiveFunctions.count(RA.F) || LiveValues.count(RA); + return FrozenFunctions.count(RA.F) || LiveValues.count(RA); } /// Given that RA is a live value, propagate it's liveness to any other values @@ -734,8 +727,8 @@ void DeadArgumentEliminationPass::propagateLiveness(const RetOrArg &RA) { /// Transform the function and all the callees of the function to not have these /// arguments and return values. bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) { - // Don't modify fully live functions - if (LiveFunctions.count(F)) + // Don't modify frozen functions + if (FrozenFunctions.count(F)) return false; // Start by computing a new prototype for the function, which is the same as @@ -807,7 +800,8 @@ bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) { // performance win, so the second option can just be used always for now. // // This should be revisited if 'returned' is ever applied more liberally. - if (RetTy->isVoidTy() || HasLiveReturnedArg) { + if (RetTy->isVoidTy() || HasLiveReturnedArg || + FrozenRetTyFunctions.count(F)) { NRetTy = RetTy; } else { // Look at each of the original return values individually. @@ -1109,26 +1103,6 @@ bool DeadArgumentEliminationPass::removeDeadStuffFromFunction(Function *F) { return true; } -void DeadArgumentEliminationPass::propagateVirtMustcallLiveness( - const Module &M) { - // If a function was marked "live", and it has musttail callers, they in turn - // can't change either. - LiveFuncSet NewLiveFuncs(LiveFunctions); - while (!NewLiveFuncs.empty()) { - LiveFuncSet Temp; - for (const auto *F : NewLiveFuncs) - for (const auto *U : F->users()) - if (const auto *CB = dyn_cast<CallBase>(U)) - if (CB->isMustTailCall()) - if (!LiveFunctions.count(CB->getParent()->getParent())) - Temp.insert(CB->getParent()->getParent()); - NewLiveFuncs.clear(); - NewLiveFuncs.insert(Temp.begin(), Temp.end()); - for (const auto *F : Temp) - markLive(*F); - } -} - PreservedAnalyses DeadArgumentEliminationPass::run(Module &M, ModuleAnalysisManager &) { bool Changed = false; @@ -1149,8 +1123,6 @@ PreservedAnalyses DeadArgumentEliminationPass::run(Module &M, for (auto &F : M) surveyFunction(F); - propagateVirtMustcallLiveness(M); - // Now, remove all dead arguments and return values from each function in // turn. We use make_early_inc_range here because functions will probably get // removed (i.e. replaced by new ones).
[ { "file": "llvm/test/Transforms/DeadArgElim/musttail-caller.ll", "commands": [ "opt -passes=deadargelim -S < %s" ], "tests": [ { "test_name": "test", "test_body": "define hidden void @test(i32 %a, i32 %b) {\n musttail call void @foo(i32 %a, i32 0)\n ret void\n}\n\ndeclare hidden void @foo(i32, i32)\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo", "test_body": "define hidden void @foo(i32 %a, i32 %b) {\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/DeadArgElim/musttail-verifier.ll", "commands": [ "opt -passes=deadargelim -S < %s" ], "tests": [ { "test_name": "<module>", "test_body": "; Testcases comes from PR126817 and PR107569\n; See PR54964 and langref for more information about how llvm deal with musttail currently\n\ndefine i64 @A() {\n;\nentry:\n %v2660 = musttail call i64 @B()\n ret i64 %v2660\n}\n\ndefine internal i64 @B() {\n;\nentry:\n ret i64 0\n}\n\ndefine internal i64 @C() {\n;\nentry:\n %v30543 = musttail call i64 @B()\n ret i64 %v30543\n}\n\n%struct.S = type { double }\n\ndefine internal %struct.S @F38() {\n;\n ret %struct.S { double 0.0 }\n}\n\ndefine internal %struct.S @F36() {\n;\n %1 = alloca %struct.S, align 8\n %3 = musttail call %struct.S @F38()\n ret %struct.S %3\n}\n\ndefine double @foo() {\n;\n %3 = call %struct.S @F36()\n %5 = extractvalue %struct.S %3, 0\n ret double %5\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "DeadArgumentElimination creates invalid code with musttail calls returning structs", "body": "The DeadArgumentElimination pass creates code which fails the IR verifier when run on this input:\r\n\r\n```test.ll\r\n%struct.S = type { i32 }\r\n\r\ndefine internal %struct.S @F38() {\r\n ret %struct.S { i32 0 }\r\n}\r\n\r\ndefine %struct.S @F36() {\r\n %3 = musttail call %struct.S @F38()\r\n ret %struct.S %3\r\n}\r\n```\r\n\r\n```\r\n$ /work/llvm/build/bin/opt test.ll -passes=deadargelim -S\r\ncannot guarantee tail call due to mismatched return types\r\n %1 = musttail call i32 @F38()\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /work/llvm/build/bin/opt test.ll -passes=deadargelim -S\r\n1. Running pass \"verify\" on module \"test.ll\"\r\n #0 0x000055c16a99ca37 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/llvm/build/bin/opt+0x4133a37)\r\n #1 0x000055c16a99a57e llvm::sys::RunSignalHandlers() (/work/llvm/build/bin/opt+0x413157e)\r\n #2 0x000055c16a99d27a SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f38e3a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007f38e3a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007f38e3a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007f38e3a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007f38e3a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007f38e3a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000055c16a9857a3 llvm::report_fatal_error(llvm::Twine const&, bool) (/work/llvm/build/bin/opt+0x411c7a3)\r\n#10 0x000055c16a9855f6 (/work/llvm/build/bin/opt+0x411c5f6)\r\n#11 0x000055c16afe2d4a (/work/llvm/build/bin/opt+0x4779d4a)\r\n#12 0x000055c16bd1b53d llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) NewPMDriver.cpp:0:0\r\n#13 0x000055c16abad88a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/work/llvm/build/bin/opt+0x434488a)\r\n#14 0x000055c16bd146eb 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) (/work/llvm/build/bin/opt+0x54ab6eb)\r\n#15 0x000055c16a964609 optMain (/work/llvm/build/bin/opt+0x40fb609)\r\n#16 0x00007f38e3a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#17 0x00007f38e3a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#18 0x00007f38e3a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#19 0x000055c16a95e0a5 _start (/work/llvm/build/bin/opt+0x40f50a5)\r\nfish: Job 1, '/work/llvm/build/bin/opt test.l…' terminated by signal SIGABRT (Abort)\r\n```\r\n\r\nFound using a fuzzer while testing #102896.", "author": "ostannard", "labels": [ "ipo", "crash-on-valid" ], "comments": [ { "author": "ostannard", "body": "Related case with a different assertion message:\r\n```test2.ll\r\n%struct.S = type { double }\r\n\r\ndefine internal %struct.S @F38() {\r\n ret %struct.S { double 0.0 }\r\n}\r\n\r\ndefine internal %struct.S @F36() {\r\n %1 = alloca %struct.S, align 8\r\n %3 = musttail call %struct.S @F38()\r\n ret %struct.S %3\r\n}\r\n\r\ndefine double @foo() {\r\n %3 = call %struct.S @F36()\r\n %5 = extractvalue %struct.S %3, 0\r\n ret double %5\r\n}\r\n```\r\n\r\n```\r\n$ /work/llvm/build/bin/opt test2.ll -passes=deadargelim -S -print-after-all\r\n; *** IR Dump After DeadArgumentEliminationPass on [module] ***\r\n; ModuleID = 'test2.ll'\r\nsource_filename = \"test2.ll\"\r\n\r\n%struct.S = type { double }\r\n\r\ndefine internal double @F38() {\r\n %oldret = extractvalue %struct.S zeroinitializer, 0\r\n ret double %oldret\r\n}\r\n\r\ndefine internal double @F36() {\r\n %1 = alloca %struct.S, align 8\r\n %2 = musttail call double @F38()\r\n %oldret = insertvalue %struct.S poison, double %2, 0\r\n %oldret1 = extractvalue %struct.S %oldret, 0\r\n ret double %oldret1\r\n}\r\n\r\ndefine double @foo() {\r\n %1 = call double @F36()\r\n %oldret = insertvalue %struct.S poison, double %1, 0\r\n %2 = extractvalue %struct.S %oldret, 0\r\n ret double %2\r\n}\r\nmusttail call must precede a ret with an optional bitcast\r\n %2 = musttail call double @F38()\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /work/llvm/build/bin/opt test2.ll -passes=deadargelim -S -print-after-all\r\n1. Running pass \"verify\" on module \"test2.ll\"\r\n #0 0x000055c5f980ca37 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/llvm/build/bin/opt+0x4133a37)\r\n #1 0x000055c5f980a57e llvm::sys::RunSignalHandlers() (/work/llvm/build/bin/opt+0x413157e)\r\n #2 0x000055c5f980d27a SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007faf4da42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007faf4da969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007faf4da969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007faf4da969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007faf4da42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007faf4da287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000055c5f97f57a3 llvm::report_fatal_error(llvm::Twine const&, bool) (/work/llvm/build/bin/opt+0x411c7a3)\r\n#10 0x000055c5f97f55f6 (/work/llvm/build/bin/opt+0x411c5f6)\r\n#11 0x000055c5f9e52d4a (/work/llvm/build/bin/opt+0x4779d4a)\r\n#12 0x000055c5fab8b53d llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) NewPMDriver.cpp:0:0\r\n#13 0x000055c5f9a1d88a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/work/llvm/build/bin/opt+0x434488a)\r\n#14 0x000055c5fab846eb 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) (/work/llvm/build/bin/opt+0x54ab6eb)\r\n#15 0x000055c5f97d4609 optMain (/work/llvm/build/bin/opt+0x40fb609)\r\n#16 0x00007faf4da29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#17 0x00007faf4da29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#18 0x00007faf4da29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#19 0x000055c5f97ce0a5 _start (/work/llvm/build/bin/opt+0x40f50a5)\r\nfish: Job 1, '/work/llvm/build/bin/opt test2.…' terminated by signal SIGABRT (Abort)\r\n```" }, { "author": "ParkHanbum", "body": "we have the test for second case at musttail-invalid.ll\r\n```declare i32 @not_tail_pos_callee()\r\ndefine i32 @not_tail_pos() {\r\n; CHECK: musttail call must precede a ret with an optional bitcast\r\n %v = musttail call i32 @not_tail_pos_callee()\r\n %w = add i32 %v, 1\r\n ret i32 %w\r\n}\r\n```\r\n\r\nbut first case is not. maybe we need to add this into testcase.\r\n\r\nfirst case \r\n```void Verifier::verifyMustTailCall(CallInst &CI) {\r\n Check(!CI.isInlineAsm(), \"cannot use musttail call with inline asm\", &CI);\r\n\r\n Function *F = CI.getParent()->getParent();\r\n FunctionType *CallerTy = F->getFunctionType();\r\n FunctionType *CalleeTy = CI.getFunctionType();\r\n Check(CallerTy->isVarArg() == CalleeTy->isVarArg(),\r\n \"cannot guarantee tail call due to mismatched varargs\", &CI);\r\n Check(isTypeCongruent(CallerTy->getReturnType(), CalleeTy->getReturnType()),\r\n \"cannot guarantee tail call due to mismatched return types\", F, CallerTy->getReturnType(), &CI, CalleeTy->getReturnType());\r\n```\r\n\r\nCallInst: %1 = musttail call i32 @F38()\r\nReturn type of Caller : %struct.S = type { i32 }\r\nReturn type of Callee: i32\r\n\r\nThis is weird. \r\nI couldn't understand why `%struct.S = type { i32 }` is changed to `i32` at `%3 = musttail call %struct.S @F38()`\r\n\r\nbut after change it to `i32` then it works.\r\n```\r\n%struct.S = type { i32 }\r\n\r\ndefine internal %struct.S @F38() {\r\n ret %struct.S { i32 0 }\r\n}\r\n\r\ndefine i32 @F36() {\r\n %3 = musttail call i32 @F38()\r\n ret i32 %3\r\n}\r\n```\r\n```\r\n% bin/opt --passes=deadargelim test.ll -S \r\n; ModuleID = 'test.ll'\r\nsource_filename = \"test.ll\"\r\n\r\n%struct.S = type { i32 }\r\n\r\ndefine internal %struct.S @F38() {\r\n ret %struct.S zeroinitializer\r\n}\r\n\r\ndefine i32 @F36() {\r\n %1 = musttail call i32 @F38()\r\n ret i32 %1\r\n}\r\n\r\n```\r\n\r\nis this normal?" }, { "author": "ParkHanbum", "body": "I found why it causes, maybe.\r\n```\r\nsource_filename = \"test.ll\"\r\n\r\n%struct.S = type { i32 }\r\n\r\ndefine internal i32 @F38() {\r\n %oldret = extractvalue %struct.S zeroinitializer, 0\r\n ret i32 %oldret\r\n}\r\n\r\ndefine %struct.S @F36() {\r\n %1 = musttail call i32 @F38()\r\n %oldret = insertvalue %struct.S poison, i32 %1, 0\r\n ret %struct.S %oldret\r\n}\r\n\r\n```\r\n\r\n" }, { "author": "ParkHanbum", "body": "we create new return type in here\r\n```\r\n// Look at each of the original return values individually.\r\n for (unsigned Ri = 0; Ri != RetCount; ++Ri) {\r\n RetOrArg Ret = createRet(F, Ri);\r\n if (LiveValues.erase(Ret)) {\r\n RetTypes.push_back(getRetComponentType(F, Ri));\r\n NewRetIdxs[Ri] = RetTypes.size() - 1;\r\n } else {\r\n ++NumRetValsEliminated;\r\n LLVM_DEBUG(\r\n dbgs() << \"DeadArgumentEliminationPass - Removing return value \"\r\n << Ri << \" from \" << F->getName() << \"\\n\");\r\n }\r\n \r\n```\r\n\r\nI tested disabling the code that creates the new return type to see if it would make a quick improvement\r\n```\r\nNRetTy = RetTy;\r\n```\r\n\r\nit seems to work\r\n```\r\n; ModuleID = 'test.ll'\r\nsource_filename = \"test.ll\"\r\n\r\n%struct.S = type { i32 }\r\n\r\ndefine internal %struct.S @F38() {\r\n ret %struct.S zeroinitializer\r\n}\r\n\r\ndefine %struct.S @F36() {\r\n %1 = musttail call %struct.S @F38()\r\n ret %struct.S %1\r\n}\r\n\r\n```\r\n\r\nIf this is a defect,\r\n1. do not change return type if it conflict with caller's return type when CB was musttail call.\r\n2. if caller's return type is conflict with new return type then change all of uses type.\r\n\r\nwe can fix it by choosing one of above. IMO\r\nhow do you think?\r\n\r\nplease let me know this issue need to fix or not~\r\n\r\n@dtcxzyw Can you please review this issue?\r\n" }, { "author": "dtcxzyw", "body": "cc @nikic @efriedma-quic " }, { "author": "efriedma-quic", "body": "I'm not sure why we're trying to run DAE on functions where we can't change the signature; why doesn't the current check for musttail callers handle this?" }, { "author": "ParkHanbum", "body": "@efriedma-quic Don't think it needs to be fix?\r\n" }, { "author": "efriedma-quic", "body": "Not sure what you're saying. I'm asking about the structure of the existing code. There are already checks for musttail calls in DeadArgumentElimination, which at first glance should exclude transforming cases like this. Can those checks be extended to also exclude this case?" } ] }
true
null
112922
https://github.com/llvm/llvm-project/issues/112922
crash
b5fa4fee46c1d0046cc395e3338ae13fe6e2cb84
2024-10-18T15:25:44
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2a6b09e0d3d3c1a05d3d5165202a6e68900974b1", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 5738, 5751 ], [ 5760, 5767 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 2958, 2968 ], [ 2976, 2983 ] ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInterleaveGroupCost" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPInterleaveRecipe::computeCost" ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 2a6b09e0d3d3c1a05d3d5165202a6e68900974b1 Author: Florian Hahn <[email protected]> Date: Fri Oct 18 19:12:39 2024 -0700 [LV] Use type from InsertPos for cost computation of interleave groups. Previously the legacy cost model would pick the type for the cost computation depending on the order of the members in the input IR. This is incompatible with the VPlan-based cost model (independent of original IR order) and also doesn't match code-gen, which uses the type of the insert position. Update the legacy cost model to use the type (and address space) from the Group's insert position. This brings the legacy cost model in line with the legacy cost model and fixes a divergence between both models. Note that the X86 cost model seems to assign different costs to groups with i64 and double types. Added a TODO to check. Fixes https://github.com/llvm/llvm-project/issues/112922. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 857efbdf687c..ce0903b838aa 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -5738,14 +5738,15 @@ LoopVectorizationCostModel::getGatherScatterCost(Instruction *I, InstructionCost LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I, ElementCount VF) { - Type *ValTy = getLoadStoreType(I); - auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF)); - unsigned AS = getLoadStoreAddressSpace(I); - enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; - const auto *Group = getInterleavedAccessGroup(I); assert(Group && "Fail to get an interleaved access group."); + Instruction *InsertPos = Group->getInsertPos(); + Type *ValTy = getLoadStoreType(InsertPos); + auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF)); + unsigned AS = getLoadStoreAddressSpace(InsertPos); + enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; + unsigned InterleaveFactor = Group->getFactor(); auto *WideVecTy = VectorType::get(ValTy, VF * InterleaveFactor); @@ -5760,8 +5761,9 @@ LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I, (Group->requiresScalarEpilogue() && !isScalarEpilogueAllowed()) || (isa<StoreInst>(I) && (Group->getNumMembers() < Group->getFactor())); InstructionCost Cost = TTI.getInterleavedMemoryOpCost( - I->getOpcode(), WideVecTy, Group->getFactor(), Indices, Group->getAlign(), - AS, CostKind, Legal->isMaskRequired(I), UseMaskForGaps); + InsertPos->getOpcode(), WideVecTy, Group->getFactor(), Indices, + Group->getAlign(), AS, CostKind, Legal->isMaskRequired(I), + UseMaskForGaps); if (Group->isReverse()) { // TODO: Add support for reversed masked interleaved access. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index f4a1f58debba..41f13cc2d9a9 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2958,11 +2958,20 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent, InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF, VPCostContext &Ctx) const { - Instruction *I = getInsertPos(); + Instruction *InsertPos = getInsertPos(); + // Find the VPValue index of the interleave group. We need to skip gaps. + unsigned InsertPosIdx = 0; + for (unsigned Idx = 0; IG->getFactor(); ++Idx) + if (auto *Member = IG->getMember(Idx)) { + if (Member == InsertPos) + break; + InsertPosIdx++; + } Type *ValTy = Ctx.Types.inferScalarType( - getNumDefinedValues() > 0 ? getVPValue(0) : getStoredValues()[0]); + getNumDefinedValues() > 0 ? getVPValue(InsertPosIdx) + : getStoredValues()[InsertPosIdx]); auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF)); - unsigned AS = getLoadStoreAddressSpace(I); + unsigned AS = getLoadStoreAddressSpace(InsertPos); enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; unsigned InterleaveFactor = IG->getFactor(); @@ -2976,8 +2985,8 @@ InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF, // Calculate the cost of the whole interleaved group. InstructionCost Cost = Ctx.TTI.getInterleavedMemoryOpCost( - I->getOpcode(), WideVecTy, IG->getFactor(), Indices, IG->getAlign(), AS, - CostKind, getMask(), NeedsMaskForGaps); + InsertPos->getOpcode(), WideVecTy, IG->getFactor(), Indices, + IG->getAlign(), AS, CostKind, getMask(), NeedsMaskForGaps); if (!IG->isReverse()) return Cost;
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/interleave-cost.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "geps_feeding_interleave_groups_with_reuse", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @geps_feeding_interleave_groups_with_reuse(ptr %arg, i64 %arg1, ptr %arg2) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %shl.iv.5 = shl i64 %iv, 5\n %gep.1 = getelementptr i8, ptr %arg, i64 %shl.iv.5\n %add.5 = or disjoint i64 %shl.iv.5, 16\n %gep.2 = getelementptr i8, ptr %arg, i64 %add.5\n %shl.iv.4 = shl i64 %iv, 4\n %gep.3 = getelementptr i8, ptr %arg2, i64 %shl.iv.4\n %l.1 = load float, ptr %gep.1, align 4\n %l.2 = load float, ptr %gep.2, align 4\n %add.1 = fadd float %l.1, %l.2\n %mul.1 = fmul float %add.1, 0.000000e+00\n store float %mul.1, ptr %gep.3, align 4\n %gep.4 = getelementptr i8, ptr %gep.1, i64 4\n %l.3 = load float, ptr %gep.4, align 4\n %gep.5 = getelementptr i8, ptr %gep.2, i64 4\n %l.4 = load float, ptr %gep.5, align 4\n %add.2 = fadd float %l.3, %l.4\n %mul.2 = fmul float %add.2, 0.000000e+00\n %gep.6 = getelementptr i8, ptr %gep.3, i64 4\n store float %mul.2, ptr %gep.6, align 4\n %gep.7 = getelementptr i8, ptr %gep.1, i64 8\n %l.5 = load float, ptr %gep.7, align 4\n %gep.8 = getelementptr i8, ptr %gep.2, i64 8\n %l.6 = load float, ptr %gep.8, align 4\n %add.3 = fadd float %l.5, %l.6\n %mul.3 = fmul float %add.3, 0.000000e+00\n %gep.9 = getelementptr i8, ptr %gep.3, i64 8\n store float %mul.3, ptr %gep.9, align 4\n %i27 = getelementptr i8, ptr %gep.1, i64 12\n %l.7 = load float, ptr %i27, align 4\n %gep.10 = getelementptr i8, ptr %gep.2, i64 12\n %l.8 = load float, ptr %gep.10, align 4\n %add.4 = fadd float %l.7, %l.8\n %mul.4 = fmul float %add.4, 0.000000e+00\n %gep.11 = getelementptr i8, ptr %gep.3, i64 12\n store float %mul.4, ptr %gep.11, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, %arg1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+sse4.2\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "geps_feeding_interleave_groups_with_reuse2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @geps_feeding_interleave_groups_with_reuse2(ptr %A, ptr %B, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.7, %loop ]\n %shr.1 = lshr exact i64 %iv, 1\n %gep.B = getelementptr nusw i32, ptr %B, i64 %shr.1\n %l = load i32, ptr %gep.B, align 4\n %gep.A = getelementptr i32, ptr %A, i64 %iv\n store i32 %l, ptr %gep.A, align 4\n %iv.next = or disjoint i64 %iv, 1\n %gep.A.1 = getelementptr i32, ptr %A, i64 %iv.next\n store i32 0, ptr %gep.A.1, align 4\n %iv.next.1 = or disjoint i64 %iv, 2\n %shr.2 = lshr exact i64 %iv.next.1, 1\n %gep.B.2 = getelementptr i32, ptr %B, i64 %shr.2\n %0 = load i32, ptr %gep.B.2, align 4\n %gep.A.2 = getelementptr i32, ptr %A, i64 %iv.next.1\n store i32 %0, ptr %gep.A.2, align 4\n %iv.next.2 = or disjoint i64 %iv, 3\n %gep.A.3 = getelementptr i32, ptr %A, i64 %iv.next.2\n store i32 0, ptr %gep.A.3, align 4\n %iv.next.3 = or disjoint i64 %iv, 4\n %gep.B.4 = getelementptr i32, ptr %B, i64 %iv\n %1 = load i32, ptr %gep.B.4, align 4\n %gep.A.4 = getelementptr i32, ptr %A, i64 %iv.next.3\n store i32 %1, ptr %gep.A.4, align 4\n %iv.next.4 = or disjoint i64 %iv, 5\n %gep.A.5 = getelementptr i32, ptr %A, i64 %iv.next.4\n store i32 0, ptr %gep.A.5, align 4\n %iv.next.5 = or disjoint i64 %iv, 6\n %gep.A.6 = getelementptr i32, ptr %A, i64 %iv.next.5\n store i32 0, ptr %gep.A.6, align 4\n %iv.next.6 = or disjoint i64 %iv, 7\n %gep.A.7 = getelementptr i32, ptr %A, i64 %iv.next.6\n store i32 0, ptr %gep.A.7, align 4\n %iv.next.7 = add nuw nsw i64 %iv, 8\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"cascadelake\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "interleave_store_double_i64_2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_double_i64_2(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.1 = getelementptr { i64, double }, ptr %dst, i64 %iv, i32 1\n store double 0.000000e+00, ptr %gep.1, align 8\n %gep.0 = getelementptr { i64, double }, ptr %dst, i64 %iv\n store i64 %iv, ptr %gep.0, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "interleave_store_i64_double", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_i64_double(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.0 = getelementptr { double, i64 }, ptr %dst, i64 %iv\n store double 0.000000e+00, ptr %gep.0, align 8\n %gep.1 = getelementptr { double, i64 }, ptr %dst, i64 %iv, i32 1\n store i64 %iv, ptr %gep.1, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_free_instructions_feeding_geps_for_interleave_groups", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @test_free_instructions_feeding_geps_for_interleave_groups(ptr noalias %p.invar, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.0 = load float, ptr %p.invar, align 4\n %iv.mul = shl i64 %iv, 2\n %gep.dst.19 = getelementptr float, ptr %dst.1, i64 %iv.mul\n store float %l.0, ptr %gep.dst.19, align 4\n %l.1 = load float, ptr %p.invar, align 4\n %add.1 = or disjoint i64 %iv.mul, 1\n %gep.dst.119 = getelementptr float, ptr %dst.1, i64 %add.1\n store float %l.1, ptr %gep.dst.119, align 4\n %add.2 = or disjoint i64 %iv.mul, 2\n %gep.dst.129 = getelementptr float, ptr %dst.1, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.129, align 4\n %add.3 = or disjoint i64 %iv.mul, 3\n %gep.dst.140 = getelementptr float, ptr %dst.1, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.140, align 4\n %l.2 = load float, ptr %p.invar, align 4\n %gep.dst.247 = getelementptr float, ptr %dst.2, i64 %iv.mul\n store float %l.2, ptr %gep.dst.247, align 4\n %gep.dst.255 = getelementptr float, ptr %dst.2, i64 %add.1\n store float 0.000000e+00, ptr %gep.dst.255, align 4\n %gep.dst.265 = getelementptr float, ptr %dst.2, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.265, align 4\n %gep.dst.276 = getelementptr float, ptr %dst.2, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.276, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "interleave_store_double_i64", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_double_i64(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.1 = getelementptr { double, i64 }, ptr %dst, i64 %iv, i32 1\n store i64 %iv, ptr %gep.1, align 8\n %gep.0 = getelementptr { double, i64 }, ptr %dst, i64 %iv\n store double 0.000000e+00, ptr %gep.0, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "interleave_store_i64_double_2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_i64_double_2(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.0 = getelementptr { i64, double }, ptr %dst, i64 %iv\n store i64 %iv, ptr %gep.0, align 8\n %gep.1 = getelementptr { i64, double }, ptr %dst, i64 %iv, i32 1\n store double 0.000000e+00, ptr %gep.1, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Assertion in `llvm::LoopVectorizationPlanner::computeBestVF()`", "body": "When building the METIS (v5.1.0) library (GKLib) an assertion is thrown during LoopVectorize. This error was introduced within the past few days (see git sha of broken and working versions below).\r\n\r\n#### Error:\r\n```shell\r\nclang: /mnt/thera/cicd/actions_work/ActionsRunner/ActionsRunner/trunk_repos/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7457: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /share/contrib-modules/Core/llvm/2024-10-16/bin/clang -I/home/bcornill/libraries/metis-5.1.0/GKlib/. -I/home/bcornill/libraries/metis-5.1.0/GKlib/test -DLINUX -D_FILE_OFFSET_BITS=64 -DNDEBUG -DNDEBUG2 -DHAVE_EXECINFO_H -DHAVE_GETLINE -O3 -MD -MT CMakeFiles/GKlib.dir/blas.c.o -MF CMakeFiles/GKlib.dir/blas.c.o.d -o CMakeFiles/GKlib.dir/blas.c.o -c /home/bcornill/libraries/metis-5.1.0/GKlib/blas.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"/home/bcornill/libraries/metis-5.1.0/GKlib/blas.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"gk_dargmax_n\"\r\n #0 0x00007fa15911cc8b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMSupport.so.20.0git+0x1c2c8b)\r\n #1 0x00007fa15911a664 llvm::sys::CleanupOnSignal(unsigned long) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMSupport.so.20.0git+0x1c0664)\r\n #2 0x00007fa1590227f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007fa1615e0dd0 __restore_rt sigaction.c:0:0\r\n #4 0x00007fa15821e70f raise (/lib64/libc.so.6+0x3770f)\r\n #5 0x00007fa158208b25 abort (/lib64/libc.so.6+0x21b25)\r\n #6 0x00007fa1582089f9 _nl_load_domain.cold.0 loadmsgcat.c:0:0\r\n #7 0x00007fa158216cc6 .annobin___GI___assert_fail.end assert.c:0:0\r\n #8 0x00007fa15db3af1b llvm::LoopVectorizationPlanner::computeBestVF() (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xb5f1b)\r\n #9 0x00007fa15db52d46 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xcdd46)\r\n#10 0x00007fa15db55ed1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xd0ed1)\r\n#11 0x00007fa15db56517 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xd1517)\r\n#12 0x00007fa155d90a9e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/../lib/libLLVMPasses.so.20.0git+0x76a9e)\r\n#13 0x00007fa15998eab7 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMCore.so.20.0git+0x323ab7)\r\n#14 0x00007fa16434e17e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMX86CodeGen.so.20.0git+0xa917e)\r\n#15 0x00007fa15998ce55 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMCore.so.20.0git+0x321e55)\r\n#16 0x00007fa16434e56e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMX86CodeGen.so.20.0git+0xa956e)\r\n#17 0x00007fa15998d9bc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMCore.so.20.0git+0x3229bc)\r\n#18 0x00007fa15faab288 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#19 0x00007fa15faaeb9c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangCodeGen.so.20.0git+0x111b9c)\r\n#20 0x00007fa15ffdd293 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangCodeGen.so.20.0git+0x640293)\r\n#21 0x00007fa150c5592c clang::ParseAST(clang::Sema&, bool, bool) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/../lib/libclangParse.so.20.0git+0x3c92c)\r\n#22 0x00007fa15d75dee9 clang::FrontendAction::Execute() (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangFrontend.so.20.0git+0x138ee9)\r\n#23 0x00007fa15d6ceb05 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangFrontend.so.20.0git+0xa9b05)\r\n#24 0x00007fa1613cad83 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangFrontendTool.so.20.0git+0x4d83)\r\n#25 0x00000000004141c7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x4141c7)\r\n#26 0x000000000040b96a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#27 0x00007fa15d135049 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#28 0x00007fa159022cb4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMSupport.so.20.0git+0xc8cb4)\r\n#29 0x00007fa15d13589e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#30 0x00007fa15d0f22fc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangDriver.so.20.0git+0x922fc)\r\n#31 0x00007fa15d0f33fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangDriver.so.20.0git+0x933fd)\r\n#32 0x00007fa15d1039c4 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangDriver.so.20.0git+0xa39c4)\r\n#33 0x0000000000410b5b clang_main(int, char**, llvm::ToolContext const&) (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x410b5b)\r\n#34 0x000000000040b074 main (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x40b074)\r\n#35 0x00007fa15820a6a3 __libc_start_main (/lib64/libc.so.6+0x236a3)\r\n#36 0x000000000040b0be _start (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x40b0be)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project ae68d532f810e217c747b10b26aeea3bb84c3844)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/clang.cfg\r\nclang: note: diagnostic msg:\r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclang: note: diagnostic msg: /tmp/blas-9fe25d.c\r\nclang: note: diagnostic msg: /tmp/blas-9fe25d.sh\r\nclang: note: diagnostic msg:\r\n\r\n********************\r\n```\r\n#### Reproducer:\r\n[gklib-blas.tar.gz](https://github.com/user-attachments/files/17437550/gklib-blas.tar.gz)\r\n\r\n#### Broken Versions:\r\n```shell\r\n>> clang --version\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project ae68d532f810e217c747b10b26aeea3bb84c3844)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/clang.cfg\r\n\r\n>> clang --version\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project af90e7c5161de9a36af768dd5c9d73464e0eed64)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-18_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-18_20.0-0/bin/clang.cfg\r\n```\r\n\r\n#### Working version:\r\n```shell\r\n>> clang --version\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project 48deb3568eb2452ff385b04b8f71c34121f47387)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-13_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-13_20.0-0/bin/clang.cfg\r\n```", "author": "bcornille", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Thanks, taking a look!" } ] }
true
null
122583
https://github.com/llvm/llvm-project/issues/122583
miscompilation
16e45b8fac797c6d4ba161228b54665492204a9d
2025-01-11T07:48:51
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "066b88879ab5c195e7e14609e546cc238c2f3bf3", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 2441, 2446 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "appendOperandsOfVL" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 066b88879ab5c195e7e14609e546cc238c2f3bf3 Author: Alexey Bataev <[email protected]> Date: Mon Jan 13 10:51:26 2025 -0800 [SLP]Correctly set vector operand for extracts with poisons When extracts are vectorized and it has some poison values instead of instructions, need to correctly set the vectorized operand not as poison, but as a main vector operand of the main extract instruction. Fixes #122583 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4b0ed5b30179..2742c3777c1e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2441,6 +2441,17 @@ public: // operations or alternating sequences (e.g., +, -), we can safely // tell the inverse operations by checking commutativity. if (isa<PoisonValue>(VL[Lane])) { + if (auto *EI = dyn_cast<ExtractElementInst>(VL0)) { + if (OpIdx == 0) { + OpsVec[OpIdx][Lane] = {EI->getVectorOperand(), true, false}; + continue; + } + } else if (auto *EV = dyn_cast<ExtractValueInst>(VL0)) { + if (OpIdx == 0) { + OpsVec[OpIdx][Lane] = {EV->getAggregateOperand(), true, false}; + continue; + } + } OpsVec[OpIdx][Lane] = { PoisonValue::get(VL0->getOperand(OpIdx)->getType()), true, false};
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/extractelemets-extended-by-poison.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@j = global [4 x i64] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.pre.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 24), align 8\n %.pre50.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 16), align 16\n %.pre51.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 8), align 8\n %.pre52.i = load i64, ptr @j, align 16\n %0 = or i64 %.pre51.i, 0\n %1 = trunc i64 %.pre.i to i32\n %2 = add i32 %1, 0\n %3 = trunc i64 %.pre50.i to i32\n %4 = add i32 %3, 0\n %5 = trunc i64 %.pre51.i to i32\n %6 = add i32 %5, 0\n %7 = trunc i64 0 to i32\n %8 = add i32 %5, 0\n %9 = add i32 %7, 0\n %10 = add i32 %1, 0\n %11 = add i32 %3, 0\n %12 = add i32 %5, 0\n %13 = add i32 %7, 0\n %14 = trunc i64 %.pre.i to i32\n %15 = add i32 %14, 0\n %16 = trunc i64 %.pre50.i to i32\n %17 = add i32 %16, 0\n %18 = trunc i64 %.pre51.i to i32\n %19 = add i32 %18, 0\n %20 = trunc i64 %.pre52.i to i32\n %conv14.1.i = or i32 %9, %13\n %21 = or i32 %conv14.1.i, %6\n %22 = or i32 %21, %8\n %23 = or i32 %22, %12\n %24 = or i32 %23, %4\n %25 = or i32 %24, %11\n %26 = or i32 %25, %2\n %27 = or i32 %26, %10\n %28 = or i32 %27, %15\n %29 = or i32 %28, %17\n %30 = or i32 %29, %19\n %31 = add i32 %14, 0\n %32 = add i32 %16, 0\n %33 = add i32 %18, 0\n %34 = add i32 %20, 0\n %35 = add i32 %14, 0\n %36 = add i32 %16, 0\n %37 = add i32 %18, 0\n %38 = add i32 %20, 0\n %39 = add i32 %14, 0\n %40 = add i32 %16, 0\n %41 = add i32 %18, 0\n %42 = add i32 %20, 0\n %inc.3.3.i.1 = or i64 %.pre52.i, 0\n %conv14.i.1 = or i32 %38, %34\n %conv14.1.i.1 = or i32 %conv14.i.1, %42\n %conv14.3.i.1 = or i32 %conv14.1.i.1, %33\n %conv14.145.i.1 = or i32 %conv14.3.i.1, %37\n %conv14.1.1.i.1 = or i32 %conv14.145.i.1, %41\n %conv14.3.1.i.1 = or i32 %conv14.1.1.i.1, %32\n %conv14.247.i.1 = or i32 %conv14.3.1.i.1, %36\n %conv14.1.2.i.1 = or i32 %conv14.247.i.1, %40\n %conv14.3.2.i.1 = or i32 %conv14.1.2.i.1, %31\n %conv14.349.i.1 = or i32 %conv14.3.2.i.1, %35\n %conv14.1.3.i.1 = or i32 %conv14.349.i.1, %39\n %conv14.3.3.i.1 = or i32 %conv14.1.3.i.1, %30\n ret i32 %conv14.3.3.i.1\n}\n", "additional_args": null, "lli_expected_out": "" } ] } ]
{ "title": "[SLPVectorizer] Miscompilation", "body": "Reproducer: https://godbolt.org/z/7eEEeeKoo\nSorry, I cannot provide alive2 link since `llvm.vector.insert.v8i64.v4i64` is not supported.\n```\n; bin/opt -passes=slp-vectorizer reduced.ll -S -o opt.ll\n\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@j = global [4 x i64] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.pre.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 24), align 8\n %.pre50.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 16), align 16\n %.pre51.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 8), align 8\n %.pre52.i = load i64, ptr @j, align 16\n %0 = or i64 %.pre51.i, 0\n %1 = trunc i64 %.pre.i to i32\n %2 = add i32 %1, 0\n %3 = trunc i64 %.pre50.i to i32\n %4 = add i32 %3, 0\n %5 = trunc i64 %.pre51.i to i32\n %6 = add i32 %5, 0\n %7 = trunc i64 0 to i32\n %8 = add i32 %5, 0\n %9 = add i32 %7, 0\n %10 = add i32 %1, 0\n %11 = add i32 %3, 0\n %12 = add i32 %5, 0\n %13 = add i32 %7, 0\n %14 = trunc i64 %.pre.i to i32\n %15 = add i32 %14, 0\n %16 = trunc i64 %.pre50.i to i32\n %17 = add i32 %16, 0\n %18 = trunc i64 %.pre51.i to i32\n %19 = add i32 %18, 0\n %20 = trunc i64 %.pre52.i to i32\n %conv14.1.i = or i32 %9, %13\n %21 = or i32 %conv14.1.i, %6\n %22 = or i32 %21, %8\n %23 = or i32 %22, %12\n %24 = or i32 %23, %4\n %25 = or i32 %24, %11\n %26 = or i32 %25, %2\n %27 = or i32 %26, %10\n %28 = or i32 %27, %15\n %29 = or i32 %28, %17\n %30 = or i32 %29, %19\n %31 = add i32 %14, 0\n %32 = add i32 %16, 0\n %33 = add i32 %18, 0\n %34 = add i32 %20, 0\n %35 = add i32 %14, 0\n %36 = add i32 %16, 0\n %37 = add i32 %18, 0\n %38 = add i32 %20, 0\n %39 = add i32 %14, 0\n %40 = add i32 %16, 0\n %41 = add i32 %18, 0\n %42 = add i32 %20, 0\n %inc.3.3.i.1 = or i64 %.pre52.i, 0\n %conv14.i.1 = or i32 %38, %34\n %conv14.1.i.1 = or i32 %conv14.i.1, %42\n %conv14.3.i.1 = or i32 %conv14.1.i.1, %33\n %conv14.145.i.1 = or i32 %conv14.3.i.1, %37\n %conv14.1.1.i.1 = or i32 %conv14.145.i.1, %41\n %conv14.3.1.i.1 = or i32 %conv14.1.1.i.1, %32\n %conv14.247.i.1 = or i32 %conv14.3.1.i.1, %36\n %conv14.1.2.i.1 = or i32 %conv14.247.i.1, %40\n %conv14.3.2.i.1 = or i32 %conv14.1.2.i.1, %31\n %conv14.349.i.1 = or i32 %conv14.3.2.i.1, %35\n %conv14.1.3.i.1 = or i32 %conv14.349.i.1, %39\n %conv14.3.3.i.1 = or i32 %conv14.1.3.i.1, %30\n ret i32 %conv14.3.3.i.1\n}\n```\nOutput:\n```\nsource_filename = \"/app/example.ll\"\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main() {\n %0 = load <4 x i64>, ptr @j, align 16\n %1 = or i64 poison, 0\n %2 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 1, i32 poison, i32 poison>\n %3 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>\n %4 = shufflevector <8 x i64> %3, <8 x i64> <i64 poison, i64 poison, i64 poison, i64 poison, i64 0, i64 poison, i64 poison, i64 poison>, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 12, i32 1, i32 poison, i32 poison>\n %5 = call <8 x i64> @llvm.vector.insert.v8i64.v4i64(<8 x i64> %4, <4 x i64> %0, i64 0)\n %6 = trunc <8 x i64> %5 to <8 x i32>\n %7 = shufflevector <8 x i32> %6, <8 x i32> poison, <16 x i32> <i32 0, i32 0, i32 0, i32 1, i32 1, i32 1, i32 2, i32 2, i32 2, i32 3, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5>\n %8 = add <16 x i32> %7, zeroinitializer\n %9 = extractelement <4 x i64> %0, i32 0\n %inc.3.3.i.1 = or i64 %9, 0\n %10 = call i32 @llvm.vector.reduce.or.v16i32(<16 x i32> %8)\n %11 = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> poison)\n %op.rdx = or i32 %10, %11\n ret i32 %op.rdx\n}\n\ndeclare <8 x i64> @llvm.vector.insert.v8i64.v4i64(<8 x i64>, <4 x i64>, i64 immarg) #0\n\ndeclare i32 @llvm.vector.reduce.or.v16i32(<16 x i32>) #0\n\ndeclare i32 @llvm.vector.reduce.or.v8i32(<8 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```\nlli output:\n```\n> bin/lli reduced.ll\n> echo $?\n0\n> bin/lli opt.ll\n> echo $?\n255\n```\n[llubi](https://github.com/dtcxzyw/llvm-ub-aware-interpreter) output:\nBefore:\n```\n> ./llubi reduced.ll --verbose\nEntering function main\n %0 = getelementptr inbounds nuw i8, ptr @j, i64 24 -> Ptr 40[@j + 24]\n %.pre.i = load i64, ptr %0, align 8 -> i64 0\n %1 = getelementptr inbounds nuw i8, ptr @j, i64 16 -> Ptr 32[@j + 16]\n %.pre50.i = load i64, ptr %1, align 16 -> i64 0\n %2 = getelementptr inbounds nuw i8, ptr @j, i64 8 -> Ptr 24[@j + 8]\n %.pre51.i = load i64, ptr %2, align 8 -> i64 0\n %.pre52.i = load i64, ptr @j, align 16 -> i64 0\n %3 = or i64 %.pre51.i, 0 -> i64 0\n %4 = trunc i64 %.pre.i to i32 -> i32 0\n %5 = add i32 %4, 0 -> i32 0\n %6 = trunc i64 %.pre50.i to i32 -> i32 0\n %7 = add i32 %6, 0 -> i32 0\n %8 = trunc i64 %.pre51.i to i32 -> i32 0\n %9 = add i32 %8, 0 -> i32 0\n %10 = trunc i64 0 to i32 -> i32 0\n %11 = add i32 %8, 0 -> i32 0\n %12 = add i32 %10, 0 -> i32 0\n %13 = add i32 %4, 0 -> i32 0\n %14 = add i32 %6, 0 -> i32 0\n %15 = add i32 %8, 0 -> i32 0\n %16 = add i32 %10, 0 -> i32 0\n %17 = trunc i64 %.pre.i to i32 -> i32 0\n %18 = add i32 %17, 0 -> i32 0\n %19 = trunc i64 %.pre50.i to i32 -> i32 0\n %20 = add i32 %19, 0 -> i32 0\n %21 = trunc i64 %.pre51.i to i32 -> i32 0\n %22 = add i32 %21, 0 -> i32 0\n %23 = trunc i64 %.pre52.i to i32 -> i32 0\n %conv14.1.i = or i32 %12, %16 -> i32 0\n %24 = or i32 %conv14.1.i, %9 -> i32 0\n %25 = or i32 %24, %11 -> i32 0\n %26 = or i32 %25, %15 -> i32 0\n %27 = or i32 %26, %7 -> i32 0\n %28 = or i32 %27, %14 -> i32 0\n %29 = or i32 %28, %5 -> i32 0\n %30 = or i32 %29, %13 -> i32 0\n %31 = or i32 %30, %18 -> i32 0\n %32 = or i32 %31, %20 -> i32 0\n %33 = or i32 %32, %22 -> i32 0\n %34 = add i32 %17, 0 -> i32 0\n %35 = add i32 %19, 0 -> i32 0\n %36 = add i32 %21, 0 -> i32 0\n %37 = add i32 %23, 0 -> i32 0\n %38 = add i32 %17, 0 -> i32 0\n %39 = add i32 %19, 0 -> i32 0\n %40 = add i32 %21, 0 -> i32 0\n %41 = add i32 %23, 0 -> i32 0\n %42 = add i32 %17, 0 -> i32 0\n %43 = add i32 %19, 0 -> i32 0\n %44 = add i32 %21, 0 -> i32 0\n %45 = add i32 %23, 0 -> i32 0\n %inc.3.3.i.1 = or i64 %.pre52.i, 0 -> i64 0\n %conv14.i.1 = or i32 %41, %37 -> i32 0\n %conv14.1.i.1 = or i32 %conv14.i.1, %45 -> i32 0\n %conv14.3.i.1 = or i32 %conv14.1.i.1, %36 -> i32 0\n %conv14.145.i.1 = or i32 %conv14.3.i.1, %40 -> i32 0\n %conv14.1.1.i.1 = or i32 %conv14.145.i.1, %44 -> i32 0\n %conv14.3.1.i.1 = or i32 %conv14.1.1.i.1, %35 -> i32 0\n %conv14.247.i.1 = or i32 %conv14.3.1.i.1, %39 -> i32 0\n %conv14.1.2.i.1 = or i32 %conv14.247.i.1, %43 -> i32 0\n %conv14.3.2.i.1 = or i32 %conv14.1.2.i.1, %34 -> i32 0\n %conv14.349.i.1 = or i32 %conv14.3.2.i.1, %38 -> i32 0\n %conv14.1.3.i.1 = or i32 %conv14.349.i.1, %42 -> i32 0\n %conv14.3.3.i.1 = or i32 %conv14.1.3.i.1, %33 -> i32 0\n ret i32 %conv14.3.3.i.1\nExiting function main\n```\nAfter:\n```\n> ./llubi opt.ll --verbose\nEntering function main\n %0 = load <4 x i64>, ptr @j, align 16 -> { i64 0, i64 0, i64 0, i64 0 }\n %1 = or i64 poison, 1 -> poison\n %2 = or i64 poison, 0 -> poison\n %3 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 1, i32 poison, i32 poison> -> { poison, poison, poison, poison, poison, i64 0, poison, poison }\n %4 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison> -> { i64 0, i64 0, i64 0, i64 0, poison, poison, poison, poison }\n %5 = shufflevector <8 x i64> %4, <8 x i64> <i64 poison, i64 poison, i64 poison, i64 poison, i64 0, i64 poison, i64 poison, i64 poison>, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 12, i32 1, i32 poison, i32 poison> -> { poison, poison, poison, poison, i64 0, i64 0, poison, poison }\n %6 = call <8 x i64> @llvm.vector.insert.v8i64.v4i64(<8 x i64> %5, <4 x i64> %0, i64 0) -> { i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, poison, poison }\n %7 = trunc <8 x i64> %6 to <8 x i32> -> { i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, poison, poison }\n %8 = shufflevector <8 x i32> %7, <8 x i32> poison, <16 x i32> <i32 0, i32 0, i32 0, i32 1, i32 1, i32 1, i32 2, i32 2, i32 2, i32 3, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5> -> { i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }\n %9 = add <16 x i32> %8, zeroinitializer -> { i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }\n %10 = extractelement <4 x i64> %0, i32 0 -> i64 0\n %inc.3.3.i.1 = or i64 %10, 0 -> i64 0\n %11 = call i32 @llvm.vector.reduce.or.v16i32(<16 x i32> %9) -> i32 0\n %12 = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> poison) -> poison\n %op.rdx = or i32 %11, %12 -> poison\n ret i32 %op.rdx\nExiting function main\n\nUB triggered: Return a poison value\nExited with immediate UB.\nStacktrace:\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SLPVectorizer", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "llvm version: 6329355860e9b66bc7ed68b46c166763e408d4cc" } ] }
true
null
138345
https://github.com/llvm/llvm-project/issues/138345
crash
1c1238d3615a7e1a99570d1e02de3b538d2e0669
2025-05-02T21:00:30
[ "llvm/test/Transforms/GVNSink" ]
{ "fix_commit": "43eafc0c4aca0b2fd159c09d4b162c1941b4f4ed", "components": [ "Local" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/Utils/Local.cpp": [ [ 4225, 4232 ] ], "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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/Utils/Local.cpp": [ "llvm::canReplaceOperandWithVariable" ], "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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 43eafc0c4aca0b2fd159c09d4b162c1941b4f4ed Author: Paul Kirth <[email protected]> Date: Mon May 5 18:16:33 2025 -0700 [llvm][gvn-sink] Don't try to sink inline asm (#138414) Fixes #138345. Before this patch, gvn-sink would try to sink inline assembly statements. Other GVN passes avoid them (see https://github.com/llvm/llvm-project/blob/b4fac94181c4cf17dbb7ecc2ae975712b0e4a6d1/llvm/lib/Transforms/Scalar/GVN.cpp#L2932 Similarly, gvn-sink should skip these instructions, since they are not safe to move. To do this, we update the early exit in canReplaceOperandWithVariable, since it should have caught this case. It's more efficient to also skip numbering in GVNSink if the instruction is InlineAsm, but that should be infrequent. The test added is reduced from a failure when compiling Fuchsia with gvn-sink. diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 809a0d7ebeea..ce03bc066c6e 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -4225,8 +4225,9 @@ bool llvm::canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx) { return false; // Early exit. - if (!isa<Constant>(I->getOperand(OpIdx))) + if (!isa<Constant, InlineAsm>(I->getOperand(OpIdx))) { return true; + } switch (I->getOpcode()) { default:
[ { "file": "llvm/test/Transforms/GVNSink/pr138345.ll", "commands": [ "opt -passes=\"gvn-sink\" -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n;; See https://github.com/llvm/llvm-project/issues/138345 for details.\n;; The program below used to crash due to taking the address of the inline asm.\n;; gvn-sink shouldn't do anything in this case, so test that the pass no longer\n;; generates invalid IR and no longer crashes.\n\ndefine void @c(i64 %num, ptr %ptr) {\n;\nentry:\n switch i64 %num, label %sw.epilog [\n i64 1, label %sw.bb\n i64 0, label %sw.bb1\n ]\n\nsw.bb: ; preds = %entry\n %1 = load i8, ptr %ptr, align 1\n call void asm sideeffect \"\", \"r,r,~{dirflag},~{fpsr},~{flags}\"(i8 %1, ptr @c)\n br label %sw.epilog\n\nsw.bb1: ; preds = %entry\n %2 = load i8, ptr %ptr, align 1\n call void asm sideeffect \"movdqu 0 %xmm0 \\0A\\09\", \"r,r,~{dirflag},~{fpsr},~{flags}\"(i8 %2, ptr @c)\n br label %sw.epilog\n\nsw.epilog: ; preds = %sw.bb1, %sw.bb, %entry\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion failure with gvn-sink", "body": "I tried to enable GVN hoist/sink when compiling Fuchsia at -Oz, since that should improve size slightly, and ran into this. I know those passes have had some issues, but I figured they had some attention a while back and we should try again. Probably some value as a regression test, if nothing else.\n\nAssertion:\n```console\n'llvm/lib/Analysis/LazyValueInfo.cpp:679: std::optional<ValueLatticeElement> llvm::LazyValueInfoImpl::solveBlockValueNonLocal(Value *, BasicBlock *): Assertion `isa<Argument>(Val) && \"Unknown live-in to the entry block\"' failed.\n```\n\nHere's a reduced test case where the assertion triggers.\n\n```LLVM\n; RUN: opt -passes=\"gvn-sink,correlated-propagation\" -disable-output %s\n\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @c(i64 %0) {\nentry:\n switch i64 %0, label %sw.epilog [\n i64 1, label %sw.bb\n i64 0, label %sw.bb1\n ]\n\nsw.bb: ; preds = %entry\n %1 = load i8, ptr null, align 1\n call void asm sideeffect \"\", \"r,r,~{dirflag},~{fpsr},~{flags}\"(i8 %1, ptr @c)\n br label %sw.epilog\n\nsw.bb1: ; preds = %entry\n %2 = load i8, ptr null, align 1\n call void asm sideeffect \"movdqu 0 %xmm0 \\0A\\09\", \"r,r,~{dirflag},~{fpsr},~{flags}\"(i8 %2, ptr @c)\n br label %sw.epilog\n\nsw.epilog: ; preds = %sw.bb1, %sw.bb, %entry\n ret void\n}\n```\n\nFrom Clang:\n\n```c++\n// RUN: clang -cc1 -Os -mllvm -enable-gvn-hoist -mllvm -enable-gvn-sink -mllvm -wholeprogramdevirt-branch-funnel-threshold=0 -emit-llvm %s\nlong a;\nchar b;\nvoid c() {\n switch (a) {\n case 8:\n __asm(\"\" : : \"r\"(b), \"r\"(c));\n break;\n case 6:\n __asm(\"movdqu 0 %%xmm0 \\n\\t\" : : \"r\"(b), \"r\"(c));\n }\n}\n```", "author": "ilovepi", "labels": [ "crash-on-valid", "llvm:GVN" ], "comments": [] }
true
null
95547
https://github.com/llvm/llvm-project/issues/95547
miscompilation
7767f0d47428db66d65b07b35aa52f0507df71f9
2024-06-14T13:54:00
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "534f8569a3c9fccfd5cbc5f632b63ad0cf711098", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": [ [ 291, 300 ] ], "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": [ "canEvaluateTruncated" ], "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 534f8569a3c9fccfd5cbc5f632b63ad0cf711098 Author: Nikita Popov <[email protected]> Date: Mon Jun 17 15:36:55 2024 +0200 [InstCombine] Don't preserve context across div We can't preserve the context across a non-speculatable instruction, as this might introduce a trap. Alternatively, we could also insert all the replacement instruction at the use-site, but that would be a more intrusive change for the sake of this edge case. Fixes https://github.com/llvm/llvm-project/issues/95547. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 1b4c319032ca..6a6bdba3fa70 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -291,10 +291,12 @@ static bool canEvaluateTruncated(Value *V, Type *Ty, InstCombinerImpl &IC, uint32_t BitWidth = Ty->getScalarSizeInBits(); assert(BitWidth < OrigBitWidth && "Unexpected bitwidths!"); APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, BitWidth); - if (IC.MaskedValueIsZero(I->getOperand(0), Mask, 0, CxtI) && - IC.MaskedValueIsZero(I->getOperand(1), Mask, 0, CxtI)) { - return canEvaluateTruncated(I->getOperand(0), Ty, IC, CxtI) && - canEvaluateTruncated(I->getOperand(1), Ty, IC, CxtI); + // Do not preserve the original context instruction. Simplifying div/rem + // based on later context may introduce a trap. + if (IC.MaskedValueIsZero(I->getOperand(0), Mask, 0, I) && + IC.MaskedValueIsZero(I->getOperand(1), Mask, 0, I)) { + return canEvaluateTruncated(I->getOperand(0), Ty, IC, I) && + canEvaluateTruncated(I->getOperand(1), Ty, IC, I); } break; }
[ { "file": "llvm/test/Transforms/InstCombine/trunc.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "trunc_nuw_xor_vector", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine <2 x i1> @trunc_nuw_xor_vector(<2 x i8> %x, <2 x i8> %y) {\n %xor = xor <2 x i8> %x, %y\n %r = trunc nuw <2 x i8> %xor to <2 x i1>\n ret <2 x i1> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr95547", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndeclare void @use.i8(i8)\n\ndefine void @pr95547(i32 %x) {\n %x.trunc = trunc i32 %x to i16\n %div = udiv i16 11, %x.trunc\n %cmp = icmp ult i32 %x, 256\n br i1 %cmp, label %loop, label %exit\n\nloop: ; preds = %loop, %0\n %trunc = trunc i16 %div to i8\n call void @use.i8(i8 %trunc)\n br label %loop\n\nexit: ; preds = %0\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Wrong value truncation due to incorrect analysis of iv known bits", "body": "```llvm\r\ndefine void @src(i32 %0, ptr %p, i1 %cnd) {\r\nentry:\r\n br i1 %cnd, label %header, label %exit\r\n\r\nheader: ; preds = %latch, %entry\r\n %iv = phi i32 [ %iv.next, %latch ], [ 256, %entry ]\r\n %iv.trunc = trunc i32 %iv to i16\r\n %div = udiv i16 11, %iv.trunc\r\n br i1 %cnd, label %loop1, label %loop0\r\n\r\nloop0: ; preds = %header\r\n %load = load i32, ptr %p, align 4\r\n br label %loop1\r\n\r\nloop1: ; preds = %loop0, %header\r\n %v = phi i32 [ %load, %loop0 ], [ 0, %header ]\r\n store i32 %v, ptr %p, align 4\r\n %guard = icmp ugt i32 %iv, 10\r\n br i1 %guard, label %latch, label %loop2\r\n\r\nloop2: ; preds = %loop1\r\n %div.trunc = trunc i16 %div to i8\r\n store i8 %div.trunc, ptr %p, align 1\r\n br label %latch\r\n\r\nlatch: ; preds = %loop2, %loop1\r\n %iv.next = add nuw nsw i32 %iv, 1\r\n %exitcond = icmp ugt i32 %iv, 300\r\n br i1 %exitcond, label %exit, label %header\r\n\r\nexit: ; preds = %latch\r\n ret void\r\n}\r\n```\r\nIf we run `instcombine` pass on this example, it will convert `trunc i32 %iv to i16` into `trunc i32 %iv to i8` to avoid cast:\r\nhttps://godbolt.org/z/ze4E45ThT\r\n\r\nBut this transformation is wrong, because on the first iteration `%iv` is equal to 256, and the 8 bits trunc makes it equal to `0`. This give us a division by zero on the next instruction: `%div = udiv i16 11, %iv.trunc`.\r\n\r\nIt seems that the problematic patch is https://github.com/llvm/llvm-project/pull/73662\r\n\r\n@nikic Could you please take a look?", "author": "aleks-tmb", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "antoniofrighetto", "body": "May be false positive in Alive2 as well?" }, { "author": "dtcxzyw", "body": "> May be false positive in Alive2 as well?\r\n\r\nYou need `-src-unroll` and `-tgt-unroll` for loops :)\r\nhttps://alive2.llvm.org/ce/z/Vh4zAU" }, { "author": "antoniofrighetto", "body": "Just out of curiosity, did you fine-tune the iterations in a particular way, or some trial-and-error? (I had tried a few ones before and didn’t manage to have the UB triggered)" }, { "author": "dtcxzyw", "body": "> Just out of curiosity, did you fine-tune the iterations in a particular way, or some trial-and-error? (I had tried a few ones before and didn’t manage to have the UB triggered)\r\n\r\nI just full unrolled the loop :)\r\n```\r\n%iv.next = add nuw nsw i32 %iv, 1\r\n%exitcond = icmp ugt i32 %iv, 300\r\n```" }, { "author": "antoniofrighetto", "body": "> I just full unrolled the loop :)\r\n\r\nDefinitely makes sense, thanks!" }, { "author": "nikic", "body": "Reduced test case:\r\n```llvm\r\ndefine void @src(i32 %x) {\r\n %x.trunc = trunc i32 %x to i16\r\n %div = udiv i16 11, %x.trunc\r\n %cmp = icmp ult i32 %x, 256\r\n br i1 %cmp, label %loop, label %exit\r\n\r\nloop:\r\n %trunc = trunc i16 %div to i8\r\n call void @use(i8 %trunc)\r\n br label %loop\r\n\r\nexit:\r\n ret void\r\n}\r\n\r\ndeclare void @use(i8)\r\n```\r\n\r\nThe issue is that canEvaluateTruncated() preserves context instruction across non-speculatable operations." } ] }
true
null
120433
https://github.com/llvm/llvm-project/issues/120433
crash
ac8a9f8fffb605514056f53f12f1fba94ee933e9
2024-12-18T15:02:42
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e7a4d78ad328d02bf515b2fa4af8b2c188a6a636", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 21148, 21155 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "SLPVectorizerPass::vectorizeCmpInsts" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit e7a4d78ad328d02bf515b2fa4af8b2c188a6a636 Author: DianQK <[email protected]> Date: Thu Dec 19 06:21:57 2024 +0800 [SLP] Check if instructions exist after vectorization (#120434) Fixes #120433. diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d967813075bb..88049897b29a 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -21148,8 +21148,11 @@ bool SLPVectorizerPass::vectorizeCmpInsts(iterator_range<ItT> CmpInsts, if (R.isDeleted(I)) continue; for (Value *Op : I->operands()) - if (auto *RootOp = dyn_cast<Instruction>(Op)) + if (auto *RootOp = dyn_cast<Instruction>(Op)) { Changed |= vectorizeRootInstruction(nullptr, RootOp, BB, R); + if (R.isDeleted(I)) + break; + } } // Try to vectorize operands as vector bundles. for (CmpInst *I : CmpInsts) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll", "commands": [ "opt -S -passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "foo", "test_body": "define void @foo() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %i = phi i32 [ %i26, %bb3 ], [ 0, %bb ]\n %i2 = phi i32 [ %i24, %bb3 ], [ 0, %bb ]\n br label %bb3\n\nbb3: ; preds = %bb1\n %i4 = zext i32 %i2 to i64\n %i5 = mul i64 %i4, 0\n %i10 = or i64 0, %i5\n %i11 = trunc i64 %i10 to i32\n %i12 = and i32 %i11, 0\n %i13 = zext i32 %i to i64\n %i14 = mul i64 %i13, 0\n %i19 = or i64 0, %i14\n %i20 = trunc i64 %i19 to i32\n %i21 = and i32 %i20, 0\n %i22 = or i32 %i12, %i21\n %i23 = icmp ult i32 %i22, 0\n %i24 = select i1 %i23, i32 0, i32 0\n %i25 = icmp ult i32 0, 0\n %i26 = select i1 %i25, i32 0, i32 0\n br label %bb1\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP] Assertion `detail::isPresent(Val) && \"dyn_cast on a non-existent value\"' failed.", "body": "This IR crashes on SLP: https://llvm.godbolt.org/z/8oar4o4d1\n\n```llvm\ndefine void @foo() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %i = phi i32 [ %i26, %bb3 ], [ 0, %bb ]\n %i2 = phi i32 [ %i24, %bb3 ], [ 0, %bb ]\n br label %bb3\n\nbb3: ; preds = %bb1\n %i4 = zext i32 %i2 to i64\n %i5 = mul i64 %i4, 0\n %i10 = or i64 0, %i5\n %i11 = trunc i64 %i10 to i32\n %i12 = and i32 %i11, 0\n %i13 = zext i32 %i to i64\n %i14 = mul i64 %i13, 0\n %i19 = or i64 0, %i14\n %i20 = trunc i64 %i19 to i32\n %i21 = and i32 %i20, 0\n %i22 = or i32 %i12, %i21\n %i23 = icmp ult i32 %i22, 0\n %i24 = select i1 %i23, i32 0, i32 0\n %i25 = icmp ult i32 0, 0\n %i26 = select i1 %i25, i32 0, i32 0\n br label %bb1\n}\n```", "author": "DianQK", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
121897
https://github.com/llvm/llvm-project/issues/121897
crash
3b19e787fc5da27dfcc9ac6552b06a763f12ea03
2025-01-07T08:06:43
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "0eaa69eb234798774a08743b64a9aa0cf71c5356", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": [ [ 49, 55 ] ], "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": [ "isUniformAfterVectorization" ], "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 0eaa69eb234798774a08743b64a9aa0cf71c5356 Author: Florian Hahn <[email protected]> Date: Tue Jan 7 21:26:40 2025 +0000 [VPlan] Handle VPExpandSCEVRecipe in isUniformAfterVectorization. VPExpandSCEVRecipes must be placed in the entry and are alway uniform. This fixes a crash by always identifying them as uniform, even if the main vector loop region has been removed. Fixes https://github.com/llvm/llvm-project/issues/121897. diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h index 965777002052..777944264f45 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h +++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h @@ -49,7 +49,8 @@ inline bool isUniformAfterVectorization(const VPValue *VPV) { return all_of(GEP->operands(), isUniformAfterVectorization); if (auto *VPI = dyn_cast<VPInstruction>(Def)) return VPI->isSingleScalar() || VPI->isVectorToScalar(); - return false; + // VPExpandSCEVRecipes must be placed in the entry and are alway uniform. + return isa<VPExpandSCEVRecipe>(Def); } /// Return true if \p V is a header mask in \p Plan.
[ { "file": "llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll", "commands": [ "opt -passes='loop-vectorize,verify<loops>' -force-vector-width=8 -force-vector-interleave=1 -S %s", "opt -passes='loop-vectorize,verify<loops>' -force-vector-width=8 -force-vector-interleave=2 -S %s", "opt -passes='loop-vectorize,verify<loops>' -force-vector-width=16 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "scev_expand_step", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine void @scev_expand_step(i64 %x, ptr %dst) {\nentry:\n %c = icmp eq i64 %x, 65536\n call void @llvm.assume(i1 %c)\n %fr = freeze i64 %x\n %step = add i64 %fr, -65534\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, %step\n %gep.dst = getelementptr i8, ptr %dst, i64 %iv.next\n store i8 0, ptr %gep.dst, align 1\n %ec = icmp slt i64 %iv.next, 16\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "remove_loop_region_outer_loop", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndeclare i1 @cond()\n\ndefine void @remove_loop_region_outer_loop(i64 range(i64 8, 17) %N, ptr noalias %src, ptr %dst) {\nentry:\n br label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi ptr [ %src, %entry ], [ %outer.iv.next, %outer.latch ]\n br label %inner\n\ninner: ; preds = %inner, %outer.header\n %inner.iv = phi i64 [ 0, %outer.header ], [ %iv.next, %inner ]\n %gep.src = getelementptr i8, ptr %outer.iv, i64 %inner.iv\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %inner.iv\n store i8 %l, ptr %gep.dst, align 1\n %iv.next = add i64 %inner.iv, 1\n %c.1 = icmp eq i64 %iv.next, %N\n br i1 %c.1, label %outer.latch, label %inner\n\nouter.latch: ; preds = %inner\n %outer.iv.next = getelementptr i8, ptr %outer.iv, i64 1\n %c.2 = call i1 @cond()\n br i1 %c.2, label %outer.header, label %exit\n\nexit: ; preds = %outer.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "remove_loop_region_with_replicate_recipe", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndefine void @remove_loop_region_with_replicate_recipe(ptr %dst, i64 range(i64 5, 10) %N) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 2, %entry ], [ %iv.next, %loop ]\n %gep.dst = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep.dst, align 2\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_tc_less_than_16", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_tc_less_than_16(ptr %A, i64 %N) {\nentry:\n %and = and i64 %N, 15\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %and, %entry ], [ %iv.next, %loop ]\n %p.src = phi ptr [ %A, %entry ], [ %p.src.next, %loop ]\n %p.src.next = getelementptr inbounds i8, ptr %p.src, i64 1\n %l = load i8, ptr %p.src, align 1\n %add = add nsw i8 %l, 10\n store i8 %add, ptr %p.src, align 1\n %iv.next = add nsw i64 %iv, -1\n %cmp = icmp eq i64 %iv.next, 0\n br i1 %cmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Crash at -O3: Assertion `hasVectorValue(Def)' failed.", "body": "This code crashes at `-O3`:\n\n```c\nint *a;\nint b, d;\nstatic int f = 65535;\nchar c[];\nint h(int i) {\n int g = 1;\n for (; b;)\n if (a[0]) {\n g = 0;\n break;\n }\n if (g)\n a;\n else if (i)\n return 1;\n return 0;\n}\nvoid k() {\n int *e[10] = {&f};\n for (;;) {\n d = 0;\n for (; d < 8; d = f - 65535 + d + 1) {\n int j = h(f);\n c[j + f - 65534 + d] = 0;\n }\n }\n}\nvoid main() {}\n```\n\nCompiler Explorer: https://godbolt.org/z/rcGqsE196 \n\nBisected to https://github.com/llvm/llvm-project/commit/f48884ded884d982a7fd13394b0e93e6588f4143, which was comitted by @fhahn \n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:236: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, const llvm::VPLane&): Assertion `hasVectorValue(Def)' failed.\n```\n\nBacktrace:\n\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"k\"\n #0 0x0000000003c71738 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c71738)\n #1 0x0000000003c6f444 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c6f444)\n #2 0x0000000003bbc988 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x000077fbea242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x000077fbea2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x000077fbea242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x000077fbea2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x000077fbea22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x000077fbea239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00000000058fd2be llvm::VPTransformState::get(llvm::VPValue*, llvm::VPLane const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58fd2be)\n#10 0x0000000005790d0d llvm::InnerLoopVectorizer::scalarizeInstruction(llvm::Instruction const*, llvm::VPReplicateRecipe*, llvm::VPLane const&, llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5790d0d)\n#11 0x00000000057916d0 llvm::VPReplicateRecipe::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57916d0)\n#12 0x00000000058e3ce7 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58e3ce7)\n#13 0x00000000058ef282 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58ef282)\n#14 0x00000000058f0ef1 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58f0ef1)\n#15 0x00000000058fddb1 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58fddb1)\n#16 0x00000000057be1eb llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57be1eb)\n#17 0x00000000057d24c3 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57d24c3)\n#18 0x00000000057d3e19 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57d3e19)\n#19 0x00000000057d4453 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57d4453)\n#20 0x00000000052f765e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52f765e)\n#21 0x000000000361c6e0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x361c6e0)\n#22 0x00000000011305ce 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/clang+0x11305ce)\n#23 0x000000000361affb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x361affb)\n#24 0x000000000112fc5e 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/clang+0x112fc5e)\n#25 0x000000000361aa00 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x361aa00)\n#26 0x0000000003f247bf (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#27 0x0000000003f28335 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f28335)\n#28 0x000000000460209e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x460209e)\n#29 0x000000000660f9cc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x660f9cc)\n#30 0x0000000004602478 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4602478)\n#31 0x00000000048be799 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48be799)\n#32 0x0000000004840e2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4840e2e)\n#33 0x00000000049abb8e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49abb8e)\n#34 0x0000000000ce93ef cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce93ef)\n#35 0x0000000000ce0e8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#36 0x0000000004647ae9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#37 0x0000000003bbce34 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bbce34)\n#38 0x00000000046480df clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#39 0x000000000460c1ed clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x460c1ed)\n#40 0x000000000460d26e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x460d26e)\n#41 0x0000000004614d95 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4614d95)\n#42 0x0000000000ce6233 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce6233)\n#43 0x0000000000bb2524 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbb2524)\n#44 0x000077fbea229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#45 0x000077fbea229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#46 0x0000000000ce0935 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce0935)\n```", "author": "cardigan1008", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "fhahn", "body": "Reduced repro:\n\n```\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @k() {\nentry:\n %.fr = freeze i32 65535\n %invariant.op = add i32 %.fr, -65534\n br label %for.cond.us\n\nfor.cond.us: ; preds = %for.body.us.us, %entry\n br label %for.body.us.us\n\nfor.body.us.us: ; preds = %for.body.us.us, %for.cond.us\n %storemerge7.us.us = phi i32 [ 0, %for.cond.us ], [ %sub.reass.us.us, %for.body.us.us ]\n %sub.reass.us.us = add i32 %storemerge7.us.us, %invariant.op\n %idxprom.us.us = sext i32 %sub.reass.us.us to i64\n %arrayidx.us.us = getelementptr [0 x i8], ptr null, i64 0, i64 %idxprom.us.us\n store i8 0, ptr %arrayidx.us.us, align 1\n %cmp.us.us = icmp slt i32 %sub.reass.us.us, 8\n br i1 %cmp.us.us, label %for.body.us.us, label %for.cond.us\n}\n```" } ] }
true
null
142286
https://github.com/llvm/llvm-project/issues/142286
miscompilation
b9fa1dfd38ee75640402fdd0ca3640a51b95a8a3
2025-05-31T20:42:03
[ "llvm/test/Transforms/CorrelatedValuePropagation" ]
{ "fix_commit": "0f7cc4132b62e0ecdbd3193e954b745c5f492e90", "components": [ "CorrelatedValuePropagation" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": [ [ 370, 384 ], [ 395, 401 ], [ 410, 436 ] ], "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": [ "processSwitch" ], "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 0f7cc4132b62e0ecdbd3193e954b745c5f492e90 Author: Yingwei Zheng <[email protected]> Date: Mon Jun 2 17:42:02 2025 +0800 [CVP] Keep `ReachableCaseCount` in sync with range of condition (#142302) https://github.com/llvm/llvm-project/pull/79993 assumes that a reachable case must be contained by `CR`. However, it doesn't hold for some edge cases. This patch adds additional checks to ensure `ReachableCaseCount` is correct. Note: Similar optimization in SCCP isn't affected by this bug because it uses `CR` to compute `ReachableCaseCount`. Closes https://github.com/llvm/llvm-project/issues/142286. diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index 5226aeb66f65..b95a851c99b4 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -370,15 +370,30 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI, { // Scope for SwitchInstProfUpdateWrapper. It must not live during // ConstantFoldTerminator() as the underlying SwitchInst can be changed. SwitchInstProfUpdateWrapper SI(*I); + ConstantRange CR = + LVI->getConstantRangeAtUse(I->getOperandUse(0), /*UndefAllowed=*/false); unsigned ReachableCaseCount = 0; for (auto CI = SI->case_begin(), CE = SI->case_end(); CI != CE;) { ConstantInt *Case = CI->getCaseValue(); - auto *Res = dyn_cast_or_null<ConstantInt>( - LVI->getPredicateAt(CmpInst::ICMP_EQ, Cond, Case, I, - /* UseBlockValue */ true)); + std::optional<bool> Predicate = std::nullopt; + if (!CR.contains(Case->getValue())) + Predicate = false; + else if (CR.isSingleElement() && + *CR.getSingleElement() == Case->getValue()) + Predicate = true; + if (!Predicate) { + // Handle missing cases, e.g., the range has a hole. + auto *Res = dyn_cast_or_null<ConstantInt>( + LVI->getPredicateAt(CmpInst::ICMP_EQ, Cond, Case, I, + /* UseBlockValue=*/true)); + if (Res && Res->isZero()) + Predicate = false; + else if (Res && Res->isOne()) + Predicate = true; + } - if (Res && Res->isZero()) { + if (Predicate && !*Predicate) { // This case never fires - remove it. BasicBlock *Succ = CI->getCaseSuccessor(); Succ->removePredecessor(BB); @@ -395,7 +410,7 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI, DTU.applyUpdatesPermissive({{DominatorTree::Delete, BB, Succ}}); continue; } - if (Res && Res->isOne()) { + if (Predicate && *Predicate) { // This case always fires. Arrange for the switch to be turned into an // unconditional branch by replacing the switch condition with the case // value. @@ -410,27 +425,24 @@ static bool processSwitch(SwitchInst *I, LazyValueInfo *LVI, ++ReachableCaseCount; } - if (ReachableCaseCount > 1 && !SI->defaultDestUnreachable()) { + // The default dest is unreachable if all cases are covered. + if (!SI->defaultDestUnreachable() && + !CR.isSizeLargerThan(ReachableCaseCount)) { BasicBlock *DefaultDest = SI->getDefaultDest(); - ConstantRange CR = LVI->getConstantRangeAtUse(I->getOperandUse(0), - /*UndefAllowed*/ false); - // The default dest is unreachable if all cases are covered. - if (!CR.isSizeLargerThan(ReachableCaseCount)) { - BasicBlock *NewUnreachableBB = - BasicBlock::Create(BB->getContext(), "default.unreachable", - BB->getParent(), DefaultDest); - new UnreachableInst(BB->getContext(), NewUnreachableBB); + BasicBlock *NewUnreachableBB = + BasicBlock::Create(BB->getContext(), "default.unreachable", + BB->getParent(), DefaultDest); + new UnreachableInst(BB->getContext(), NewUnreachableBB); - DefaultDest->removePredecessor(BB); - SI->setDefaultDest(NewUnreachableBB); + DefaultDest->removePredecessor(BB); + SI->setDefaultDest(NewUnreachableBB); - if (SuccessorsCount[DefaultDest] == 1) - DTU.applyUpdates({{DominatorTree::Delete, BB, DefaultDest}}); - DTU.applyUpdates({{DominatorTree::Insert, BB, NewUnreachableBB}}); + if (SuccessorsCount[DefaultDest] == 1) + DTU.applyUpdates({{DominatorTree::Delete, BB, DefaultDest}}); + DTU.applyUpdates({{DominatorTree::Insert, BB, NewUnreachableBB}}); - ++NumDeadCases; - Changed = true; - } + ++NumDeadCases; + Changed = true; } }
[ { "file": "llvm/test/Transforms/CorrelatedValuePropagation/switch.ll", "commands": [ "opt < %s -passes=correlated-propagation -S" ], "tests": [ { "test_name": "pr142286", "test_body": "define void @pr142286() {\nstart:\n br label %loop\n\nloop: ; preds = %loop3, %start\n %phi = phi i8 [ -1, %start ], [ 0, %loop3 ]\n br label %loop2\n\nloop2: ; preds = %loop3, %loop\n br label %loop3\n\nloop3: ; preds = %loop3, %loop2\n switch i8 %phi, label %exit [\n i8 0, label %loop3\n i8 1, label %loop2\n i8 2, label %loop\n ]\n\nexit: ; preds = %loop3\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "CorrelatedValuePropagation miscompilation", "body": "Like https://github.com/llvm/llvm-project/issues/139866 this is from a fuzzer that generates Rust MIR: https://github.com/cbeuw/rustlantis.\n\nThe Rust MIR reproducer is: https://godbolt.org/z/sb568G8r4\n\nWith this command line, the program runs:\n```\nrustc 9870897538617236803.rs -Copt-level=2 -Cllvm-args=-opt-bisect-limit=478\n```\nAny greater value of opt-bisect-limit runs CorrelatedValuePropagation on `main` and produces a program that just executes a `ud2`.", "author": "saethlin", "labels": [ "miscompilation", "release:cherry-pick-failed", "generated by fuzzer" ], "comments": [ { "author": "nikic", "body": "https://llvm.godbolt.org/z/s1sYaWbc3\n```llvm\n; RUN: opt -S -passes=correlated-propagation < %s\ndefine void @test() {\nstart:\n br label %loop\n\nloop:\n %phi = phi i8 [ -69, %start ], [ 0, %loop3 ]\n br label %loop2\n\nloop2:\n br label %loop3\n\nloop3:\n switch i8 %phi, label %exit [\n i8 0, label %loop3\n i8 1, label %loop2\n i8 2, label %loop\n ]\n\nexit:\n call void @foo()\n ret void\n}\n\ndeclare void @foo()\n```" } ] }
true
null
112467
https://github.com/llvm/llvm-project/issues/112467
miscompilation
9df8d8d05c2650b51bd4233e1759206d163f3133
2024-10-16T03:31:20
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ [ 3369, 3376 ] ], "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ "InstCombinerImpl::foldAndOrOfICmps" ], "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a Author: Yingwei Zheng <[email protected]> Date: Wed Oct 16 16:24:44 2024 +0800 [InstCombine] Drop `samesign` flag in `foldAndOrOfICmpsWithConstEq` (#112489) In https://github.com/llvm/llvm-project/commit/5dbfca30c1a672cd0c5089df2b4fdd171436643a we assume that RHS is poison implies LHS is also poison. It doesn't hold after introducing samesign flag. This patch drops the `samesign` flag on RHS if the original expression is a logical and/or. Closes #112467. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 64bee4ab974e..c8407e8ba5ab 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -3369,8 +3369,14 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, // We can convert this case to bitwise and, because both operands are used // on the LHS, and as such poison from both will propagate. if (Value *V = foldAndOrOfICmpsWithConstEq(RHS, LHS, IsAnd, - /*IsLogical*/ false, Builder, Q)) + /*IsLogical=*/false, Builder, Q)) { + // If RHS is still used, we should drop samesign flag. + if (IsLogical && RHS->hasSameSign() && !RHS->use_empty()) { + RHS->setSameSign(false); + addToWorklist(RHS); + } return V; + } if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder, *this)) return V;
[ { "file": "llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "sge_and_max_commute", "test_body": "define i1 @sge_and_max_commute(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp eq i8 %x, 127\n %r = and i1 %cmpeq, %cmp\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sge_and_max_logical", "test_body": "define i1 @sge_and_max_logical(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp eq i8 %x, 127\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sge_and_max_logical_samesign", "test_body": "define i1 @sge_and_max_logical_samesign(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp samesign eq i8 %x, 127\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "sgt_and_min_logical_samesign", "test_body": "define i1 @sgt_and_min_logical_samesign(ptr %x, ptr %y) {\n %cmp = icmp sgt ptr %x, %y\n %cmpeq = icmp samesign eq ptr %x, null\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sgt_and_min_logical", "test_body": "define i1 @sgt_and_min_logical(ptr %x, ptr %y) {\n %cmp = icmp sgt ptr %x, %y\n %cmpeq = icmp eq ptr %x, null\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sle_or_not_min", "test_body": "define i1 @sle_or_not_min(ptr %x, ptr %y) {\n %cmp = icmp sle ptr %x, %y\n %cmpeq = icmp ne ptr %x, null\n %r = or i1 %cmp, %cmpeq\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped in `foldAndOrOfICmpsWithConstEq`", "body": "Reproducer:\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i1 @src(i8 %x, i8 %y) {\r\n %cmp = icmp sgt i8 %x, %y\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %r = select i1 %cmp, i1 true, i1 %cmpeq\r\n ret i1 %r\r\n}\r\n```\r\n```\r\ndefine i1 @tgt(i8 %x, i8 %y) {\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %1 = icmp slt i8 %y, 0\r\n %r = or i1 %cmpeq, %1\r\n ret i1 %r\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i1 @src(i8 %x, i8 %y) {\r\n#0:\r\n %cmp = icmp sgt i8 %x, %y\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %r = select i1 %cmp, i1 1, i1 %cmpeq\r\n ret i1 %r\r\n}\r\n=>\r\ndefine i1 @tgt(i8 %x, i8 %y) {\r\n#0:\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %#1 = icmp slt i8 %y, 0\r\n %r = or i1 %cmpeq, %#1\r\n ret i1 %r\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni8 %x = #x81 (129, -127)\r\ni8 %y = #x80 (128, -128)\r\n\r\nSource:\r\ni1 %cmp = #x1 (1)\r\ni1 %cmpeq = poison\r\ni1 %r = #x1 (1)\r\n\r\nTarget:\r\ni1 %cmpeq = poison\r\ni1 %#1 = #x1 (1)\r\ni1 %r = poison\r\nSource value: #x1 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
124267
https://github.com/llvm/llvm-project/issues/124267
miscompilation
9cf52fe1f94fdcd8e27c76f7d33a80eeb2075833
2025-01-24T13:05:38
[ "llvm/test/Analysis/ValueTracking" ]
{ "fix_commit": "c546b5317c518987a5f45dd4c4d25321a955c758", "components": [ "ValueTracking" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/include/llvm/IR/Instruction.h": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 9494, 9500 ], [ 9504, 9510 ] ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ "isImpliedCondICmps" ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit c546b5317c518987a5f45dd4c4d25321a955c758 Author: DianQK <[email protected]> Date: Fri Jan 24 23:02:50 2025 +0800 [ValueTracking] Pass changed predicate `SignedLPred` to `isImpliedByMatchingCmp` (#124271) Fixes #124267. Since we are using the new predicate, we should also update the parameters of `isImpliedByMatchingCmp`. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 264fedd6b66b..eba728c7c8c3 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -9494,7 +9494,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0, SignedLPred == ICmpInst::ICMP_SGE) && match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) { if (match(R1, m_NonPositive()) && - ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == false) + ICmpInst::isImpliedByMatchingCmp(SignedLPred, RPred) == false) return false; } @@ -9504,7 +9504,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0, SignedLPred == ICmpInst::ICMP_SLE) && match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) { if (match(R1, m_NonNegative()) && - ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == true) + ICmpInst::isImpliedByMatchingCmp(SignedLPred, RPred) == true) return true; }
[ { "file": "llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll", "commands": [ "opt -passes=instsimplify -S %s" ], "tests": [ { "test_name": "gt_sub_nsw_ult", "test_body": "define i1 @gt_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {\n %LHS = icmp samesign ugt i8 %L0, %L1\n br i1 %LHS, label %LHS_true, label %LHS_false\n\nLHS_true: ; preds = %0\n %R0 = sub nsw i8 %L0, %L1\n %RHS = icmp ult i8 %R0, -1\n ret i1 %RHS\n\nLHS_false: ; preds = %0\n ret i1 %V\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "lt_sub_nsw_ult", "test_body": "define i1 @lt_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {\n %LHS = icmp samesign ult i8 %L0, %L1\n br i1 %LHS, label %LHS_true, label %LHS_false\n\nLHS_true: ; preds = %0\n %R0 = sub nsw i8 %L0, %L1\n %RHS = icmp ult i8 %R0, 1\n ret i1 %RHS\n\nLHS_false: ; preds = %0\n ret i1 %V\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[ValueTracking] miscompile in samesign compare", "body": "#122590 and #122700 miscompile the following code:\n\n```llvm\ndefine i1 @src(i8 %L0, i8 %L1, i1 %V) {\n %LHS = icmp samesign ugt i8 %L0, %L1\n %R0 = sub nsw i8 %L0, %L1\n %RHS = icmp ult i8 %R0, -1\n br i1 %LHS, label %LHS_true, label %LHS_false\n\nLHS_true:\n br label %EXIT\n\nLHS_false:\n br label %EXIT\n\nEXIT:\n %RET = phi i1 [ %RHS, %LHS_true ], [ %V, %LHS_false ]\n ret i1 %RET\n}\n```\n\n`%RHS` should be 1: https://alive2.llvm.org/ce/z/RscAzy.", "author": "DianQK", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [] }
true
null
115574
https://github.com/llvm/llvm-project/issues/115574
miscompilation
00bdce1c373a1c5b756f4cf694a952ef702d0294
2024-11-09T01:49:48
[ "llvm/test/Transforms/InstSimplify" ]
{ "fix_commit": "1af627b592dd15bbe58136f902ced46251fc344d", "components": [ "InstructionSimplify" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": [ [ 27, 32 ], [ 4731, 4742 ] ], "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": [ "simplifySelectWithICmpCond" ], "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1af627b592dd15bbe58136f902ced46251fc344d Author: Yingwei Zheng <[email protected]> Date: Sun Feb 2 19:04:23 2025 +0800 [InstSimplify] Add additional checks when substituting pointers (#125385) Compile-time impact: https://llvm-compile-time-tracker.com/compare.php?from=d09b521624f263b5f1296f8d4771836b97e600cb&to=e437ba2cb83bb965e13ef00727671896f03ff84f&stat=instructions:u IR diff looks acceptable. Closes https://github.com/llvm/llvm-project/issues/115574 diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 21c937530cd8..3cbc4107433e 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -27,6 +27,7 @@ #include "llvm/Analysis/CmpInstAnalysis.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/InstSimplifyFolder.h" +#include "llvm/Analysis/Loads.h" #include "llvm/Analysis/LoopAnalysisManager.h" #include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/OverflowInstAnalysis.h" @@ -4731,12 +4732,16 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, // the arms of the select. See if substituting this value into the arm and // simplifying the result yields the same value as the other arm. if (Pred == ICmpInst::ICMP_EQ) { - if (Value *V = simplifySelectWithEquivalence({{CmpLHS, CmpRHS}}, TrueVal, - FalseVal, Q, MaxRecurse)) - return V; - if (Value *V = simplifySelectWithEquivalence({{CmpRHS, CmpLHS}}, TrueVal, - FalseVal, Q, MaxRecurse)) - return V; + if (CmpLHS->getType()->isIntOrIntVectorTy() || + canReplacePointersIfEqual(CmpLHS, CmpRHS, Q.DL)) + if (Value *V = simplifySelectWithEquivalence({{CmpLHS, CmpRHS}}, TrueVal, + FalseVal, Q, MaxRecurse)) + return V; + if (CmpLHS->getType()->isIntOrIntVectorTy() || + canReplacePointersIfEqual(CmpRHS, CmpLHS, Q.DL)) + if (Value *V = simplifySelectWithEquivalence({{CmpRHS, CmpLHS}}, TrueVal, + FalseVal, Q, MaxRecurse)) + return V; Value *X; Value *Y;
[ { "file": "llvm/test/Transforms/InstSimplify/select-icmp.ll", "commands": [ "opt < %s -passes=instsimplify -S" ], "tests": [ { "test_name": "icmp_ptr_eq_replace_null", "test_body": "target datalayout = \"p:8:8:8\"\n\ndefine ptr @icmp_ptr_eq_replace_null(ptr %a) {\n %cmp = icmp eq ptr %a, null\n %sel = select i1 %cmp, ptr null, ptr %a\n ret ptr %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ptr_eq_replace_same_underlying_object", "test_body": "target datalayout = \"p:8:8:8\"\n\ndefine ptr @ptr_eq_replace_same_underlying_object(ptr %st, i64 %i, i64 %j) {\n %a = getelementptr inbounds i8, ptr %st, i64 %i\n %b = getelementptr inbounds i8, ptr %st, i64 %j\n %cmp = icmp eq ptr %a, %b\n %sel = select i1 %cmp, ptr %a, ptr %b\n ret ptr %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmp_ptr_eq_replace", "test_body": "target datalayout = \"p:8:8:8\"\n\ndefine ptr @icmp_ptr_eq_replace(ptr %a, ptr %b) {\n %cmp = icmp eq ptr %a, %b\n %sel = select i1 %cmp, ptr %a, ptr %b\n ret ptr %sel\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstSimplify] wrong folding of pointer comparison `select (icmp eq ptr ...)`", "body": "https://github.com/llvm/llvm-project/blob/c93e001ca695e905cb965b36d63f7a348d1dd809/llvm/lib/Analysis/InstructionSimplify.cpp#L148-L167\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/aux2zY\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine ptr @smin_test8.2(ptr %a, ptr %b, ptr %c) {\r\n#0:\r\n %cmp1 = icmp eq ptr %a, %b\r\n %umin1 = select i1 %cmp1, ptr %a, ptr %b\r\n %cmp2 = icmp slt ptr %b, %c\r\n %umin2 = select i1 %cmp2, ptr %b, ptr %c\r\n %cmp3 = icmp ult ptr %umin2, %a\r\n %umin3 = select i1 %cmp3, ptr %umin2, ptr %a\r\n %cmp4 = icmp slt ptr %c, %umin3\r\n %res = select i1 %cmp4, ptr %umin1, ptr %umin3\r\n ret ptr %res\r\n}\r\n=>\r\ndefine ptr @smin_test8.2(ptr %a, ptr %b, ptr %c) {\r\n#0:\r\n %cmp2 = icmp slt ptr %b, %c\r\n %umin2 = select i1 %cmp2, ptr %b, ptr %c\r\n %cmp3 = icmp ult ptr %umin2, %a\r\n %umin3 = select i1 %cmp3, ptr %umin2, ptr %a\r\n %cmp4 = icmp slt ptr %c, %umin3\r\n %res = select i1 %cmp4, ptr %b, ptr %umin3\r\n ret ptr %res\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\nptr %a = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\nptr %b = pointer(non-local, block_id=1, offset=0) / Address=#x1\r\nptr %c = pointer(non-local, block_id=0, offset=-8) / Address=#x8\r\n\r\nSource:\r\ni1 %cmp1 = #x1 (1)\r\nptr %umin1 = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\ni1 %cmp2 = #x0 (0)\r\nptr %umin2 = pointer(non-local, block_id=0, offset=-8) / Address=#x8\r\ni1 %cmp3 = #x0 (0)\r\nptr %umin3 = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\ni1 %cmp4 = #x1 (1)\r\nptr %res = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\n\r\nSOURCE MEMORY STATE\r\n===================\r\nNON-LOCAL BLOCKS:\r\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\r\nBlock 1 >\tsize: 1\talign: 1\talloc type: 0\talive: true\taddress: 1\r\nBlock 2 >\tsize: 1\talign: 1\talloc type: 0\talive: true\taddress: 2\r\nBlock 3 >\tsize: 3\talign: 1\talloc type: 0\talive: true\taddress: 8\r\n\r\nTarget:\r\ni1 %cmp2 = #x0 (0)\r\nptr %umin2 = pointer(non-local, block_id=0, offset=-8) / Address=#x8\r\ni1 %cmp3 = #x0 (0)\r\nptr %umin3 = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\ni1 %cmp4 = #x1 (1)\r\nptr %res = pointer(non-local, block_id=1, offset=0) / Address=#x1\r\nSource value: pointer(non-local, block_id=0, offset=1) / Address=#x1\r\nTarget value: pointer(non-local, block_id=1, offset=0) / Address=#x1\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [] }
true
null
113986
https://github.com/llvm/llvm-project/issues/113986
crash
0c1c37bfbed08c9d4e414a10f46cbed9a3e4c870
2024-10-29T00:38:49
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "18311093abe6481388a0d963d58438d743b47569", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": [ [ 2902, 2909 ] ], "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": [ "InstCombinerImpl::visitShuffleVectorInst" ], "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 18311093abe6481388a0d963d58438d743b47569 Author: Yingwei Zheng <[email protected]> Date: Tue Oct 29 10:39:07 2024 +0800 [InstCombine] Do not fold `shufflevector(select)` if the select condition is a vector (#113993) Since `shufflevector` is not element-wise, we cannot do fold it into select when the select condition is a vector. For shufflevector that doesn't change the length, it doesn't crash, but it is still a miscompilation: https://alive2.llvm.org/ce/z/s8saCx Fixes https://github.com/llvm/llvm-project/issues/113986. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 75e7c1c97018..454fe5a91d37 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -2902,8 +2902,12 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) { if (match(RHS, m_Constant())) { if (auto *SI = dyn_cast<SelectInst>(LHS)) { - if (Instruction *I = FoldOpIntoSelect(SVI, SI)) - return I; + // We cannot do this fold for elementwise select since ShuffleVector is + // not elementwise. + if (SI->getCondition()->getType()->isIntegerTy()) { + if (Instruction *I = FoldOpIntoSelect(SVI, SI)) + return I; + } } if (auto *PN = dyn_cast<PHINode>(LHS)) { if (Instruction *I = foldOpIntoPhi(SVI, PN))
[ { "file": "llvm/test/Transforms/InstCombine/vec_shuffle.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "foldselect0", "test_body": "define <2 x i32> @foldselect0(i1 %c) {\n %sel = select i1 %c, <2 x i32> <i32 42, i32 7>, <2 x i32> <i32 0, i32 1>\n %shuf = shufflevector <2 x i32> %sel, <2 x i32> poison, <2 x i32> <i32 1, i32 0>\n ret <2 x i32> %shuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shuf_larger_length_vec_select", "test_body": "define <4 x float> @shuf_larger_length_vec_select(<2 x i1> %cond) {\n %sel = select <2 x i1> %cond, <2 x float> zeroinitializer, <2 x float> splat (float 1.000000e+00)\n %shuf = shufflevector <2 x float> %sel, <2 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x float> %shuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shuf_same_length_vec_select", "test_body": "define <4 x i32> @shuf_same_length_vec_select(<4 x i1> %cond) {\n %sel = select <4 x i1> %cond, <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %shuf = shufflevector <4 x i32> %sel, <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32> <i32 2, i32 1, i32 3, i32 5>\n ret <4 x i32> %shuf\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Assertion `!areInvalidOperands(C, S1, S2) && \"Invalid operands for select\"' failed.", "body": "Reproducer: \r\n```\r\n; bin/opt -passes=instcombine 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-pc-linux-gnu\"\r\n\r\ndefine <32 x float> @process(<8 x i1> %0) {\r\n %3 = select <8 x i1> %0, <8 x float> zeroinitializer, <8 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>\r\n %4 = shufflevector <8 x float> %3, <8 x float> zeroinitializer, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\r\n %5 = shufflevector <16 x float> %4, <16 x float> zeroinitializer, <32 x i32> <i32 0, i32 8, i32 16, i32 24, i32 1, i32 9, i32 17, i32 25, i32 2, i32 10, i32 18, i32 26, i32 3, i32 11, i32 19, i32 27, i32 4, i32 12, i32 20, i32 28, i32 5, i32 13, i32 21, i32 29, i32 6, i32 14, i32 22, i32 30, i32 7, i32 15, i32 23, i32 31>\r\n ret <32 x float> %5\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/include/llvm/IR/Instructions.h:1614: void llvm::SelectInst::init(llvm::Value*, llvm::Value*, llvm::Value*): Assertion `!areInvalidOperands(C, S1, S2) && \"Invalid operands for select\"' 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. Program arguments: bin/opt -passes=instcombine reduced.ll\r\n1. Running pass \"function(instcombine<max-iterations=1;verify-fixpoint>)\" on module \"reduced.ll\"\r\n2. Running pass \"instcombine<max-iterations=1;verify-fixpoint>\" on function \"process\"\r\n #0 0x00007ffff7e15b02 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x215b02)\r\n #1 0x00007ffff7e129af llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x2129af)\r\n #2 0x00007ffff7e12af5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007ffff7842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007ffff78969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007ffff78969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007ffff78969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007ffff7842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007ffff78287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007ffff782871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007ffff7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00007ffff1272963 llvm::InstCombinerImpl::FoldOpIntoSelect(llvm::Instruction&, llvm::SelectInst*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x60963)\r\n#12 0x00007ffff13a09d1 llvm::InstCombinerImpl::visitShuffleVectorInst(llvm::ShuffleVectorInst&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x18e9d1)\r\n#13 0x00007ffff1275da8 llvm::InstCombinerImpl::run() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x63da8)\r\n#14 0x00007ffff1276f09 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0\r\n#15 0x00007ffff1277dfb llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x65dfb)\r\n#16 0x00007ffff30d9955 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd9955)\r\n#17 0x00007ffff01678bd llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3678bd)\r\n#18 0x00007ffff68d9e65 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd9e65)\r\n#19 0x00007ffff01659f6 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3659f6)\r\n#20 0x00007ffff68da825 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xda825)\r\n#21 0x00007ffff016657a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x36657a)\r\n#22 0x00007ffff7f95051 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) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2d051)\r\n#23 0x00007ffff7fa073f optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x3873f)\r\n#24 0x00007ffff7829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#25 0x00007ffff7829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#26 0x00007ffff7829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#27 0x0000555555555095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\nIt is caused by https://github.com/llvm/llvm-project/pull/113746. We cannot do this fold if the output and input operands don't have the exact same type. It was reported by llvm-opt-benchmark pre-commit test https://github.com/dtcxzyw/llvm-opt-benchmark/pull/1543. I am sorry I didn't notice about this. Fortunately this issue was captured by a post-commit test https://github.com/dtcxzyw/llvm-opt-benchmark/issues/1560.\r\n\r\ncc @MatzeB @RKSimon @goldsteinn \r\n\r\nI will post a fix later.\r\n\r\n\r\n", "author": "dtcxzyw", "labels": [ "llvm:instcombine", "crash-on-valid" ], "comments": [] }
true
null
97600
https://github.com/llvm/llvm-project/issues/97600
miscompilation
97a2bd8415dc6792b99ec0f091ad7570673c3f37
2024-07-03T16:13:45
[ "llvm/test/Analysis/BasicAA" ]
{ "fix_commit": "ebab105670a409e426ddcb0278578711a622b1b2", "components": [ "IR", "ValueTracking" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/include/llvm/IR/Instruction.h": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 6403, 6411 ] ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": [ [ 652, 660 ] ], "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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": [ "llvm::getUnderlyingObject" ], "llvm/lib/IR/Instruction.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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": [ "stripPointerCastsAndOffsets" ], "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit ebab105670a409e426ddcb0278578711a622b1b2 Author: Nikita Popov <[email protected]> Date: Thu Jul 4 09:43:16 2024 +0200 [IR] Don't strip through pointer to vector of pointer bitcasts When using stripPointerCasts() and getUnderlyingObject(), don't strip through a bitcast from ptr to <1 x ptr>, which is not a no-op pointer cast. Calling code is generally not prepared to handle that situation, resulting in incorrect alias analysis results for example. Fixes https://github.com/llvm/llvm-project/issues/97600. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 5476dc5d8518..258576f0cdff 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6403,9 +6403,10 @@ const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) { V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast || Operator::getOpcode(V) == Instruction::AddrSpaceCast) { - V = cast<Operator>(V)->getOperand(0); - if (!V->getType()->isPointerTy()) + Value *NewV = cast<Operator>(V)->getOperand(0); + if (!NewV->getType()->isPointerTy()) return V; + V = NewV; } else if (auto *GA = dyn_cast<GlobalAlias>(V)) { if (GA->isInterposable()) return V; diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 8522747ccf12..b2ee75811fbb 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -652,9 +652,10 @@ static const Value *stripPointerCastsAndOffsets( } V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast) { - V = cast<Operator>(V)->getOperand(0); - if (!V->getType()->isPointerTy()) + Value *NewV = cast<Operator>(V)->getOperand(0); + if (!NewV->getType()->isPointerTy()) return V; + V = NewV; } else if (StripKind != PSK_ZeroIndicesSameRepresentation && Operator::getOpcode(V) == Instruction::AddrSpaceCast) { // TODO: If we know an address space cast will not change the
[ { "file": "llvm/test/Analysis/BasicAA/ptr-vector.ll", "commands": [ "opt -S -passes=licm < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "@c = dso_local global i32 0, align 4\n@d = dso_local local_unnamed_addr global ptr @c, align 8\n\ndefine i32 @main() {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %f.exit.split, %entry\n %b.0 = phi i32 [ 0, %entry ], [ %inc6, %f.exit.split ]\n %cmp = icmp ult i32 %b.0, 2\n br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup\n\nfor.cond1.preheader: ; preds = %for.cond\n br label %for.cond1\n\nfor.cond.cleanup: ; preds = %for.cond\n %0 = load i32, ptr @c, align 4, !tbaa !13\n %retval = xor i32 %0, 7\n ret i32 %retval\n\nfor.cond1: ; preds = %for.cond1, %for.cond1.preheader\n %i.0 = phi i32 [ %inc, %for.cond1 ], [ 0, %for.cond1.preheader ]\n %cmp2 = icmp ult i32 %i.0, 2\n %inc = add nuw nsw i32 %i.0, 1\n br i1 %cmp2, label %for.cond1, label %for.body.i.preheader, !llvm.loop !17\n\nfor.body.i.preheader: ; preds = %for.cond1\n %cmp2.lcssa = phi i1 [ %cmp2, %for.cond1 ]\n %1 = xor i1 %cmp2.lcssa, true\n %2 = bitcast i1 %1 to <1 x i1>\n %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr @d, i32 8, <1 x i1> %2, <1 x ptr> poison), !tbaa !9\n %4 = bitcast <1 x ptr> %3 to ptr\n store i32 0, ptr @c, align 4, !tbaa !13\n %5 = load i32, ptr %4, align 4, !tbaa !13\n %tobool1.not.i = icmp ne i32 %5, 0\n %tobool1.not.i.fr = freeze i1 %tobool1.not.i\n br i1 %tobool1.not.i.fr, label %f.exit.split, label %for.body.i.preheader.split\n\nfor.body.i.preheader.split: ; preds = %for.body.i.preheader\n br label %for.body.i\n\nfor.body.i: ; preds = %for.body.i.preheader.split, %for.body.i\n %n.04.i = phi i8 [ %add.i, %for.body.i ], [ -66, %for.body.i.preheader.split ]\n %add.i = add nsw i8 %n.04.i, 1\n %tobool.not.i = icmp eq i8 %add.i, 0\n br i1 %tobool.not.i, label %f.exit, label %for.body.i, !llvm.loop !15\n\nf.exit: ; preds = %for.body.i\n br label %f.exit.split\n\nf.exit.split: ; preds = %for.body.i.preheader, %f.exit\n store i32 7, ptr %4, align 4, !tbaa !13\n %inc6 = add nuw nsw i32 %b.0, 1\n br label %for.cond, !llvm.loop !18\n}\n\n!9 = !{!10, !10, i64 0}\n!10 = !{!\"any pointer\", !11, i64 0}\n!11 = !{!\"omnipotent char\", !12, i64 0}\n!12 = !{!\"Simple C/C++ TBAA\"}\n!13 = !{!14, !14, i64 0}\n!14 = !{!\"int\", !11, i64 0}\n!15 = distinct !{!15, !16}\n!16 = !{!\"llvm.loop.mustprogress\"}\n!17 = distinct !{!17, !16}\n!18 = distinct !{!18, !16}", "additional_args": null, "lli_expected_out": "" } ] } ]
{ "title": "[LICM] Miscompilation caused by wrong AA result", "body": "Reproducer: https://godbolt.org/z/Y1vvbndf8\r\n```\r\n@c = dso_local global i32 0, align 4\r\n@d = dso_local local_unnamed_addr global ptr @c, align 8\r\n\r\ndefine i32 @main() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %f.exit.split, %entry\r\n %b.0 = phi i32 [ 0, %entry ], [ %inc6, %f.exit.split ]\r\n %cmp = icmp ult i32 %b.0, 2\r\n br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup\r\n\r\nfor.cond1.preheader: ; preds = %for.cond\r\n br label %for.cond1\r\n\r\nfor.cond.cleanup: ; preds = %for.cond\r\n %0 = load i32, ptr @c, align 4, !tbaa !13\r\n ret i32 %0\r\n\r\nfor.cond1: ; preds = %for.cond1, %for.cond1.preheader\r\n %i.0 = phi i32 [ %inc, %for.cond1 ], [ 0, %for.cond1.preheader ]\r\n %cmp2 = icmp ult i32 %i.0, 2\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br i1 %cmp2, label %for.cond1, label %for.body.i.preheader, !llvm.loop !17\r\n\r\nfor.body.i.preheader: ; preds = %for.cond1\r\n %cmp2.lcssa = phi i1 [ %cmp2, %for.cond1 ]\r\n %1 = xor i1 %cmp2.lcssa, true\r\n %2 = bitcast i1 %1 to <1 x i1>\r\n %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr @d, i32 8, <1 x i1> %2, <1 x ptr> poison), !tbaa !9\r\n %4 = bitcast <1 x ptr> %3 to ptr\r\n store i32 0, ptr @c, align 4, !tbaa !13\r\n %5 = load i32, ptr %4, align 4, !tbaa !13\r\n %tobool1.not.i = icmp ne i32 %5, 0\r\n %tobool1.not.i.fr = freeze i1 %tobool1.not.i\r\n br i1 %tobool1.not.i.fr, label %f.exit.split, label %for.body.i.preheader.split\r\n\r\nfor.body.i.preheader.split: ; preds = %for.body.i.preheader\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %for.body.i.preheader.split, %for.body.i\r\n %n.04.i = phi i8 [ %add.i, %for.body.i ], [ -66, %for.body.i.preheader.split ]\r\n %add.i = add nsw i8 %n.04.i, 1\r\n %tobool.not.i = icmp eq i8 %add.i, 0\r\n br i1 %tobool.not.i, label %f.exit, label %for.body.i, !llvm.loop !15\r\n\r\nf.exit: ; preds = %for.body.i\r\n br label %f.exit.split\r\n\r\nf.exit.split: ; preds = %for.body.i.preheader, %f.exit\r\n store i32 7, ptr %4, align 4, !tbaa !13\r\n %inc6 = add nuw nsw i32 %b.0, 1\r\n br label %for.cond, !llvm.loop !18\r\n}\r\n\r\n!9 = !{!10, !10, i64 0}\r\n!10 = !{!\"any pointer\", !11, i64 0}\r\n!11 = !{!\"omnipotent char\", !12, i64 0}\r\n!12 = !{!\"Simple C/C++ TBAA\"}\r\n!13 = !{!14, !14, i64 0}\r\n!14 = !{!\"int\", !11, i64 0}\r\n!15 = distinct !{!15, !16}\r\n!16 = !{!\"llvm.loop.mustprogress\"}\r\n!17 = distinct !{!17, !16}\r\n!18 = distinct !{!18, !16}\r\n```\r\nAfter LICM:\r\n```\r\nsource_filename = \"/app/example.ll\"\r\n\r\ndefine i32 @main() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %f.exit.split, %entry\r\n %0 = phi i32 [ poison, %entry ], [ 0, %f.exit.split ]\r\n %b.0 = phi i32 [ 0, %entry ], [ %inc6, %f.exit.split ]\r\n %cmp = icmp ult i32 %b.0, 2\r\n br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup\r\n\r\nfor.cond1.preheader: ; preds = %for.cond\r\n br label %for.cond1\r\n\r\nfor.cond.cleanup: ; preds = %for.cond\r\n %.lcssa = phi i32 [ %0, %for.cond ]\r\n store i32 %.lcssa, ptr @c, align 4, !tbaa !0\r\n %1 = load i32, ptr @c, align 4, !tbaa !0\r\n ret i32 %1\r\n\r\nfor.cond1: ; preds = %for.cond1, %for.cond1.preheader\r\n %i.0 = phi i32 [ %inc, %for.cond1 ], [ 0, %for.cond1.preheader ]\r\n %cmp2 = icmp ult i32 %i.0, 2\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br i1 %cmp2, label %for.cond1, label %for.body.i.preheader, !llvm.loop !4\r\n\r\nfor.body.i.preheader: ; preds = %for.cond1\r\n %cmp2.lcssa = phi i1 [ %cmp2, %for.cond1 ]\r\n %2 = xor i1 %cmp2.lcssa, true\r\n %3 = bitcast i1 %2 to <1 x i1>\r\n %4 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr @d, i32 8, <1 x i1> %3, <1 x ptr> poison), !tbaa !6\r\n %5 = bitcast <1 x ptr> %4 to ptr\r\n %6 = load i32, ptr %5, align 4, !tbaa !0\r\n %tobool1.not.i = icmp ne i32 %6, 0\r\n %tobool1.not.i.fr = freeze i1 %tobool1.not.i\r\n br i1 %tobool1.not.i.fr, label %f.exit.split, label %for.body.i.preheader.split\r\n\r\nfor.body.i.preheader.split: ; preds = %for.body.i.preheader\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %for.body.i, %for.body.i.preheader.split\r\n %n.04.i = phi i8 [ %add.i, %for.body.i ], [ -66, %for.body.i.preheader.split ]\r\n %add.i = add nsw i8 %n.04.i, 1\r\n %tobool.not.i = icmp eq i8 %add.i, 0\r\n br i1 %tobool.not.i, label %f.exit, label %for.body.i, !llvm.loop !8\r\n\r\nf.exit: ; preds = %for.body.i\r\n br label %f.exit.split\r\n\r\nf.exit.split: ; preds = %f.exit, %for.body.i.preheader\r\n store i32 7, ptr %5, align 4, !tbaa !0\r\n %inc6 = add nuw nsw i32 %b.0, 1\r\n br label %for.cond, !llvm.loop !9\r\n}\r\n\r\ndeclare <1 x ptr> @llvm.masked.load.v1p0.p0(ptr nocapture, i32 immarg, <1 x i1>, <1 x ptr>) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }\r\n\r\n!0 = !{!1, !1, i64 0}\r\n!1 = !{!\"int\", !2, i64 0}\r\n!2 = !{!\"omnipotent char\", !3, i64 0}\r\n!3 = !{!\"Simple C/C++ TBAA\"}\r\n!4 = distinct !{!4, !5}\r\n!5 = !{!\"llvm.loop.mustprogress\"}\r\n!6 = !{!7, !7, i64 0}\r\n!7 = !{!\"any pointer\", !2, i64 0}\r\n!8 = distinct !{!8, !5}\r\n!9 = distinct !{!9, !5}\r\n```\r\n```\r\n> lli test.ll\r\n> echo $?\r\n7\r\n> bin/opt -passes=licm test.ll -S -o out.ll\r\n> lli out.ll\r\n> echo $?\r\n0\r\n```\r\n`store i32 7, ptr %5, align 4, !tbaa !0` may write something to `@c`. So this transform is incorrect.\r\n\r\nRelated patch: https://github.com/llvm/llvm-project/pull/96878\r\nOriginal C code (needs x86 +cf or riscv +zicldst):\r\n```\r\n#include \"csmith.h\"\r\nuint32_t c = 0;\r\nint32_t *d = &c;\r\nvoid f(int32_t *o) {\r\n uint8_t n;\r\n for (n = 190; n; n += 1) {\r\n *o = 0;\r\n if (*d)\r\n break;\r\n }\r\n}\r\nint main() {\r\n for (int b = 0; b <= 1; b++) {\r\n uint64_t j[2];\r\n int i;\r\n for (i = 0; i < 2; i++)\r\n j[i] = 1;\r\n f(&c);\r\n safe_add_func_int32_t_s_s(0, j[1]);\r\n *d = 7;\r\n }\r\n printf(\"%d\\n\", c);\r\n return 0;\r\n}\r\n```\r\n\r\ncc @nikic @fhahn @KanRobert \r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "TBAA", "llvm:ir", "llvm:analysis" ], "comments": [ { "author": "KanRobert", "body": "Which patch supports `zicldst` for riscv? @dtcxzyw " }, { "author": "nikic", "body": "Hm, we probably have a lot of places that don't handle things like `bitcast <1 x ptr> %3 to ptr` correctly, and assume that bitcast of pointer is always a pointer to pointer cast." }, { "author": "dtcxzyw", "body": "> Which patch supports `zicldst` for riscv? @dtcxzyw\r\n\r\nWe have a prototype which is still working in progress:\r\n+ llvm support: https://github.com/llvm/llvm-project/compare/main...dtcxzyw:llvm-project:zicldst-support\r\n+ qemu support: https://github.com/qemu/qemu/compare/master...cyyself:qemu:exp_rv_zicldst\r\n" } ] }
true
null
112068
https://github.com/llvm/llvm-project/issues/112068
miscompilation
b24acc06e1d465b3e3e4e28515dd437f6a7454f2
2024-10-12T02:41:57
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a59976bea8ad76f18119a11391dc8ba3e6ba07d5", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": [ [ 505, 512 ] ], "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": [ "foldCttzCtlz" ], "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a59976bea8ad76f18119a11391dc8ba3e6ba07d5 Author: Yingwei Zheng <[email protected]> Date: Tue Nov 19 20:06:34 2024 +0800 [InstCombine] Drop noundef attributes in `foldCttzCtlz` (#116718) Closes https://github.com/llvm/llvm-project/issues/112068. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 6cff3c7af91e..42c0acd1e45e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -505,8 +505,10 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) { // If ctlz/cttz is only used as a shift amount, set is_zero_poison to true. if (II.hasOneUse() && match(Op1, m_Zero()) && - match(II.user_back(), m_Shift(m_Value(), m_Specific(&II)))) + match(II.user_back(), m_Shift(m_Value(), m_Specific(&II)))) { + II.dropUBImplyingAttrsAndMetadata(); return IC.replaceOperand(II, 1, IC.Builder.getTrue()); + } Constant *C;
[ { "file": "llvm/test/Transforms/InstCombine/shift-cttz-ctlz.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "shl_cttz_false_multiuse", "test_body": "define i32 @shl_cttz_false_multiuse(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n call void @use(i32 %cttz)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\ndeclare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shl_cttz_false_noundef", "test_body": "define i32 @shl_cttz_false_noundef(i32 %x, i32 %y) {\nentry:\n %cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ashr_cttz_false", "test_body": "define i32 @ashr_cttz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = ashr i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shl_cttz_false", "test_body": "define i32 @shl_cttz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shl_cttz_as_lhs", "test_body": "define i32 @shl_cttz_as_lhs(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = shl i32 %cttz, %x\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shl_ctlz_false", "test_body": "define i32 @shl_ctlz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.ctlz.i32(i32 %y, i1 false)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "lshr_cttz_false", "test_body": "define i32 @lshr_cttz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = lshr i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `noundef` attribute should be dropped after setting `is_zero_poison` to true", "body": "Reproducer: https://alive2.llvm.org/ce/z/7-TgAf\r\n```\r\ndefine i32 @src(i32 %x, i32 %y) {\r\nentry:\r\n %cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 false)\r\n %res = lshr i32 %x, %cttz\r\n ret i32 %res\r\n}\r\n\r\ndefine i32 @tgt(i32 %x, i32 %y) {\r\nentry:\r\n %cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 true)\r\n %res = lshr i32 %x, %cttz\r\n ret i32 %res\r\n}\r\n\r\ndefine i32 @src2(i32 %x) {\r\n %ct = call noundef i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %cmp = icmp ne i32 %x, 0\r\n %res = select i1 %cmp, i32 %ct, i32 123\r\n ret i32 %res\r\n}\r\n\r\ndefine i32 @tgt2(i32 %x) {\r\n %ct = call noundef i32 @llvm.ctlz.i32(i32 %x, i1 true)\r\n %cmp = icmp ne i32 %x, 0\r\n %res = select i1 %cmp, i32 %ct, i32 123\r\n ret i32 %res\r\n}\r\n```\r\n`noundef` attribute should be dropped. Otherwise we will convert a poison value to immediate UB.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
135182
https://github.com/llvm/llvm-project/issues/135182
miscompilation
77db154cf9383fa20685fca56633601ce0ea47fa
2025-04-10T13:51:31
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "d14acb78065bdd331019924feaaef52e5e744529", "components": [ "SimplifyIndVar" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [ [ 1743, 1748 ] ], "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [ "WidenIV::widenWithVariantUse" ], "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit d14acb78065bdd331019924feaaef52e5e744529 Author: Yingwei Zheng <[email protected]> Date: Fri Apr 11 09:03:06 2025 +0800 [IndVarSimplify] Handle the case where both operands are the same when widening IV (#135207) `WidenIV::widenWithVariantUse` assumes that exactly one of the binop operands is the IV to be widened. This miscompilation happens when it tries to sign-extend the "NonIV" operand while the IV is zero-extended. Closes https://github.com/llvm/llvm-project/issues/135182. diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 7b9c5c77cbe9..5a76bec01765 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1743,6 +1743,9 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) { // TODO: Support case for NarrowDef = NarrowUse->getOperand(1). if (NarrowUse->getOperand(0) != NarrowDef) return false; + // We cannot use a different extend kind for the same operand. + if (NarrowUse->getOperand(1) == NarrowDef) + return false; if (!SE->isKnownNegative(RHS)) return false; bool ProvedSubNUW = SE->isKnownPredicateAt(ICmpInst::ICMP_UGE, LHS,
[ { "file": "llvm/test/Transforms/IndVarSimplify/pr135182.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "pr135182", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @pr135182() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvar = phi i16 [ -12, %entry ], [ %indvar.next, %for.body ]\n %add = add i16 %indvar, %indvar\n %ext = zext i16 %add to i32\n %indvar.next = add i16 %indvar, 1\n br i1 false, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret i32 %ext\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[IndVarSimplify] Miscompilation at -O3", "body": "Reproducer: https://alive2.llvm.org/ce/z/fvxiS3\n```\n; bin/opt -passes=indvars test.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @src(ptr %p) {\nentry:\n br label %for.body21\n\nfor.body21:\n %storemerge629 = phi i8 [ -12, %entry ], [ %dec, %for.body21 ]\n %conv29 = sext i8 %storemerge629 to i16\n %conv1.i = sext i8 %storemerge629 to i16\n %add.i = add i16 %conv29, %conv1.i\n %conv55 = zext i16 %add.i to i32\n store i32 %conv55, ptr %p, align 4\n %dec = add i8 %storemerge629, 1\n br i1 false, label %for.body21, label %for.end234\n\nfor.end234:\n ret void\n}\n```\nOutput:\n```\ndefine void @tgt(ptr %p) {\n br label %for.body21\n\nfor.body21: ; preds = %for.body21, %entry\n store i32 131048, ptr %p, align 4\n br i1 false, label %for.body21, label %for.end234\n\nfor.end234: ; preds = %for.body21\n ret void\n}\n```\n`store i32 131048, ptr @g_150, align 4` should be `store i32 65512, ptr @g_150, align 4`\nllvm version: f819f46284f2a79790038e1f6649172789734ae8\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [] }
true
null
143513
https://github.com/llvm/llvm-project/issues/143513
crash
cf637b7e3554976419a0d672ad4c252137dc34f3
2025-06-10T12:05:35
[ "llvm/test/Transforms/PhaseOrdering", "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "0108a5908cab5e418c683ef9b6e1810755344b5e", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 12085, 12091 ], [ 12130, 12136 ], [ 12152, 12159 ], [ 12171, 12182 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "computeExtractCost" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 0108a5908cab5e418c683ef9b6e1810755344b5e Author: Alexey Bataev <[email protected]> Date: Tue Jun 17 07:55:52 2025 -0700 [SLP]Fix a crash on an subvector size calculation for non-power-of-2 vector Patch fixes cost estimation for the extractelements from non-power-of-2 vectors, defined as subvector extracts. In this case the subvector size might be not adjusted to a whole register size, need to get the minimum between whole vector size and the actual difference to prevent compiler crash. Fixes #143513 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d811e9d77d18..4551a365a696 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -12085,7 +12085,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { // FIXME: this must be moved to TTI for better estimation. unsigned EltsPerVector = getPartNumElems(VL.size(), NumParts); auto CheckPerRegistersShuffle = [&](MutableArrayRef<int> Mask, - SmallVectorImpl<unsigned> &Indices) + SmallVectorImpl<unsigned> &Indices, + SmallVectorImpl<unsigned> &SubVecSizes) -> std::optional<TTI::ShuffleKind> { if (NumElts <= EltsPerVector) return std::nullopt; @@ -12130,7 +12131,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { return std::min(S, I); }), EltsPerVector); - Indices.push_back(OffsetReg1 % NumElts); + unsigned Index = OffsetReg1 % NumElts; + Indices.push_back(Index); + SubVecSizes.push_back(std::min(NumElts - Index, EltsPerVector)); } Idx = I - OffsetReg1; } @@ -12152,8 +12155,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { SmallVector<int> SubMask(EltsPerVector, PoisonMaskElem); copy(MaskSlice, SubMask.begin()); SmallVector<unsigned, 2> Indices; + SmallVector<unsigned, 2> SubVecSizes; std::optional<TTI::ShuffleKind> RegShuffleKind = - CheckPerRegistersShuffle(SubMask, Indices); + CheckPerRegistersShuffle(SubMask, Indices, SubVecSizes); if (!RegShuffleKind) { if (*ShuffleKinds[Part] != TTI::SK_PermuteSingleSrc || !ShuffleVectorInst::isIdentityMask( @@ -12171,12 +12175,12 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { } const unsigned BaseVF = getFullVectorNumberOfElements( *R.TTI, VL.front()->getType(), alignTo(NumElts, EltsPerVector)); - for (unsigned Idx : Indices) { - assert((Idx + EltsPerVector) <= BaseVF && + for (const auto [Idx, SubVecSize] : zip(Indices, SubVecSizes)) { + assert((Idx + SubVecSize) <= BaseVF && "SK_ExtractSubvector index out of range"); Cost += ::getShuffleCost(TTI, TTI::SK_ExtractSubvector, getWidenedType(ScalarTy, BaseVF), {}, CostKind, - Idx, getWidenedType(ScalarTy, EltsPerVector)); + Idx, getWidenedType(ScalarTy, SubVecSize)); } // Second attempt to check, if just a permute is better estimated than // subvector extract.
[ { "file": "llvm/test/Transforms/PhaseOrdering/X86/hadd.ll", "commands": [ "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v4", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64-v4" ], "tests": [ { "test_name": "add_v16i16_0123u56789uBCDEF", "test_body": "define <16 x i16> @add_v16i16_0123u56789uBCDEF(<16 x i16> %a, <16 x i16> %b) {\n %a0 = extractelement <16 x i16> %a, i32 0\n %a1 = extractelement <16 x i16> %a, i32 1\n %a2 = extractelement <16 x i16> %a, i32 2\n %a3 = extractelement <16 x i16> %a, i32 3\n %a4 = extractelement <16 x i16> %a, i32 4\n %a5 = extractelement <16 x i16> %a, i32 5\n %a6 = extractelement <16 x i16> %a, i32 6\n %a7 = extractelement <16 x i16> %a, i32 7\n %a8 = extractelement <16 x i16> %a, i32 8\n %a9 = extractelement <16 x i16> %a, i32 9\n %aA = extractelement <16 x i16> %a, i32 10\n %aB = extractelement <16 x i16> %a, i32 11\n %aC = extractelement <16 x i16> %a, i32 12\n %aD = extractelement <16 x i16> %a, i32 13\n %aE = extractelement <16 x i16> %a, i32 14\n %aF = extractelement <16 x i16> %a, i32 15\n %a01 = add i16 %a0, %a1\n %a23 = add i16 %a2, %a3\n %a45 = add i16 %a4, %a5\n %a67 = add i16 %a6, %a7\n %a89 = add i16 %a8, %a9\n %aAB = add i16 %aA, %aB\n %aCD = add i16 %aC, %aD\n %aEF = add i16 %aE, %aF\n %b0 = extractelement <16 x i16> %b, i32 0\n %b1 = extractelement <16 x i16> %b, i32 1\n %b2 = extractelement <16 x i16> %b, i32 2\n %b3 = extractelement <16 x i16> %b, i32 3\n %b4 = extractelement <16 x i16> %b, i32 4\n %b5 = extractelement <16 x i16> %b, i32 5\n %b6 = extractelement <16 x i16> %b, i32 6\n %b7 = extractelement <16 x i16> %b, i32 7\n %b8 = extractelement <16 x i16> %b, i32 8\n %b9 = extractelement <16 x i16> %b, i32 9\n %bA = extractelement <16 x i16> %b, i32 10\n %bB = extractelement <16 x i16> %b, i32 11\n %bC = extractelement <16 x i16> %b, i32 12\n %bD = extractelement <16 x i16> %b, i32 13\n %bE = extractelement <16 x i16> %b, i32 14\n %bF = extractelement <16 x i16> %b, i32 15\n %b01 = add i16 %b0, %b1\n %b23 = add i16 %b2, %b3\n %b45 = add i16 %b4, %b5\n %b67 = add i16 %b6, %b7\n %b89 = add i16 %b8, %b9\n %bAB = add i16 %bA, %bB\n %bCD = add i16 %bC, %bD\n %bEF = add i16 %bE, %bF\n %hadd0 = insertelement <16 x i16> poison, i16 %a01, i32 0\n %hadd1 = insertelement <16 x i16> %hadd0, i16 %a23, i32 1\n %hadd2 = insertelement <16 x i16> %hadd1, i16 %a45, i32 2\n %hadd3 = insertelement <16 x i16> %hadd2, i16 %a67, i32 3\n %hadd4 = insertelement <16 x i16> %hadd3, i16 %b01, i32 4\n %hadd5 = insertelement <16 x i16> %hadd4, i16 %b23, i32 5\n %hadd6 = insertelement <16 x i16> %hadd5, i16 %b45, i32 6\n %hadd7 = insertelement <16 x i16> %hadd6, i16 %b67, i32 7\n %hadd8 = insertelement <16 x i16> %hadd7, i16 %a89, i32 8\n %hadd9 = insertelement <16 x i16> %hadd8, i16 %aAB, i32 9\n %haddA = insertelement <16 x i16> %hadd9, i16 %aCD, i32 10\n %haddB = insertelement <16 x i16> %haddA, i16 %aEF, i32 11\n %haddC = insertelement <16 x i16> %haddB, i16 %b89, i32 12\n %haddD = insertelement <16 x i16> %haddC, i16 %bAB, i32 13\n %haddE = insertelement <16 x i16> %haddD, i16 %bCD, i32 14\n %haddF = insertelement <16 x i16> %haddE, i16 %bEF, i32 15\n %result = shufflevector <16 x i16> %haddF, <16 x i16> %a, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 5, i32 6, i32 7, i32 8, i32 9, i32 poison, i32 11, i32 12, i32 13, i32 14, i32 15>\n ret <16 x i16> %result\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "add_v16i16_0123456789ABCDEF", "test_body": "define <16 x i16> @add_v16i16_0123456789ABCDEF(<16 x i16> %a, <16 x i16> %b) {\n %a0 = extractelement <16 x i16> %a, i32 0\n %a1 = extractelement <16 x i16> %a, i32 1\n %a2 = extractelement <16 x i16> %a, i32 2\n %a3 = extractelement <16 x i16> %a, i32 3\n %a4 = extractelement <16 x i16> %a, i32 4\n %a5 = extractelement <16 x i16> %a, i32 5\n %a6 = extractelement <16 x i16> %a, i32 6\n %a7 = extractelement <16 x i16> %a, i32 7\n %a8 = extractelement <16 x i16> %a, i32 8\n %a9 = extractelement <16 x i16> %a, i32 9\n %aA = extractelement <16 x i16> %a, i32 10\n %aB = extractelement <16 x i16> %a, i32 11\n %aC = extractelement <16 x i16> %a, i32 12\n %aD = extractelement <16 x i16> %a, i32 13\n %aE = extractelement <16 x i16> %a, i32 14\n %aF = extractelement <16 x i16> %a, i32 15\n %a01 = add i16 %a0, %a1\n %a23 = add i16 %a2, %a3\n %a45 = add i16 %a4, %a5\n %a67 = add i16 %a6, %a7\n %a89 = add i16 %a8, %a9\n %aAB = add i16 %aA, %aB\n %aCD = add i16 %aC, %aD\n %aEF = add i16 %aE, %aF\n %b0 = extractelement <16 x i16> %b, i32 0\n %b1 = extractelement <16 x i16> %b, i32 1\n %b2 = extractelement <16 x i16> %b, i32 2\n %b3 = extractelement <16 x i16> %b, i32 3\n %b4 = extractelement <16 x i16> %b, i32 4\n %b5 = extractelement <16 x i16> %b, i32 5\n %b6 = extractelement <16 x i16> %b, i32 6\n %b7 = extractelement <16 x i16> %b, i32 7\n %b8 = extractelement <16 x i16> %b, i32 8\n %b9 = extractelement <16 x i16> %b, i32 9\n %bA = extractelement <16 x i16> %b, i32 10\n %bB = extractelement <16 x i16> %b, i32 11\n %bC = extractelement <16 x i16> %b, i32 12\n %bD = extractelement <16 x i16> %b, i32 13\n %bE = extractelement <16 x i16> %b, i32 14\n %bF = extractelement <16 x i16> %b, i32 15\n %b01 = add i16 %b0, %b1\n %b23 = add i16 %b2, %b3\n %b45 = add i16 %b4, %b5\n %b67 = add i16 %b6, %b7\n %b89 = add i16 %b8, %b9\n %bAB = add i16 %bA, %bB\n %bCD = add i16 %bC, %bD\n %bEF = add i16 %bE, %bF\n %hadd0 = insertelement <16 x i16> poison, i16 %a01, i32 0\n %hadd1 = insertelement <16 x i16> %hadd0, i16 %a23, i32 1\n %hadd2 = insertelement <16 x i16> %hadd1, i16 %a45, i32 2\n %hadd3 = insertelement <16 x i16> %hadd2, i16 %a67, i32 3\n %hadd4 = insertelement <16 x i16> %hadd3, i16 %b01, i32 4\n %hadd5 = insertelement <16 x i16> %hadd4, i16 %b23, i32 5\n %hadd6 = insertelement <16 x i16> %hadd5, i16 %b45, i32 6\n %hadd7 = insertelement <16 x i16> %hadd6, i16 %b67, i32 7\n %hadd8 = insertelement <16 x i16> %hadd7, i16 %a89, i32 8\n %hadd9 = insertelement <16 x i16> %hadd8, i16 %aAB, i32 9\n %haddA = insertelement <16 x i16> %hadd9, i16 %aCD, i32 10\n %haddB = insertelement <16 x i16> %haddA, i16 %aEF, i32 11\n %haddC = insertelement <16 x i16> %haddB, i16 %b89, i32 12\n %haddD = insertelement <16 x i16> %haddC, i16 %bAB, i32 13\n %haddE = insertelement <16 x i16> %haddD, i16 %bCD, i32 14\n %haddF = insertelement <16 x i16> %haddE, i16 %bEF, i32 15\n %result = shufflevector <16 x i16> %haddF, <16 x i16> %a, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n ret <16 x i16> %result\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/PhaseOrdering/X86/hsub.ll", "commands": [ "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v4", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -passes=\"default<O3>\" -S -mtriple=x86_64-- -mcpu=x86-64-v4" ], "tests": [ { "test_name": "sub_v16i16_0123456789ABCDEF", "test_body": "define <16 x i16> @sub_v16i16_0123456789ABCDEF(<16 x i16> %a, <16 x i16> %b) {\n %a0 = extractelement <16 x i16> %a, i32 0\n %a1 = extractelement <16 x i16> %a, i32 1\n %a2 = extractelement <16 x i16> %a, i32 2\n %a3 = extractelement <16 x i16> %a, i32 3\n %a4 = extractelement <16 x i16> %a, i32 4\n %a5 = extractelement <16 x i16> %a, i32 5\n %a6 = extractelement <16 x i16> %a, i32 6\n %a7 = extractelement <16 x i16> %a, i32 7\n %a8 = extractelement <16 x i16> %a, i32 8\n %a9 = extractelement <16 x i16> %a, i32 9\n %aA = extractelement <16 x i16> %a, i32 10\n %aB = extractelement <16 x i16> %a, i32 11\n %aC = extractelement <16 x i16> %a, i32 12\n %aD = extractelement <16 x i16> %a, i32 13\n %aE = extractelement <16 x i16> %a, i32 14\n %aF = extractelement <16 x i16> %a, i32 15\n %a01 = sub i16 %a0, %a1\n %a23 = sub i16 %a2, %a3\n %a45 = sub i16 %a4, %a5\n %a67 = sub i16 %a6, %a7\n %a89 = sub i16 %a8, %a9\n %aAB = sub i16 %aA, %aB\n %aCD = sub i16 %aC, %aD\n %aEF = sub i16 %aE, %aF\n %b0 = extractelement <16 x i16> %b, i32 0\n %b1 = extractelement <16 x i16> %b, i32 1\n %b2 = extractelement <16 x i16> %b, i32 2\n %b3 = extractelement <16 x i16> %b, i32 3\n %b4 = extractelement <16 x i16> %b, i32 4\n %b5 = extractelement <16 x i16> %b, i32 5\n %b6 = extractelement <16 x i16> %b, i32 6\n %b7 = extractelement <16 x i16> %b, i32 7\n %b8 = extractelement <16 x i16> %b, i32 8\n %b9 = extractelement <16 x i16> %b, i32 9\n %bA = extractelement <16 x i16> %b, i32 10\n %bB = extractelement <16 x i16> %b, i32 11\n %bC = extractelement <16 x i16> %b, i32 12\n %bD = extractelement <16 x i16> %b, i32 13\n %bE = extractelement <16 x i16> %b, i32 14\n %bF = extractelement <16 x i16> %b, i32 15\n %b01 = sub i16 %b0, %b1\n %b23 = sub i16 %b2, %b3\n %b45 = sub i16 %b4, %b5\n %b67 = sub i16 %b6, %b7\n %b89 = sub i16 %b8, %b9\n %bAB = sub i16 %bA, %bB\n %bCD = sub i16 %bC, %bD\n %bEF = sub i16 %bE, %bF\n %hsub0 = insertelement <16 x i16> poison, i16 %a01, i32 0\n %hsub1 = insertelement <16 x i16> %hsub0, i16 %a23, i32 1\n %hsub2 = insertelement <16 x i16> %hsub1, i16 %a45, i32 2\n %hsub3 = insertelement <16 x i16> %hsub2, i16 %a67, i32 3\n %hsub4 = insertelement <16 x i16> %hsub3, i16 %b01, i32 4\n %hsub5 = insertelement <16 x i16> %hsub4, i16 %b23, i32 5\n %hsub6 = insertelement <16 x i16> %hsub5, i16 %b45, i32 6\n %hsub7 = insertelement <16 x i16> %hsub6, i16 %b67, i32 7\n %hsub8 = insertelement <16 x i16> %hsub7, i16 %a89, i32 8\n %hsub9 = insertelement <16 x i16> %hsub8, i16 %aAB, i32 9\n %hsubA = insertelement <16 x i16> %hsub9, i16 %aCD, i32 10\n %hsubB = insertelement <16 x i16> %hsubA, i16 %aEF, i32 11\n %hsubC = insertelement <16 x i16> %hsubB, i16 %b89, i32 12\n %hsubD = insertelement <16 x i16> %hsubC, i16 %bAB, i32 13\n %hsubE = insertelement <16 x i16> %hsubD, i16 %bCD, i32 14\n %hsubF = insertelement <16 x i16> %hsubE, i16 %bEF, i32 15\n %result = shufflevector <16 x i16> %hsubF, <16 x i16> %a, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n ret <16 x i16> %result\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sub_v16i16_0123u56789uBCDEF", "test_body": "define <16 x i16> @sub_v16i16_0123u56789uBCDEF(<16 x i16> %a, <16 x i16> %b) {\n %a0 = extractelement <16 x i16> %a, i32 0\n %a1 = extractelement <16 x i16> %a, i32 1\n %a2 = extractelement <16 x i16> %a, i32 2\n %a3 = extractelement <16 x i16> %a, i32 3\n %a4 = extractelement <16 x i16> %a, i32 4\n %a5 = extractelement <16 x i16> %a, i32 5\n %a6 = extractelement <16 x i16> %a, i32 6\n %a7 = extractelement <16 x i16> %a, i32 7\n %a8 = extractelement <16 x i16> %a, i32 8\n %a9 = extractelement <16 x i16> %a, i32 9\n %aA = extractelement <16 x i16> %a, i32 10\n %aB = extractelement <16 x i16> %a, i32 11\n %aC = extractelement <16 x i16> %a, i32 12\n %aD = extractelement <16 x i16> %a, i32 13\n %aE = extractelement <16 x i16> %a, i32 14\n %aF = extractelement <16 x i16> %a, i32 15\n %a01 = sub i16 %a0, %a1\n %a23 = sub i16 %a2, %a3\n %a45 = sub i16 %a4, %a5\n %a67 = sub i16 %a6, %a7\n %a89 = sub i16 %a8, %a9\n %aAB = sub i16 %aA, %aB\n %aCD = sub i16 %aC, %aD\n %aEF = sub i16 %aE, %aF\n %b0 = extractelement <16 x i16> %b, i32 0\n %b1 = extractelement <16 x i16> %b, i32 1\n %b2 = extractelement <16 x i16> %b, i32 2\n %b3 = extractelement <16 x i16> %b, i32 3\n %b4 = extractelement <16 x i16> %b, i32 4\n %b5 = extractelement <16 x i16> %b, i32 5\n %b6 = extractelement <16 x i16> %b, i32 6\n %b7 = extractelement <16 x i16> %b, i32 7\n %b8 = extractelement <16 x i16> %b, i32 8\n %b9 = extractelement <16 x i16> %b, i32 9\n %bA = extractelement <16 x i16> %b, i32 10\n %bB = extractelement <16 x i16> %b, i32 11\n %bC = extractelement <16 x i16> %b, i32 12\n %bD = extractelement <16 x i16> %b, i32 13\n %bE = extractelement <16 x i16> %b, i32 14\n %bF = extractelement <16 x i16> %b, i32 15\n %b01 = sub i16 %b0, %b1\n %b23 = sub i16 %b2, %b3\n %b45 = sub i16 %b4, %b5\n %b67 = sub i16 %b6, %b7\n %b89 = sub i16 %b8, %b9\n %bAB = sub i16 %bA, %bB\n %bCD = sub i16 %bC, %bD\n %bEF = sub i16 %bE, %bF\n %hsub0 = insertelement <16 x i16> poison, i16 %a01, i32 0\n %hsub1 = insertelement <16 x i16> %hsub0, i16 %a23, i32 1\n %hsub2 = insertelement <16 x i16> %hsub1, i16 %a45, i32 2\n %hsub3 = insertelement <16 x i16> %hsub2, i16 %a67, i32 3\n %hsub4 = insertelement <16 x i16> %hsub3, i16 %b01, i32 4\n %hsub5 = insertelement <16 x i16> %hsub4, i16 %b23, i32 5\n %hsub6 = insertelement <16 x i16> %hsub5, i16 %b45, i32 6\n %hsub7 = insertelement <16 x i16> %hsub6, i16 %b67, i32 7\n %hsub8 = insertelement <16 x i16> %hsub7, i16 %a89, i32 8\n %hsub9 = insertelement <16 x i16> %hsub8, i16 %aAB, i32 9\n %hsubA = insertelement <16 x i16> %hsub9, i16 %aCD, i32 10\n %hsubB = insertelement <16 x i16> %hsubA, i16 %aEF, i32 11\n %hsubC = insertelement <16 x i16> %hsubB, i16 %b89, i32 12\n %hsubD = insertelement <16 x i16> %hsubC, i16 %bAB, i32 13\n %hsubE = insertelement <16 x i16> %hsubD, i16 %bCD, i32 14\n %hsubF = insertelement <16 x i16> %hsubE, i16 %bEF, i32 15\n %result = shufflevector <16 x i16> %hsubF, <16 x i16> %a, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 5, i32 6, i32 7, i32 8, i32 9, i32 poison, i32 11, i32 12, i32 13, i32 14, i32 15>\n ret <16 x i16> %result\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/SystemZ/non-power-2-subvector-extract.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=s390x-ibm-linux -mcpu=z13 -slp-max-reg-size=256 -slp-vectorize-hor-store -slp-vectorize-non-power-of-2 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@c = external global [1 x [10 x i32]]\[email protected] = external global i32\n\ndefine void @p() {\n;\nentry:\n %arrayidx12.promoted.5.i = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 200), align 4\n %conv14.5.i = xor i32 %arrayidx12.promoted.5.i, 1\n store i32 %conv14.5.i, ptr getelementptr inbounds nuw (i8, ptr @c, i64 200), align 4\n %arrayidx12.promoted.5.i.1 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 204), align 4\n %conv14.5.i.1 = xor i32 %arrayidx12.promoted.5.i.1, 1\n store i32 %conv14.5.i.1, ptr getelementptr inbounds nuw (i8, ptr @c, i64 204), align 4\n %arrayidx12.promoted.5.i.2 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 208), align 4\n %conv14.5.i.2 = xor i32 %arrayidx12.promoted.5.i.2, 1\n store i32 %conv14.5.i.2, ptr getelementptr inbounds nuw (i8, ptr @c, i64 208), align 4\n %arrayidx12.promoted.1.i.3 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 52), align 4\n %conv14.1.i.3 = xor i32 %arrayidx12.promoted.1.i.3, 1\n store i32 %conv14.1.i.3, ptr getelementptr inbounds nuw (i8, ptr @c, i64 52), align 4\n %arrayidx12.promoted.5.i.3 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 212), align 4\n %conv14.5.i.3 = xor i32 %arrayidx12.promoted.5.i.3, 1\n store i32 %conv14.5.i.3, ptr getelementptr inbounds nuw (i8, ptr @c, i64 212), align 4\n %arrayidx12.promoted.6.i.3 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 252), align 4\n %conv14.6.i.3 = xor i32 %arrayidx12.promoted.6.i.3, 1\n %or.1.5.i.3 = or i32 %arrayidx12.promoted.1.i.3, %arrayidx12.promoted.5.i.3\n store i32 %conv14.6.i.3, ptr getelementptr inbounds nuw (i8, ptr @c, i64 252), align 4\n store i32 %or.1.5.i.3, ptr @j.0, align 4\n %arrayidx12.promoted.1.i.4 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 56), align 4\n %conv14.1.i.4 = xor i32 %arrayidx12.promoted.1.i.4, 1\n store i32 %conv14.1.i.4, ptr getelementptr inbounds nuw (i8, ptr @c, i64 56), align 4\n %arrayidx12.promoted.5.i.4 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 216), align 4\n %conv14.5.i.4 = xor i32 %arrayidx12.promoted.5.i.4, 1\n store i32 %conv14.5.i.4, ptr getelementptr inbounds nuw (i8, ptr @c, i64 216), align 4\n %arrayidx12.promoted.6.i.4 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 256), align 4\n %conv14.6.i.4 = xor i32 %arrayidx12.promoted.6.i.4, 1\n store i32 %conv14.6.i.4, ptr getelementptr inbounds nuw (i8, ptr @c, i64 256), align 4\n %arrayidx12.promoted.1.i.5 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 60), align 4\n %conv14.1.i.5 = xor i32 %arrayidx12.promoted.1.i.5, 1\n store i32 %conv14.1.i.5, ptr getelementptr inbounds nuw (i8, ptr @c, i64 60), align 4\n %arrayidx12.promoted.5.i.5 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 220), align 4\n %conv14.5.i.5 = xor i32 %arrayidx12.promoted.5.i.5, 1\n store i32 %conv14.5.i.5, ptr getelementptr inbounds nuw (i8, ptr @c, i64 220), align 4\n %arrayidx12.promoted.6.i.5 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 260), align 4\n %conv14.6.i.5 = xor i32 %arrayidx12.promoted.6.i.5, 1\n %0 = or i32 %arrayidx12.promoted.6.i.4, %arrayidx12.promoted.1.i.5\n %or.1.5.i.5 = or i32 %0, %arrayidx12.promoted.5.i.5\n %or.1.6.i.5 = or i32 %or.1.5.i.5, %arrayidx12.promoted.6.i.5\n store i32 %conv14.6.i.5, ptr getelementptr inbounds nuw (i8, ptr @c, i64 260), align 4\n store i32 %or.1.6.i.5, ptr @j.0, align 4\n %arrayidx12.promoted.1.i.6 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 64), align 4\n %conv14.1.i.6 = xor i32 %arrayidx12.promoted.1.i.6, 1\n store i32 %conv14.1.i.6, ptr getelementptr inbounds nuw (i8, ptr @c, i64 64), align 4\n %arrayidx12.promoted.5.i.6 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 224), align 4\n %conv14.5.i.6 = xor i32 %arrayidx12.promoted.5.i.6, 1\n store i32 %conv14.5.i.6, ptr getelementptr inbounds nuw (i8, ptr @c, i64 224), align 4\n %arrayidx12.promoted.6.i.6 = load i32, ptr getelementptr inbounds nuw (i8, ptr @c, i64 264), align 4\n %conv14.6.i.6 = xor i32 %arrayidx12.promoted.6.i.6, 1\n store i32 %conv14.6.i.6, ptr getelementptr inbounds nuw (i8, ptr @c, i64 264), align 4\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "SLP Vectorizer Options trigger Assertion in cost computation on `s390x`", "body": "While running experiments with `csmith`, i ran into the following example (already reduced with `cvise`):\n```C\nstatic int c[][10];\nshort d;\nlong *e;\nlong f;\nint g, k;\nchar h, i;\nstatic int j[3];\nvoid l();\nstatic int *m() {\n short *n = &d;\n d = 0;\n for (; d <= 2;)\n if (*n)\n ;\n else\n return j;\n return &g;\n}\nvoid p() { l(); }\nvoid l() {\n int *q;\n h = 0;\n for (; h <= 6; h++) {\n int **r = &q;\n *e = 4073709551615;\n *r = m();\n k = 0;\n for (; k <= 6; k++) {\n i = 2;\n for (; i <= 6; i++)\n **r |= c[k][h] ^= f;\n }\n }\n}\n```\n When compiling this with the options\n```\n -O3 \\\n -S \\\n -w \\\n -c \\\n -o a.out \\\n --target=s390x-ibm-linux \\\n -march=z13 \\\n -mllvm -slp-max-reg-size=256 \\\n -mllvm -slp-vectorize-hor-store \\\n -mllvm -slp-vectorize-non-power-of-2 \\\n -mllvm -enable-tbaa=false \\\n```\nThe assertion `(Idx + EltsPerVector) <= BaseVF && \"SK_ExtractSubvector index out of range\"` fails in `llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::computeExtractCost`. This does not seem to be an issue on X86.\n\n[repro.tar.gz](https://github.com/user-attachments/files/20672338/repro.tar.gz)", "author": "dominik-steenken", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
116809
https://github.com/llvm/llvm-project/issues/116809
crash
0a1795f781163a8e7b72fee492f87ab27d5e3995
2024-11-19T14:26:43
[ "llvm/test/Transforms/LICM" ]
{ "fix_commit": "18b02bbf441660683df7f3925946984203d49bab", "components": [ "LICM", "MemorySSAUpdater" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": [ [ 190, 196 ] ], "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ [ 1403, 1411 ] ], "llvm/lib/Transforms/Scalar/LICM.cpp": [ [ 1465, 1472 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ "MemorySSAUpdater::createMemoryAccessBefore", "MemorySSAUpdater::createMemoryAccessInBB" ], "llvm/lib/Transforms/Scalar/LICM.cpp": [ "cloneInstructionInExitBlock" ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 18b02bbf441660683df7f3925946984203d49bab Author: DianQK <[email protected]> Date: Wed Nov 20 19:52:51 2024 +0800 [LICM] allow MemoryAccess creation failure (#116813) Fixes #116809. After running some passes (SimpleLoopUnswitch, LoopInstSimplify, etc.), MemorySSA might be outdated, and the instruction `I` may have become a non-memory touching instruction. LICM has already handled this, but it does not pass `CreationMustSucceed=false` to `createDefinedAccess`. diff --git a/llvm/include/llvm/Analysis/MemorySSAUpdater.h b/llvm/include/llvm/Analysis/MemorySSAUpdater.h index d4da3ef1146d..055feceefb05 100644 --- a/llvm/include/llvm/Analysis/MemorySSAUpdater.h +++ b/llvm/include/llvm/Analysis/MemorySSAUpdater.h @@ -190,7 +190,8 @@ public: /// inaccessible and it *must* have removeMemoryAccess called on it. MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, - MemorySSA::InsertionPlace Point); + MemorySSA::InsertionPlace Point, + bool CreationMustSucceed = true); /// Create a MemoryAccess in MemorySSA before an existing MemoryAccess. /// diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index aa550f0b6a7b..f672bd0e1e13 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -1403,9 +1403,11 @@ void MemorySSAUpdater::changeToUnreachable(const Instruction *I) { MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB( Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, - MemorySSA::InsertionPlace Point) { - MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition); - MSSA->insertIntoListsForBlock(NewAccess, BB, Point); + MemorySSA::InsertionPlace Point, bool CreationMustSucceed) { + MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess( + I, Definition, /*Template=*/nullptr, CreationMustSucceed); + if (NewAccess) + MSSA->insertIntoListsForBlock(NewAccess, BB, Point); return NewAccess; } diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index fa04ced7182d..94bfe44a847a 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1465,8 +1465,11 @@ static Instruction *cloneInstructionInExitBlock( if (MSSAU.getMemorySSA()->getMemoryAccess(&I)) { // Create a new MemoryAccess and let MemorySSA set its defining access. + // After running some passes, MemorySSA might be outdated, and the + // instruction `I` may have become a non-memory touching instruction. MemoryAccess *NewMemAcc = MSSAU.createMemoryAccessInBB( - New, nullptr, New->getParent(), MemorySSA::Beginning); + New, nullptr, New->getParent(), MemorySSA::Beginning, + /*CreationMustSucceed=*/false); if (NewMemAcc) { if (auto *MemDef = dyn_cast<MemoryDef>(NewMemAcc)) MSSAU.insertDef(MemDef, /*RenameUses=*/true);
[ { "file": "llvm/test/Transforms/LICM/PR116813-memoryssa-outdated.ll", "commands": [ "opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)' -verify-memoryssa -S < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Check that running LICM after SimpleLoopUnswitch does not result in a crash.\n\ndefine i32 @foo(i1 %arg, ptr %arg1) {\n;\nstart:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %i = select i1 %arg, ptr %arg1, ptr @bar\n %i3 = call i32 %i()\n br i1 %arg, label %loop, label %ret\n\nret: ; preds = %loop\n ret i32 %i3\n}\n\ndeclare i32 @bar() nounwind willreturn memory(none)", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SimpleLoopUnswitch][LICM] Assertion `NewAccess != nullptr && \"Tried to create a memory access for a \" \"non-memory touching instruction\"'", "body": "The following IR triggers the assertion mentioned in the title:\r\n\r\n```llvm\r\n; opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)'\r\ndefine i32 @foo(i1 %arg, ptr %arg1) {\r\nbb:\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb2, %bb\r\n %i = select i1 %arg, ptr %arg1, ptr @bar\r\n %i3 = call i32 %i()\r\n br i1 %arg, label %bb2, label %bb4\r\n\r\nbb4: ; preds = %bb2\r\n ret i32 %i3\r\n}\r\n\r\ndeclare i32 @bar() nounwind willreturn memory(none)\r\n```\r\n\r\nhttps://llvm.godbolt.org/z/bj79jxo8x", "author": "DianQK", "labels": [ "crash", "llvm:analysis", "llvm:transforms" ], "comments": [] }
true
null
97475
https://github.com/llvm/llvm-project/issues/97475
miscompilation
b77e734e4e6c8f5e016ba3ac49526862e6039482
2024-07-02T20:25:03
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "3969d2c3b5f42e4a180f5205efa780b0f950d733", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 4049, 4055 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "InstCombinerImpl::visitSelectInst" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 3969d2c3b5f42e4a180f5205efa780b0f950d733 Author: Nikita Popov <[email protected]> Date: Wed Jul 3 09:47:01 2024 +0200 [InstCombine] Disable select known bits fold for vectors This is not safe if the simplification ends up looking through lane-crossing operations. For now, we don't have a good way to limit this in computeKnownBits(), so just disable vector handling entirely. Fixes https://github.com/llvm/llvm-project/issues/97475. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 736013395e8c..394dfca262e1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -4049,7 +4049,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { if (CondVal->getType() == SI.getType() && isKnownInversion(FalseVal, TrueVal)) return BinaryOperator::CreateXor(CondVal, FalseVal); - if (SelType->isIntOrIntVectorTy() && + // For vectors, this transform is only safe if the simplification does not + // look through any lane-crossing operations. For now, limit to scalars only. + if (SelType->isIntegerTy() && (!isa<Constant>(TrueVal) || !isa<Constant>(FalseVal))) { // Try to simplify select arms based on KnownBits implied by the condition. CondContext CC(CondVal);
[ { "file": "llvm/test/Transforms/InstCombine/select-binop-cmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "select_xor_icmp_vec_bad", "test_body": "define <2 x i8> @select_xor_icmp_vec_bad(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {\n %A = icmp eq <2 x i8> %x, <i8 5, i8 3>\n %B = xor <2 x i8> %x, %z\n %C = select <2 x i1> %A, <2 x i8> %B, <2 x i8> %y\n ret <2 x i8> %C\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "vec_select_no_equivalence", "test_body": "define <2 x i32> @vec_select_no_equivalence(<2 x i32> %x) {\n %x10 = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> <i32 1, i32 0>\n %cond = icmp eq <2 x i32> %x, zeroinitializer\n %s = select <2 x i1> %cond, <2 x i32> %x10, <2 x i32> %x\n ret <2 x i32> %s\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "integer vector miscompile from instcombine", "body": "I believe this is being mis-optimized:\r\n```lllvm\r\ndefine <4 x i32> @f(<4 x i32> %0) {\r\n %2 = icmp eq <4 x i32> %0, zeroinitializer\r\n %3 = shufflevector <4 x i32> %0, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 1, i32 0, i32 3>\r\n %4 = select <4 x i1> %2, <4 x i32> %3, <4 x i32> zeroinitializer\r\n ret <4 x i32> %4\r\n}\r\n```\r\nI'll just give Alive's reasoning, which is pretty easy to follow and seems correct:\r\n```\r\nregehr@ohm:~$ ~/alive2-regehr/build/alive-tv -passes=instcombine foo.ll\r\n\r\n----------------------------------------\r\ndefine <4 x i32> @f(<4 x i32> %#0) {\r\n#1:\r\n %#2 = icmp eq <4 x i32> %#0, { 0, 0, 0, 0 }\r\n %#3 = shufflevector <4 x i32> %#0, <4 x i32> { 0, 0, 0, 0 }, 1, 1, 0, 3\r\n %#4 = select <4 x i1> %#2, <4 x i32> %#3, <4 x i32> { 0, 0, 0, 0 }\r\n ret <4 x i32> %#4\r\n}\r\n=>\r\ndefine <4 x i32> @f(<4 x i32> %#0) {\r\n#1:\r\n ret <4 x i32> { 0, 0, 0, 0 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<4 x i32> %#0 = < #x00000000 (0), #x00000001 (1), #x00000000 (0), poison >\r\n\r\nSource:\r\n<4 x i1> %#2 = < #x1 (1), #x0 (0), #x1 (1), poison >\r\n<4 x i32> %#3 = < #x00000001 (1), #x00000001 (1), #x00000000 (0), poison >\r\n<4 x i32> %#4 = < #x00000001 (1), #x00000000 (0), #x00000000 (0), poison >\r\n\r\nTarget:\r\nSource value: < #x00000001 (1), #x00000000 (0), #x00000000 (0), poison >\r\nTarget value: < #x00000000 (0), #x00000000 (0), #x00000000 (0), #x00000000 (0) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\nregehr@ohm:~$ \r\n```\r\ncc @nunoplopes ", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "nikic", "body": "Probably caused by https://github.com/llvm/llvm-project/commit/77eb05683082dd3751ccfab963f5160f1852058d. Fell into the vector select trap again." } ] }
true
null
131360
https://github.com/llvm/llvm-project/issues/131360
crash
dccc0a836c20914549fa375905615db49d2f813b
2025-03-14T17:22:16
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "fbf0276b6a7a7a4508c373cf87fc349569652659", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 6665, 6670 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::reorderBottomToTop" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit fbf0276b6a7a7a4508c373cf87fc349569652659 Author: Alexey Bataev <[email protected]> Date: Fri Mar 14 14:07:01 2025 -0700 [SLP] Reorder reuses mask, if it is not empty, for subvector operands If the subvector operands has reuses mask, need to reorder the mask, not the scalars, to prevent compiler crash due to mask/scalars size mismatch. Fixes #131360 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 708dda9bd7f8..d450336cbc3c 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6665,6 +6665,8 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) { // Clear ordering of the operand. if (!OpTE.ReorderIndices.empty()) { OpTE.ReorderIndices.clear(); + } else if (!OpTE.ReuseShuffleIndices.empty()) { + reorderReuses(OpTE.ReuseShuffleIndices, Mask); } else { assert(OpTE.isGather() && "Expected only gather/buildvector node."); reorderScalars(OpTE.Scalars, Mask);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reorder-reused-subvector.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-100 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(i32 %j.6, i32 %m.4, i8 %v.5, ptr %a, i1 %tobool14.not) {\n;\nentry:\n br label %n\n\nentry.o_crit_edge:\n br label %o\n\nn:\n %i.0 = phi i32 [ 0, %entry ], [ 1, %if.end18 ]\n %j.0 = phi i32 [ 0, %entry ], [ %j.6, %if.end18 ]\n %m.0 = phi i32 [ 0, %entry ], [ %m.4, %if.end18 ]\n %l.0 = phi i8 [ 0, %entry ], [ %l.4, %if.end18 ]\n %u.0 = phi i32 [ 0, %entry ], [ %u.5, %if.end18 ]\n store i32 %j.0, ptr %a, align 4\n %cmp.not.not = icmp eq i8 %l.0, 0\n br i1 %cmp.not.not, label %o.sink.split, label %p\n\np:\n %0 = phi i32 [ %r.3, %if.end18 ], [ 0, %n ]\n %i.1 = phi i32 [ %s.3, %if.end18 ], [ 1, %n ]\n %j.1 = phi i32 [ %j.65, %if.end18 ], [ %j.0, %n ]\n %k.1 = phi i32 [ %t.3, %if.end18 ], [ %i.0, %n ]\n %m.1 = phi i32 [ %m.46, %if.end18 ], [ %m.0, %n ]\n %l.1 = phi i8 [ 1, %if.end18 ], [ 0, %n ]\n %s.1 = phi i32 [ %s.3, %if.end18 ], [ 0, %n ]\n %t.1 = phi i32 [ %t.3, %if.end18 ], [ 0, %n ]\n %u.12 = phi i32 [ %u.5, %if.end18 ], [ 0, %n ]\n %v.1 = phi i8 [ 0, %if.end18 ], [ %v.5, %n ]\n %tobool4.not = icmp eq i32 %m.1, 0\n %spec.select = select i1 %tobool4.not, i32 %j.1, i32 0\n %tobool7.not = icmp eq i32 %0, 0\n br i1 %tobool7.not, label %o.sink.split, label %q\n\no.sink.split:\n %spec.select.sink = phi i32 [ %j.0, %n ], [ %spec.select, %p ]\n %i.3.ph = phi i32 [ 0, %n ], [ %i.1, %p ]\n %k.3.ph = phi i32 [ %i.0, %n ], [ %k.1, %p ]\n %m.3.ph = phi i32 [ %m.0, %n ], [ 0, %p ]\n %l.3.ph = phi i8 [ 0, %n ], [ %l.1, %p ]\n %u.3.ph = phi i32 [ %u.0, %n ], [ 1, %p ]\n %conv10 = zext i32 %spec.select.sink to i64\n %call11 = tail call i32 (ptr, ...) @printf(ptr null, i64 %conv10)\n br label %o\n\no:\n %j.4 = phi i32 [ 0, %entry.o_crit_edge ], [ %spec.select.sink, %o.sink.split ]\n %k.3 = phi i32 [ 0, %entry.o_crit_edge ], [ %k.3.ph, %o.sink.split ]\n %m.3 = phi i32 [ 0, %entry.o_crit_edge ], [ %m.3.ph, %o.sink.split ]\n %u.3 = phi i32 [ 0, %entry.o_crit_edge ], [ %u.3.ph, %o.sink.split ]\n %sub = sub i32 0, %j.6\n %div = sdiv i32 %sub, %i.3.ph\n %sub13 = sub i32 0, %div\n br i1 %tobool14.not, label %if.end18, label %q\n\nq:\n %s.2 = phi i32 [ %s.1, %p ], [ 0, %o ]\n %t.2 = phi i32 [ %t.1, %p ], [ %k.3, %o ]\n %u.4 = phi i32 [ %u.12, %p ], [ 0, %o ]\n %v.44 = phi i8 [ %v.1, %p ], [ 0, %o ]\n %conv17 = sext i8 %v.44 to i32\n %rem = mul i32 %u.4, %conv17\n br label %if.end18\n\nif.end18:\n %j.65 = phi i32 [ 0, %q ], [ %j.4, %o ]\n %m.46 = phi i32 [ %rem, %q ], [ %m.3, %o ]\n %l.4 = phi i8 [ 0, %q ], [ %l.3.ph, %o ]\n %r.3 = phi i32 [ 0, %q ], [ %k.3, %o ]\n %s.3 = phi i32 [ %s.2, %q ], [ %sub, %o ]\n %t.3 = phi i32 [ %t.2, %q ], [ %sub13, %o ]\n %u.5 = phi i32 [ 0, %q ], [ %u.3, %o ]\n br i1 %tobool14.not, label %n, label %p\n\n}\ndeclare i32 @printf(ptr, ...)", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes at -O{s,2,3} on x86_64-linux-gnu: Assertion `idx < size()' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 20.1.0. \n\nCompiler Explorer: https://godbolt.org/z/31z58Pqnf\n\n```\n[507] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git da3ee9763266f9adedaac1b1b3162d14f951fc55)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[508] % \n[508] % clangtk -Os small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/ADT/SmallVector.h:291: T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) [with T = llvm::Value*; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = llvm::Value*&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250314-clangtk-m64-O3-build-143933/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250314-clangtk-m64-O3-build-143933/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/21 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-fb79f4.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"g\"\n #0 0x0000559c00edefcf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4577fcf)\n #1 0x0000559c00edc7a4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007f26a38b4420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007f26a32eb00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007f26a32ca859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007f26a32ca729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007f26a32ca729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007f26a32dbfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x0000559c0296f55e llvm::reorderScalars(llvm::SmallVectorImpl<llvm::Value*>&, llvm::ArrayRef<int>) SLPVectorizer.cpp:0:0\n #9 0x0000559c02a36719 llvm::slpvectorizer::BoUpSLP::reorderBottomToTop(bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60cf719)\n#10 0x0000559c02a41c60 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60dac60)\n#11 0x0000559c02a4712d bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#12 0x0000559c02a48b21 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60e1b21)\n#13 0x0000559c02a50b66 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\n#14 0x0000559c02a51733 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60ea733)\n#15 0x0000559c024c7cf6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5b60cf6)\n#16 0x0000559c0084f7c9 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee87c9)\n#17 0x0000559bfe1397a6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x17d27a6)\n#18 0x0000559c0084e032 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee7032)\n#19 0x0000559bfe1373b6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x17d03b6)\n#20 0x0000559c0084da51 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee6a51)\n#21 0x0000559c0119ce4a (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#22 0x0000559c011a08a1 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x48398a1)\n#23 0x0000559c018e0d91 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f79d91)\n#24 0x0000559c0326e6dc clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x69076dc)\n#25 0x0000559c018e11b8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f7a1b8)\n#26 0x0000559c01bb7bc9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5250bc9)\n#27 0x0000559c01b38ece clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51d1ece)\n#28 0x0000559c01cac996 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5345996)\n#29 0x0000559bfdccc9ed cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x13659ed)\n#30 0x0000559bfdcc415a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#31 0x0000559bfdcc83c7 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x13613c7)\n#32 0x0000559bfdbad0db main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x12460db)\n#33 0x00007f26a32cc083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#34 0x0000559bfdcc3bee _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x135cbee)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git da3ee9763266f9adedaac1b1b3162d14f951fc55)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-d812eb.c\nclangtk: note: diagnostic msg: /tmp/small-d812eb.sh\nclangtk: note: diagnostic msg: \n\n********************\n[509] % \n[509] % cat small.c\nint printf(const char *, ...);\nint a, b, c, d, e, f;\nvoid g() {\n int i = 1, j = 0, k = 0, m;\n char l = 1;\n if (d)\n n : {\n a = j;\n if (e >= l) {\n printf(\"%ld\", (long) j);\n goto o;\n }\n p:\n if (m)\n j = 1;\n if (b)\n goto q;\n printf(\"%ld\", (long) j);\n }\n o : ;\n int r = k, s = -f, t = -(s / i);\n if (c) {\n t = k;\n int u = a;\n char v = u;\n q:\n m = u % v;\n l = 0;\n }\n i = s;\n k = t;\n b = r;\n if (a)\n goto p;\n goto n;\n}\n```\n", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
106257
https://github.com/llvm/llvm-project/issues/106257
crash
a4989cd603b8e8185e35e3c2b7b48b422d4898be
2024-08-27T17:46:38
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "4b84288f00f3e112045bbc4be4f1539147574ead", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 8648, 8653 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "addUsersInExitBlock" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 4b84288f00f3e112045bbc4be4f1539147574ead Author: Florian Hahn <[email protected]> Date: Wed Aug 28 19:12:04 2024 +0100 [VPlan] Pass live-ins used as exit values straight to live-out. Live-ins that are used as exit values don't need to be extracted, they can be passed through directly. This fixes a crash when trying to extract from a live-in. Fixes https://github.com/llvm/llvm-project/issues/106257. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4c68a95b9c26..cb104c4ed2d0 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8648,6 +8648,11 @@ addUsersInExitBlock(VPlan &Plan, // Introduce VPUsers modeling the exit values. for (const auto &[ExitPhi, V] : ExitingValuesToFix) { + // Pass live-in values used by exit phis directly through to the live-out. + if (V->isLiveIn()) { + Plan.addLiveOut(ExitPhi, V); + continue; + } VPValue *Ext = B.createNaryOp( VPInstruction::ExtractFromEnd, {V, Plan.getOrAddLiveIn(ConstantInt::get(
[ { "file": "llvm/test/Transforms/LoopVectorize/extract-from-end-vector-constant.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "exit_value_vector_live_in", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine <2 x i64> @exit_value_vector_live_in(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.1, %loop ]\n %gep = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep, align 2\n %iv.next.1 = add i64 %iv, 1\n %ec = icmp ult i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n %res = phi <2 x i64> [ zeroinitializer, %loop ]\n ret <2 x i64> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "exit_value_scalar_live_in", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i64 @exit_value_scalar_live_in(ptr %dst, i64 %in) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.1, %loop ]\n %gep = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep, align 2\n %iv.next.1 = add i64 %iv, 1\n %ec = icmp ult i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n %res = phi i64 [ %in, %loop ]\n ret i64 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize] Assertion `(GeneratedValue->getType()->isVectorTy() == !GeneratesPerFirstLaneOnly || State.VF.isScalar()) && \"scalar value but not only first lane defined\"' failed.", "body": "Testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine fastcc void @g() #0 {\r\nfor.cond1.preheader.us.preheader:\r\n br label %for.cond.cleanup20.us.us.1\r\n\r\nfor.cond.cleanup20.us.us.1: ; preds = %for.cond.cleanup20.us.us.1, %for.cond1.preheader.us.preheader\r\n %indvars.iv.1 = phi i64 [ 0, %for.cond1.preheader.us.preheader ], [ %indvars.iv.next.1, %for.cond.cleanup20.us.us.1 ]\r\n %arrayidx.us.us.1 = getelementptr [0 x i16], ptr null, i64 0, i64 %indvars.iv.1\r\n store i16 0, ptr %arrayidx.us.us.1, align 2\r\n %indvars.iv.next.1 = add i64 %indvars.iv.1, 1\r\n %cmp12.us.us.1 = icmp ult i64 %indvars.iv.1, 1\r\n br i1 %cmp12.us.us.1, label %for.cond.cleanup20.us.us.1, label %for.cond.cleanup14.us.us.1\r\n\r\nfor.cond.cleanup14.us.us.1: ; preds = %for.cond.cleanup20.us.us.1\r\n %.lcssa.1 = phi <2 x i64> [ zeroinitializer, %for.cond.cleanup20.us.us.1 ]\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\nhttps://godbolt.org/z/aoe8vdc1f\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp:732: virtual void llvm::VPInstruction::execute(llvm::VPTransformState&): Assertion `(GeneratedValue->getType()->isVectorTy() == !GeneratesPerFirstLaneOnly || State.VF.isScalar()) && \"scalar value but not only first lane defined\"' 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. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"g\"\r\n #0 0x0000644a7eb61500 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300e500)\r\n #1 0x0000644a7eb5e91f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300b91f)\r\n #2 0x0000644a7eb5ea75 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000790e6c842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000790e6c8969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000790e6c8969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x0000790e6c8969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000790e6c842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x0000790e6c8287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x0000790e6c82871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000790e6c839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000644a7dc8e57a llvm::VPInstruction::execute(llvm::VPTransformState&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x213b57a)\r\n#12 0x0000644a7dc4f617 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fc617)\r\n#13 0x0000644a7dc4f910 llvm::VPIRBasicBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fc910)\r\n#14 0x0000644a7dc51c2d llvm::VPlan::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fec2d)\r\n#15 0x0000644a7db37af9 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe4af9)\r\n#16 0x0000644a7db4afce llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ff7fce)\r\n#17 0x0000644a7db4d101 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffa101)\r\n#18 0x0000644a7db4d777 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffa777)\r\n#19 0x0000644a7c9b0a46 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5da46)\r\n#20 0x0000644a7e96c95f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1995f)\r\n#21 0x0000644a7c9b3bd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe60bd6)\r\n#22 0x0000644a7e96b6db llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e186db)\r\n#23 0x0000644a7c9afe76 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5ce76)\r\n#24 0x0000644a7e96971d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1671d)\r\n#25 0x0000644a7c1d9e36 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) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x686e36)\r\n#26 0x0000644a7c1cbbc1 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x678bc1)\r\n#27 0x0000790e6c829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#28 0x0000790e6c829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#29 0x0000790e6c829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#30 0x0000644a7c1c1f75 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66ef75)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nFound via fuzzer", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
83127
https://github.com/llvm/llvm-project/issues/83127
hang
7a0acccd81df268dc7ad4c0358c42552789f19b4
2024-02-27T12:20:45
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "9f45c5e1a65a1abf4920b617d36ed05e73c04bea", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 1285, 1291 ], [ 1303, 1309 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "InstCombinerImpl::foldSelectValueEquivalence" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 9f45c5e1a65a1abf4920b617d36ed05e73c04bea Author: Nikita Popov <[email protected]> Date: Wed Mar 6 09:33:51 2024 +0100 [InstCombine] Fix infinite loop in select equivalence fold (#84036) When replacing with a non-constant, it's possible that the result of the simplification is actually more complicated than the original, and may result in an infinite combine loop. Mitigate the issue by requiring that either the replacement or simplification result is constant, which should ensure that it's simpler. While this check is crude, it does not appear to cause optimization regressions in real-world code in practice. Fixes https://github.com/llvm/llvm-project/issues/83127. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index c47bc33df070..aee18d770f72 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1285,7 +1285,11 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel, isGuaranteedNotToBeUndefOrPoison(CmpRHS, SQ.AC, &Sel, &DT)) { if (Value *V = simplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, SQ, /* AllowRefinement */ true)) - return replaceOperand(Sel, Swapped ? 2 : 1, V); + // Require either the replacement or the simplification result to be a + // constant to avoid infinite loops. + // FIXME: Make this check more precise. + if (isa<Constant>(CmpRHS) || isa<Constant>(V)) + return replaceOperand(Sel, Swapped ? 2 : 1, V); // Even if TrueVal does not simplify, we can directly replace a use of // CmpLHS with CmpRHS, as long as the instruction is not used anywhere @@ -1303,7 +1307,8 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel, isGuaranteedNotToBeUndefOrPoison(CmpLHS, SQ.AC, &Sel, &DT)) if (Value *V = simplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, SQ, /* AllowRefinement */ true)) - return replaceOperand(Sel, Swapped ? 2 : 1, V); + if (isa<Constant>(CmpLHS) || isa<Constant>(V)) + return replaceOperand(Sel, Swapped ? 2 : 1, V); auto *FalseInst = dyn_cast<Instruction>(FalseVal); if (!FalseInst)
[ { "file": "llvm/test/Transforms/InstCombine/select.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "select_replacement_shift_noundef", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @select_replacement_shift_noundef(i8 %x, i8 %y, i8 %z) {\n %shr = lshr exact i8 %x, 1\n call void @use_i8(i8 noundef %shr)\n %cmp = icmp eq i8 %shr, %y\n %shl = shl i8 %y, 1\n %sel = select i1 %cmp, i8 %shl, i8 %z\n ret i8 %sel\n}\n\ndeclare void @use_i8(i8)\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_replacement_loop4", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i16 @select_replacement_loop4(i16 noundef %p_12) {\n %cmp1 = icmp ult i16 %p_12, 2\n %and1 = and i16 %p_12, 1\n %and2 = select i1 %cmp1, i16 %and1, i16 0\n %cmp2 = icmp eq i16 %and2, %p_12\n %and3 = select i1 %cmp2, i16 %and1, i16 0\n ret i16 %and3\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_replacement_loop3", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @select_replacement_loop3(i32 noundef %x) {\n %trunc = trunc i32 %x to i8\n %rev = call i8 @llvm.bitreverse.i8(i8 %trunc)\n %ext = zext i8 %rev to i32\n %cmp = icmp eq i32 %ext, %x\n %sel = select i1 %cmp, i8 %trunc, i8 0\n ret i8 %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.bitreverse.i8(i8) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_replacement_sub", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @select_replacement_sub(i8 %x, i8 %y, i8 %z) {\n %cmp = icmp eq i8 %x, %y\n %sub = sub i8 %x, %y\n %sel = select i1 %cmp, i8 %sub, i8 %z\n ret i8 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_replacement_gep_inbounds", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine ptr @select_replacement_gep_inbounds(ptr %base, i64 %offset) {\n %cmp = icmp eq i64 %offset, 0\n %gep = getelementptr inbounds i8, ptr %base, i64 %offset\n %sel = select i1 %cmp, ptr %base, ptr %gep\n ret ptr %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_replacement_loop2", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i32 @select_replacement_loop2(i32 %arg, i32 %arg2) {\n %div = udiv i32 %arg, %arg2\n %mul = mul nsw i32 %div, %arg2\n %cmp = icmp eq i32 %mul, %arg\n %sel = select i1 %cmp, i32 %div, i32 undef\n ret i32 %sel\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] InstCombine gets stuck when simplifying selects", "body": "Reduced test case: https://godbolt.org/z/ds9eq96db\r\n```\r\ndefine i16 @func(i16 noundef %p_12) {\r\nentry:\r\n %cmp1 = icmp ult i16 %p_12, 2\r\n %and1 = and i16 %p_12, 1\r\n %and2 = select i1 %cmp1, i16 %and1, i16 0\r\n %cmp2 = icmp eq i16 %and2, %p_12\r\n %and3 = select i1 %cmp2, i16 %and1, i16 0\r\n ret i16 %and3\r\n}\r\n```\r\n```\r\nADD: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD DEFERRED: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %cmp2 = icmp eq i16 %and2, %p_12\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD DEFERRED: %and1 = and i16 %p_12, 1\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n\r\n\r\nADD: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD DEFERRED: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %cmp2 = icmp eq i16 %and2, %p_12\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD DEFERRED: %and1 = and i16 %p_12, 1\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n\r\n...\r\n```", "author": "dtcxzyw", "labels": [ "llvm:instcombine", "llvm:hang" ], "comments": [ { "author": "dtcxzyw", "body": "Another reproducer: https://godbolt.org/z/7MEYTe9cq\r\n```\r\ndeclare void @use(i32,i32)\r\n\r\ndefine void @func(ptr %p) {\r\n %1 = load i32, ptr %p, align 4\r\n %2 = sext i32 %1 to i64\r\n %3 = icmp slt i64 %2, 2\r\n %4 = zext i1 %3 to i32\r\n %5 = and i32 %4, %1\r\n %6 = icmp eq i32 %5, %1\r\n %7 = zext i1 %6 to i32\r\n %8 = and i32 %7, %1\r\n call void @use(i32 %8, i32 noundef %1)\r\n ret void\r\n}\r\n```\r\n" }, { "author": "dtcxzyw", "body": "Third reproducer: https://godbolt.org/z/8f8b4xved\r\n```\r\ndefine i8 @func(i32 noundef %p_38) {\r\nentry:\r\n %conv393 = trunc i32 %p_38 to i8\r\n %0 = call i8 @llvm.bitreverse.i8(i8 %conv393)\r\n %conv394 = zext i8 %0 to i32\r\n %cmp395 = icmp eq i32 %conv394, %p_38\r\n %conv397 = zext i1 %cmp395 to i8\r\n %mul.i = mul i8 %conv393, %conv397\r\n ret i8 %mul.i\r\n}\r\n```" }, { "author": "dtcxzyw", "body": "> Third reproducer: https://godbolt.org/z/8f8b4xved\r\n> \r\n> ```\r\n> define i8 @func(i32 noundef %p_38) {\r\n> entry:\r\n> %conv393 = trunc i32 %p_38 to i8\r\n> %0 = call i8 @llvm.bitreverse.i8(i8 %conv393)\r\n> %conv394 = zext i8 %0 to i32\r\n> %cmp395 = icmp eq i32 %conv394, %p_38\r\n> %conv397 = zext i1 %cmp395 to i8\r\n> %mul.i = mul i8 %conv393, %conv397\r\n> ret i8 %mul.i\r\n> }\r\n> ```\r\n\r\nA simpler testcase:\r\n```\r\ndefine i8 @func(i32 noundef %x) {\r\nentry:\r\n %trunc = trunc i32 %x to i8\r\n %rev = call i8 @llvm.bitreverse.i8(i8 %trunc)\r\n %ext = zext i8 %rev to i32\r\n %cmp = icmp eq i32 %ext, %x\r\n %sel = select i1 %cmp, i8 %trunc, i8 0\r\n ret i8 %sel\r\n}\r\n```\r\n\r\n@nikic I have no idea how to fix it in `foldSelectValueEquivalence`/`simplifyWithOpReplaced`. `simplifyWithOpReplaced` may replace the input `x` with a more complicated value `f(x)`.\r\n" }, { "author": "dtcxzyw", "body": "@nikic Ping." } ] }
true
null
113123
https://github.com/llvm/llvm-project/issues/113123
miscompilation
67ff5ba9af9754261abe11d762af11532a816126
2024-10-21T02:18:29
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a2ba438f3e5635e368333213914c7452a6a6a2da", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ [ 1531, 1538 ] ], "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ "InstCombinerImpl::foldLogicOfFCmps" ], "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a2ba438f3e5635e368333213914c7452a6a6a2da Author: XChy <[email protected]> Date: Mon Oct 21 22:30:31 2024 +0800 [InstCombine] Preserve the flag from RHS only if the `and` is bitwise (#113164) Fixes #113123 Alive proof: https://alive2.llvm.org/ce/z/hnqeLC diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index d72013ba223d..835eae9f5725 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1531,8 +1531,10 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS, } if (IsLessThanOrLessEqual(IsAnd ? PredL : PredR)) { BuilderTy::FastMathFlagGuard Guard(Builder); - Builder.setFastMathFlags(LHS->getFastMathFlags() | - RHS->getFastMathFlags()); + FastMathFlags NewFlag = LHS->getFastMathFlags(); + if (!IsLogicalSelect) + NewFlag |= RHS->getFastMathFlags(); + Builder.setFastMathFlags(NewFlag); Value *FAbs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, LHS0); return Builder.CreateFCmp(PredL, FAbs,
[ { "file": "llvm/test/Transforms/InstCombine/fcmp-range-check-idiom.ll", "commands": [ "opt -S -passes=instcombine %s" ], "tests": [ { "test_name": "test_and_olt_fmf_propagation_union_logical_rhs_poison", "test_body": "define i1 @test_and_olt_fmf_propagation_union_logical_rhs_poison(float %x) {\n %cmp1 = fcmp ninf olt float %x, 0x3C00000000000000\n %cmp2 = fcmp ogt float %x, 0xBC00000000000000\n %cond = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %cond\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_and_olt_fmf_propagation_union_logical_both_poison", "test_body": "define i1 @test_and_olt_fmf_propagation_union_logical_both_poison(float %x) {\n %cmp1 = fcmp ninf olt float %x, 0x3C00000000000000\n %cmp2 = fcmp ninf ogt float %x, 0xBC00000000000000\n %cond = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %cond\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_and_olt_fmf_propagation_union", "test_body": "define i1 @test_and_olt_fmf_propagation_union(float %x) {\n %cmp1 = fcmp nnan ninf olt float %x, 0x3C00000000000000\n %cmp2 = fcmp nnan nsz ogt float %x, 0xBC00000000000000\n %cond = and i1 %cmp1, %cmp2\n ret i1 %cond\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_and_olt_fmf_propagation_union_logical_lhs_poison", "test_body": "define i1 @test_and_olt_fmf_propagation_union_logical_lhs_poison(float %x) {\n %cmp1 = fcmp olt float %x, 0x3C00000000000000\n %cmp2 = fcmp ninf ogt float %x, 0xBC00000000000000\n %cond = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %cond\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Wrong canonicalization of a range check idiom", "body": "https://github.com/llvm/llvm-project/blob/11dad2fa5138a50d60a5a34a2c7e074b976820e2/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L1511-L1527\r\n\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/qBHAmS\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @test_and_olt_fmf_propagation_union.2(float %x) {\r\n#0:\r\n %cmp1 = fcmp nnan ninf olt float %x, 0.000000\r\n %cmp2 = fcmp nnan nsz ogt float %x, -0.000000\r\n %#1 = select i1 %cmp2, i1 %cmp1, i1 %cmp2\r\n %cond = and i1 %#1, %cmp2\r\n ret i1 %cond\r\n}\r\n=>\r\ndefine i1 @test_and_olt_fmf_propagation_union.2(float %x) {\r\n#0:\r\n %#1 = fabs nnan ninf nsz float %x\r\n %#2 = fcmp nnan ninf nsz olt float %#1, 0.000000\r\n ret i1 %#2\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\nfloat %x = #xff800000 (-oo)\r\n\r\nSource:\r\ni1 %cmp1 = poison\r\ni1 %cmp2 = #x0 (0)\r\ni1 %#1 = #x0 (0)\r\ni1 %cond = #x0 (0)\r\n\r\nTarget:\r\nfloat %#1 = poison\r\ni1 %#2 = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [ { "author": "XChy", "body": "Thanks for the report.\r\n\r\nWe preserve `ninf` flag from `cmp1` when folding logical and `select cmp2, cmp1, false` into `fcmp ninf (fabs(x))`. But if `cmp2` equals to `false`, the select won't be poison whatever `cmp1` is. Thus, such fold makes it more poisonous. See https://alive2.llvm.org/ce/z/hnqeLC" }, { "author": "XChy", "body": "And it looks like you are mutating the unit tests to fuzz LLVM. Looks interesting to me. If OK, could you provide some information about it?" }, { "author": "bongjunj", "body": "> And it looks like you are mutating the unit tests to fuzz LLVM. Looks interesting to me. If OK, could you provide some information about it?\r\n\r\n@XChy Yes we are designing a fuzzer on top of LLVM to test the compiler. We can't disclose the full detail at this time. Thank you." } ] }
true
null
142895
https://github.com/llvm/llvm-project/issues/142895
crash
d5d6f60632c6c6ef5a4342439f767e10880784e1
2025-06-05T03:42:55
[ "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "4eac8daa38990871e50b804c0cc19a3ad9c98db2", "components": [ "LoopPeel" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": [ [ 1257, 1263 ] ], "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": [ "llvm::peelLoop" ], "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 4eac8daa38990871e50b804c0cc19a3ad9c98db2 Author: Yingwei Zheng <[email protected]> Date: Fri Jun 6 12:56:28 2025 +0800 [LoopPeel] Handle non-local instructions/arguments when updating exiting values (#142993) Similar to https://github.com/llvm/llvm-project/commit/7e14161f49b32387988cf9d937bbfaa27d0fbdd5, the exiting value may be a non-local instruction or an argument. Closes https://github.com/llvm/llvm-project/issues/142895. diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index bd025fddd0cf..9149f71941db 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -1257,7 +1257,11 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, bool PeelLast, LoopInfo *LI, // Now adjust users of the original exit values by replacing them with the // exit value from the peeled iteration and remove them. for (const auto &[P, E] : ExitValues) { - P->replaceAllUsesWith(isa<Constant>(E) ? E : &*VMap.lookup(E)); + Instruction *ExitInst = dyn_cast<Instruction>(E); + if (ExitInst && L->contains(ExitInst)) + P->replaceAllUsesWith(&*VMap[ExitInst]); + else + P->replaceAllUsesWith(E); P->eraseFromParent(); } formLCSSA(*L, DT, LI, SE);
[ { "file": "llvm/test/Transforms/LoopUnroll/unroll-and-peel-last-iteration.ll", "commands": [ "opt -p loop-unroll -S %s" ], "tests": [ { "test_name": "pr142895_exit_value_is_inst", "test_body": "define i32 @pr142895_exit_value_is_inst(i32 %arg) {\nentry:\n %mul = mul i32 %arg, 7\n br label %loop\n\nloop: ; preds = %loop, %entry\n %indvar = phi i32 [ 0, %entry ], [ %inc, %loop ]\n %cmp1 = icmp eq i32 %indvar, 32\n %sel = select i1 %cmp1, i32 0, i32 0\n %sub = sub i32 0, 0\n %xor = xor i32 0, 0\n %inc = add i32 %indvar, 1\n %exitcond = icmp ne i32 %inc, 33\n br i1 %exitcond, label %loop, label %exit\n\nexit: ; preds = %loop\n %exit.lcssa = phi i32 [ %mul, %loop ]\n ret i32 %exit.lcssa\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr142895_exit_value_is_arg", "test_body": "define i32 @pr142895_exit_value_is_arg(i32 %arg) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %indvar = phi i32 [ 0, %entry ], [ %inc, %loop ]\n %cmp1 = icmp eq i32 %indvar, 32\n %sel = select i1 %cmp1, i32 0, i32 0\n %sub = sub i32 0, 0\n %xor = xor i32 0, 0\n %inc = add i32 %indvar, 1\n %exitcond = icmp ne i32 %inc, 33\n br i1 %exitcond, label %loop, label %exit\n\nexit: ; preds = %loop\n %exit.lcssa = phi i32 [ %arg, %loop ]\n ret i32 %exit.lcssa\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopPeel] Assertion `V && \"Dereferencing deleted ValueHandle\"' failed.", "body": "Crash is reproducible on Godbolt:\n[https://godbolt.org/z/4axfWq4dq](https://godbolt.org/z/4axfWq4dq)\n\nReproduce code (compile with `clang-21 -O3 foo.c`):\n```c\nchar func(char a, int b) {\n return b < 32 ? b : 0;\n}\n\nint a;\nint b;\nint main() {\n char v[4][4] = {};\n for (int i = 0; i < 33; i++) {\n for (int j = 0; j < 4; j++) {\n for (int k = 0; k < 4; k++) {\n a ^= v[0][k] - func(b ^= v[0][j], i);\n }\n }\n }\n return 0;\n}\n\n```\n\nStack dump:\n```\n #0 0x0000000003c94d38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3c94d38)\n #1 0x0000000003c92e7c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3c92e7c)\n #2 0x0000000003be36d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x000074a5bf042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x0000000005876204 (anonymous namespace)::VectorCombine::foldSingleElementStore(llvm::Instruction&) VectorCombine.cpp:0:0\n #5 0x00000000058805d9 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\n #6 0x0000000005881057 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x5881057)\n #7 0x0000000004e48f3e llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4e48f3e)\n #8 0x0000000003656ddf llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3656ddf)\n #9 0x00000000011b1a9e 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-trunk/bin/clang+0x11b1a9e)\n#10 0x0000000002bec20e llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2bec20e)\n#11 0x00000000011b1f0e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x11b1f0e)\n#12 0x0000000002be55c6 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2be55c6)\n#13 0x0000000004e489ee llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4e489ee)\n#14 0x0000000002bed3e9 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2bed3e9)\n#15 0x0000000004e48a0e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4e48a0e)\n#16 0x0000000002be8043 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x2be8043)\n#17 0x0000000004e489ce llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4e489ce)\n#18 0x000000000365991f llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x365991f)\n#19 0x00000000054e64b9 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x54e64b9)\n#20 0x0000000004d00f8e llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4d00f8e)\n#21 0x000000000365991f llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x365991f)\n#22 0x0000000003f4491a (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#23 0x0000000003f47412 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3f47412)\n#24 0x00000000045e01e8 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x45e01e8)\n#25 0x000000000624133c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x624133c)\n#26 0x00000000045e0dbd clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x45e0dbd)\n#27 0x00000000048f107a clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x48f107a)\n#28 0x000000000486ca6b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x486ca6b)\n#29 0x00000000049e5683 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x49e5683)\n#30 0x0000000000dcab25 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xdcab25)\n#31 0x0000000000dc296d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#32 0x0000000004652b59 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#33 0x0000000003be3af3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3be3af3)\n#34 0x0000000004652d79 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#35 0x00000000046159ed clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x46159ed)\n#36 0x00000000046169b1 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x46169b1)\n#37 0x00000000046212dc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x46212dc)\n#38 0x0000000000dc72b1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xdc72b1)\n#39 0x0000000000c47e24 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xc47e24)\n#40 0x000074a5bf029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#41 0x000074a5bf029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#42 0x0000000000dc2405 _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xdc2405)\n```", "author": "rivertale", "labels": [ "regression", "crash", "llvm:transforms" ], "comments": [ { "author": "shafik", "body": "Looks like a regression on trunk: https://godbolt.org/z/d6P7cfxox" }, { "author": "dtcxzyw", "body": "Reduced: https://godbolt.org/z/na9veEo6z\n```\n; bin/opt -passes=\"loop(loop-unroll-full)\" test.ll -S\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i32 %b.promoted) {\nentry:\n br label %for.cond1.preheader\n\nfor.cond1.preheader: ; preds = %for.cond1.preheader, %entry\n %i.045 = phi i32 [ 0, %entry ], [ %inc21, %for.cond1.preheader ]\n %cmp.i.not = icmp eq i32 %i.045, 32\n %conv15 = select i1 %cmp.i.not, i32 0, i32 0\n %sub.3.3 = sub i32 0, 0\n %xor16.3.3 = xor i32 0, 0\n %inc21 = add i32 %i.045, 1\n %exitcond = icmp ne i32 %inc21, 33\n br i1 %exitcond, label %for.cond1.preheader, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.cond1.preheader\n %xor.lcssa.lcssa.lcssa = phi i32 [ %b.promoted, %for.cond1.preheader ]\n ret i32 %xor.lcssa.lcssa.lcssa\n}\n```\n```\nopt: /root/llvm-project/llvm/include/llvm/IR/ValueHandle.h:95: llvm::Value& llvm::ValueHandleBase::operator*() const: Assertion `V && \"Dereferencing deleted ValueHandle\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop(loop-unroll-full) <source>\n1.\tRunning pass \"function(loop(loop-unroll-full))\" on module \"<source>\"\n2.\tRunning pass \"loop(loop-unroll-full)\" on function \"main\"\n #0 0x0000000005628878 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5628878)\n #1 0x0000000005626204 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x0000784aa1a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x0000784aa1a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x0000784aa1a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x0000784aa1a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x0000784aa1a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x0000784aa1a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x0000000004875d88 llvm::peelLoop(llvm::Loop*, unsigned int, bool, llvm::LoopInfo*, llvm::ScalarEvolution*, llvm::DominatorTree&, llvm::AssumptionCache*, bool, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4875d88)\n #9 0x0000000004468359 tryToUnrollLoop(llvm::Loop*, llvm::DominatorTree&, llvm::LoopInfo*, llvm::ScalarEvolution&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, bool, int, bool, bool, bool, std::optional<unsigned int>, std::optional<unsigned int>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<unsigned int>, llvm::AAResults*) LoopUnrollPass.cpp:0:0\n#10 0x00000000044691af llvm::LoopFullUnrollPass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44691af)\n#11 0x0000000002d9b20e llvm::detail::PassModel<llvm::Loop, llvm::LoopFullUnrollPass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2d9b20e)\n#12 0x000000000440d346 std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::Loop, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440d346)\n#13 0x000000000440d4ee llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440d4ee)\n#14 0x000000000440e854 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440e854)\n#15 0x000000000440f35d llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440f35d)\n#16 0x0000000000ea0b8e llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xea0b8e)\n#17 0x000000000541eae0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x541eae0)\n#18 0x0000000000ea19fe 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+0xea19fe)\n#19 0x000000000541eff3 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x541eff3)\n#20 0x0000000000ea084e 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+0xea084e)\n#21 0x000000000541cc10 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x541cc10)\n#22 0x0000000000956bba 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+0x956bba)\n#23 0x000000000094a38c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94a38c)\n#24 0x0000784aa1a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#25 0x0000784aa1a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#26 0x0000000000941fc5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x941fc5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```" } ] }
true
null
127739
https://github.com/llvm/llvm-project/issues/127739
crash
d6301b218c6698ceb0db1753c8de480d37d11cf8
2025-02-19T03:17:57
[ "llvm/test/Transforms/Scalarizer" ]
{ "fix_commit": "1440f02259abf585f0c2965bd4ececf0f3499405", "components": [ "Scalarizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": [ [ 719, 731 ], [ 1083, 1088 ] ], "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": [ "ScalarizerVisitor::splitCall", "ScalarizerVisitor::visitExtractValueInst" ], "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1440f02259abf585f0c2965bd4ececf0f3499405 Author: Deric C. <[email protected]> Date: Tue Mar 4 13:10:31 2025 -0800 [Scalarizer] Ensure valid VectorSplits for each struct element in `visitExtractValueInst` (#128538) Fixes #127739 The `visitExtractValueInst` is missing a check that was present in `splitCall` / `visitCallInst`. This check ensures that each struct element has a VectorSplit, and that each VectorSplit contains the same number of elements packed per fragment. --------- Co-authored-by: Jay Foad <[email protected]> diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp index 2b27150112ad..820c8e12d244 100644 --- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -719,13 +719,12 @@ bool ScalarizerVisitor::splitCall(CallInst &CI) { for (unsigned I = 1; I < CallType->getNumContainedTypes(); I++) { std::optional<VectorSplit> CurrVS = getVectorSplit(cast<FixedVectorType>(CallType->getContainedType(I))); - // This case does not seem to happen, but it is possible for - // VectorSplit.NumPacked >= NumElems. If that happens a VectorSplit - // is not returned and we will bailout of handling this call. - // The secondary bailout case is if NumPacked does not match. - // This can happen if ScalarizeMinBits is not set to the default. - // This means with certain ScalarizeMinBits intrinsics like frexp - // will only scalarize when the struct elements have the same bitness. + // It is possible for VectorSplit.NumPacked >= NumElems. If that happens a + // VectorSplit is not returned and we will bailout of handling this call. + // The secondary bailout case is if NumPacked does not match. This can + // happen if ScalarizeMinBits is not set to the default. This means with + // certain ScalarizeMinBits intrinsics like frexp will only scalarize when + // the struct elements have the same bitness. if (!CurrVS || CurrVS->NumPacked != VS->NumPacked) return false; if (isVectorIntrinsicWithStructReturnOverloadAtField(ID, I, TTI)) @@ -1083,6 +1082,18 @@ bool ScalarizerVisitor::visitExtractValueInst(ExtractValueInst &EVI) { std::optional<VectorSplit> VS = getVectorSplit(VecType); if (!VS) return false; + for (unsigned I = 1; I < OpTy->getNumContainedTypes(); I++) { + std::optional<VectorSplit> CurrVS = + getVectorSplit(cast<FixedVectorType>(OpTy->getContainedType(I))); + // It is possible for VectorSplit.NumPacked >= NumElems. If that happens a + // VectorSplit is not returned and we will bailout of handling this call. + // The secondary bailout case is if NumPacked does not match. This can + // happen if ScalarizeMinBits is not set to the default. This means with + // certain ScalarizeMinBits intrinsics like frexp will only scalarize when + // the struct elements have the same bitness. + if (!CurrVS || CurrVS->NumPacked != VS->NumPacked) + return false; + } IRBuilder<> Builder(&EVI); Scatterer Op0 = scatter(&EVI, Op, *VS); assert(!EVI.getIndices().empty() && "Make sure an index exists");
[ { "file": "llvm/test/Transforms/Scalarizer/min-bits.ll", "commands": [ "opt %s -passes='function(scalarizer<load-store;min-bits=16>,dce)' -S", "opt %s -passes='function(scalarizer<load-store;min-bits=32>,dce)' -S", "opt %s -passes='function(scalarizer<load-store;min-bits=64>,dce)' -S" ], "tests": [ { "test_name": "load_add_store_v2i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v2i16(ptr %pa, ptr %pb) {\n %a = load <2 x i16>, ptr %pa, align 8\n %b = load <2 x i16>, ptr %pb, align 8\n %c = add <2 x i16> %a, %b\n store <2 x i16> %c, ptr %pa, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_uniform_condition_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @select_uniform_condition_v3f16(<3 x half> %a, <3 x half> %b, i1 %cc) {\n %r = select i1 %cc, <3 x half> %a, <3 x half> %b\n ret <3 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "call_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @call_v4f16(<4 x half> %a, <4 x half> %b) {\n %r = call <4 x half> @llvm.minnum.v4f16(<4 x half> %a, <4 x half> %b)\n ret <4 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.minnum.v4f16(<4 x half>, <4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "unary_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @unary_v4f16(<4 x half> %a) {\n %r = fneg <4 x half> %a\n ret <4 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "gep1_v4", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x ptr> @gep1_v4(ptr %base, <4 x i16> %a) {\n %p = getelementptr i32, ptr %base, <4 x i16> %a\n ret <4 x ptr> %p\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fptosi_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x i16> @fptosi_v3f16(<3 x half> %a) {\n %r = fptosi <3 x half> %a to <3 x i16>\n ret <3 x i16> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "binary_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @binary_v2f16(<2 x half> %a, <2 x half> %b) {\n %r = fadd <2 x half> %a, %b\n ret <2 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "gep3_v4", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x ptr> @gep3_v4(<4 x ptr> %base, <4 x i16> %a) {\n %p = getelementptr i32, <4 x ptr> %base, <4 x i16> %a\n ret <4 x ptr> %p\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fptosi_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x i16> @fptosi_v4f16(<4 x half> %a) {\n %r = fptosi <4 x half> %a to <4 x i16>\n ret <4 x i16> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "binary_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @binary_v3f16(<3 x half> %a, <3 x half> %b) {\n %r = fadd <3 x half> %a, %b\n ret <3 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "load_add_store_v4i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v4i16(ptr %pa, ptr %pb) {\n %a = load <4 x i16>, ptr %pa, align 8\n %b = load <4 x i16>, ptr %pb, align 8\n %c = add <4 x i16> %a, %b\n store <4 x i16> %c, ptr %pa, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_uniform_condition_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @select_uniform_condition_v2f16(<2 x half> %a, <2 x half> %b, i1 %cc) {\n %r = select i1 %cc, <2 x half> %a, <2 x half> %b\n ret <2 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shufflevector_shrink", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @shufflevector_shrink(ptr %pa) {\n %a = load <4 x i16>, ptr %pa, align 8\n %r = shufflevector <4 x i16> %a, <4 x i16> poison, <2 x i32> <i32 1, i32 2>\n store <2 x i16> %r, ptr %pa, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "phi_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @phi_v2f16(ptr %base, i64 %bound) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %x = phi <2 x half> [ zeroinitializer, %entry ], [ %x.next, %loop ]\n %idx = phi i64 [ 0, %entry ], [ %idx.next, %loop ]\n %p = getelementptr <2 x half>, ptr %base, i64 %idx\n %a = load <2 x half>, ptr %p, align 2\n %x.next = fadd <2 x half> %x, %a\n %idx.next = add i64 %idx, 1\n %cc = icmp ult i64 %idx.next, %bound\n br i1 %cc, label %loop, label %end\n\nend: ; preds = %loop\n store <2 x half> %x.next, ptr %base, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "frexp_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine noundef <2 x half> @frexp_v2f16(<2 x half> noundef %h) {\n %r = call { <2 x half>, <2 x i32> } @llvm.frexp.v2f16.v2i32(<2 x half> %h)\n %e0 = extractvalue { <2 x half>, <2 x i32> } %r, 0\n ret <2 x half> %e0\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { <2 x half>, <2 x i32> } @llvm.frexp.v2f16.v2i32(<2 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "load_insertelement_v3i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x i16> @load_insertelement_v3i16(ptr %pa, i16 %b) {\n %a = load <3 x i16>, ptr %pa, align 8\n %r = insertelement <3 x i16> %a, i16 %b, i64 2\n ret <3 x i16> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "load_add_store_v3i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v3i16(ptr %pa, ptr %pb) {\n %a = load <3 x i16>, ptr %pa, align 8\n %b = load <3 x i16>, ptr %pb, align 8\n %c = add <3 x i16> %a, %b\n store <3 x i16> %c, ptr %pa, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fptosi_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x i16> @fptosi_v2f16(<2 x half> %a) {\n %r = fptosi <2 x half> %a to <2 x i16>\n ret <2 x i16> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "insertelement_v4i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @insertelement_v4i16(ptr %p, <4 x i16> %a, i16 %b) {\n %r = insertelement <4 x i16> %a, i16 %b, i64 3\n store <4 x i16> %r, ptr %p, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "load_insertelement_v2i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x i16> @load_insertelement_v2i16(ptr %pa, i16 %b) {\n %a = load <2 x i16>, ptr %pa, align 4\n %r = insertelement <2 x i16> %a, i16 %b, i64 1\n ret <2 x i16> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "load_insertelement_v4i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x i16> @load_insertelement_v4i16(ptr %pa, i16 %b) {\n %a = load <4 x i16>, ptr %pa, align 8\n %r = insertelement <4 x i16> %a, i16 %b, i64 3\n ret <4 x i16> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "insertelement_v2i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @insertelement_v2i16(ptr %p, <2 x i16> %a, i16 %b) {\n %r = insertelement <2 x i16> %a, i16 %b, i64 1\n store <2 x i16> %r, ptr %p, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shufflevector_grow", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @shufflevector_grow(ptr %pa, ptr %pb) {\n %a = load <2 x i16>, ptr %pa, align 4\n %b = load <2 x i16>, ptr %pb, align 4\n %r = shufflevector <2 x i16> %a, <2 x i16> %b, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n store <4 x i16> %r, ptr %pa, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "uadd_with_overflow_v3i32", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x i32> @uadd_with_overflow_v3i32(<3 x i32> %a, <3 x i32> %b) {\n %t = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %a, <3 x i32> %b)\n %r = extractvalue { <3 x i32>, <3 x i1> } %t, 0\n ret <3 x i32> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32>, <3 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "insertelement_v3i16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @insertelement_v3i16(ptr %p, <3 x i16> %a, i16 %b) {\n %r = insertelement <3 x i16> %a, i16 %b, i64 2\n store <3 x i16> %r, ptr %p, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "call_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @call_v2f16(<2 x half> %a, <2 x half> %b) {\n %r = call <2 x half> @llvm.minnum.v2f16(<2 x half> %a, <2 x half> %b)\n ret <2 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x half> @llvm.minnum.v2f16(<2 x half>, <2 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "phi_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @phi_v3f16(ptr %base, i64 %bound) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %x = phi <3 x half> [ zeroinitializer, %entry ], [ %x.next, %loop ]\n %idx = phi i64 [ 0, %entry ], [ %idx.next, %loop ]\n %p = getelementptr <3 x half>, ptr %base, i64 %idx\n %a = load <3 x half>, ptr %p, align 2\n %x.next = fadd <3 x half> %x, %a\n %idx.next = add i64 %idx, 1\n %cc = icmp ult i64 %idx.next, %bound\n br i1 %cc, label %loop, label %end\n\nend: ; preds = %loop\n store <3 x half> %x.next, ptr %base, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "phi_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @phi_v4f16(ptr %base, i64 %bound) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %x = phi <4 x half> [ zeroinitializer, %entry ], [ %x.next, %loop ]\n %idx = phi i64 [ 0, %entry ], [ %idx.next, %loop ]\n %p = getelementptr <4 x half>, ptr %base, i64 %idx\n %a = load <4 x half>, ptr %p, align 2\n %x.next = fadd <4 x half> %x, %a\n %idx.next = add i64 %idx, 1\n %cc = icmp ult i64 %idx.next, %bound\n br i1 %cc, label %loop, label %end\n\nend: ; preds = %loop\n store <4 x half> %x.next, ptr %base, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "call_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @call_v3f16(<3 x half> %a, <3 x half> %b) {\n %r = call <3 x half> @llvm.minnum.v3f16(<3 x half> %a, <3 x half> %b)\n ret <3 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <3 x half> @llvm.minnum.v3f16(<3 x half>, <3 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "binary_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @binary_v4f16(<4 x half> %a, <4 x half> %b) {\n %r = fadd <4 x half> %a, %b\n ret <4 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fpext_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x float> @fpext_v4f16(<4 x half> %a) {\n %r = fpext <4 x half> %a to <4 x float>\n ret <4 x float> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "load_add_store_v4i10", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @load_add_store_v4i10(ptr %pa, ptr %pb) {\n %a = load <4 x i10>, ptr %pa, align 8\n %b = load <4 x i10>, ptr %pb, align 8\n %c = add <4 x i10> %a, %b\n store <4 x i10> %c, ptr %pa, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "unary_v3f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <3 x half> @unary_v3f16(<3 x half> %a) {\n %r = fneg <3 x half> %a\n ret <3 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "unary_v2f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <2 x half> @unary_v2f16(<2 x half> %a) {\n %r = fneg <2 x half> %a\n ret <2 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_uniform_condition_v4f16", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine <4 x half> @select_uniform_condition_v4f16(<4 x half> %a, <4 x half> %b, i1 %cc) {\n %r = select i1 %cc, <4 x half> %a, <4 x half> %b\n ret <4 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[Scalarizer] Test *_with_overflow crash with min-bits=32 and min-bits=16", "body": "first reported here: https://github.com/llvm/llvm-project/pull/127520\nintroduced by: https://github.com/llvm/llvm-project/pull/126815\n\n```llvm\n; RUN: opt %s -passes='function(scalarizer<load-store;min-bits=16>,dce)' -S | FileCheck %s --check-prefixes=CHECK,MIN16\n; RUN: opt %s -passes='function(scalarizer<load-store;min-bits=32>,dce)' -S | FileCheck %s --check-prefixes=CHECK,MIN32\n\ndefine <3 x i32> @call_v3i32(<3 x i32> %a, <3 x i32> %b) {\n; CHECK-LABEL: @call_v3i32(\n; CHECK-NEXT: [[T:%.*]] = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> [[A:%.*]], <3 x i32> [[B:%.*]])\n; CHECK-NEXT: [[R:%.*]] = extractvalue { <3 x i32>, <3 x i1> } [[T]], 0\n; CHECK-NEXT: ret <3 x i32> [[R]]\n;\n %t = call { <3 x i32>, <3 x i1> } @llvm.uadd.with.overflow.v3i32(<3 x i32> %a, <3 x i32> %b)\n %r = extractvalue { <3 x i32>, <3 x i1> } %t, 0\n ret <3 x i32> %r\n}\n\n```\n\n```bash\nopt: include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = llvm::VectorType, From = llvm::Type]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: opt -passes=function(scalarizer<load-store;min-bits=16>,dce) -S\n1.\tRunning pass \"function(scalarizer,dce)\" on module \"<stdin>\"\n2.\tRunning pass \"scalarizer\" on function \"call_v3i32\"\n #0 0x0000000004028908 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (opt+0x4028908)\n #1 0x000000000402643e llvm::sys::RunSignalHandlers() (opt+0x402643e)\n #2 0x0000000004029131 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x000075c457a45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x000075c457a9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #5 0x000075c457a9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #6 0x000075c457a9eb2c pthread_kill ./nptl/pthread_kill.c:89:10\n #7 0x000075c457a4527e raise ./signal/../sysdeps/posix/raise.c:27:6\n #8 0x000075c457a288ff abort ./stdlib/abort.c:81:7\n #9 0x000075c457a2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n#10 0x000075c457a3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)\n#11 0x0000000004143bea (opt+0x4143bea)\n#12 0x00000000049addf4 (anonymous namespace)::Scatterer::operator[](unsigned int) Scalarizer.cpp:0:0\n#13 0x00000000049aa142 (anonymous namespace)::ScalarizerVisitor::visit(llvm::Function&) Scalarizer.cpp:0:0\n#14 0x00000000049a5419 llvm::ScalarizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (opt+0x49a5419)\n```\n\nNo line numbers, Looks like we have some missing debug symbols I suspect the assert is coming from `ScalarizerVisitor::visitExtractValueInst`\n\nThere is a use of Scatterer::operator[] as part of creating the ExtractValue IR.\n\n```cpp\nfor (unsigned OpIdx = 0; OpIdx < Op0.size(); ++OpIdx) {\n Value *ResElem = Builder.CreateExtractValue(\n Op0[OpIdx], Index, EVI.getName() + \".elem\" + Twine(Index));\n Res.push_back(ResElem);\n }\n```\n\nWe likely need to check `VS.NumPacked` before calling `Scatterer::operator[]`\n\nBecause that operator is using `Frag * VS.NumPacked` to create the exrtractElement instruction.\n\n```cpp\n CV[Frag] = Builder.CreateExtractElement(V, Frag * VS.NumPacked,\n V->getName() + \".i\" + Twine(Frag))\n```\n\n ", "author": "farzonl", "labels": [ "crash-on-valid", "llvm:analysis" ], "comments": [ { "author": "farzonl", "body": "@Icohedron can you look into this issue. I'm also noticing a second potential issue:\n\n`call { <3 x i32>, <3 x i1> }`\n\nThe struct return elements are not the same type. one is vec3 of i32 one is and one is vec3 of i1. you need to add the `*_with_overflow` intrinsics to `isVectorIntrinsicWithStructReturnOverloadAtField` if these types are not the same." }, { "author": "Icohedron", "body": "I'm on it" }, { "author": "jayfoad", "body": "As mentioned in #127996, note that you can also provoke this bug by adding `min-bits=64` to `test/Transforms/Scalarizer/frexp.ll`." }, { "author": "Icohedron", "body": "> [@Icohedron](https://github.com/Icohedron) can you look into this issue. I'm also noticing a second potential issue:\n> \n> `call { <3 x i32>, <3 x i1> }`\n> \n> The struct return elements are not the same type. one is vec3 of i32 one is and one is vec3 of i1. you need to add the `*_with_overflow` intrinsics to `isVectorIntrinsicWithStructReturnOverloadAtField` if these types are not the same.\n\n`isVectorIntrinsicWithStructReturnOverloadAtField` appears to only be for intrinsic name-mangling when there is more than one possible type for the the 2nd element in the struct return type (see [splitCall](https://github.com/llvm/llvm-project/blob/5f8da7e7738f043dbde447e48622e9b2afb5ba92/llvm/lib/Transforms/Scalar/Scalarizer.cpp#L770) and [getOrInsertDeclaration](https://github.com/llvm/llvm-project/blob/5f8da7e7738f043dbde447e48622e9b2afb5ba92/llvm/lib/IR/Intrinsics.cpp#L763)). For the `*_with_overflow` intrinsics, the 2nd element of the return struct is always i1, so it does not need to be added to `isVectorIntrinsicWithStructReturnOverloadAtField`.\n\nAdding the `*_with_overflow` intrinsic to `isVectorIntrinsicWithStructReturnOverloadAtField` results in a broken LLVM module.\n```\nIntrinsic name not mangled correctly for type arguments! Should be: llvm.uadd.with.overflow.i32\nptr @llvm.uadd.with.overflow.i32.i1\nLLVM ERROR: Broken module found, compilation aborted!\n```" } ] }
true
null
82230
https://github.com/llvm/llvm-project/issues/82230
crash
769c22f25b81b74e4da7871d4e552584605caef1
2024-02-19T09:37:19
[ "llvm/test/DebugInfo" ]
{ "fix_commit": "5b342e6041f8567a39354ae3c5346cf74b3bb84f", "components": [ "IR" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": [ [ 293, 299 ], [ 4886, 4893 ] ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/IR/AsmWriter.cpp": [ "DPValue::print", "PrintCallingConv", "getModuleFromDPI" ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 5b342e6041f8567a39354ae3c5346cf74b3bb84f Author: Stephen Tozer <[email protected]> Date: Mon Feb 19 11:38:04 2024 +0000 [RemoveDIs][DebugInfo] Check for null marker when printing DPValues (#82238) The function to print DPValues currently tries to incorporate the function it is part of, which is found through its marker; this means when we try to print a DPValue with no marker, we dereference a nullptr. We can print instructions without parents, and so the same should be true for DPValues; this patch changes DPValue::print to check for a null marker and avoid dereferencing it. Fixes issue: https://github.com/llvm/llvm-project/issues/82230 diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 0ae720e8b7ce..d3c64a57f7fd 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -293,7 +293,7 @@ static const Module *getModuleFromDPI(const DPMarker *Marker) { } static const Module *getModuleFromDPI(const DPValue *DPV) { - return getModuleFromDPI(DPV->getMarker()); + return DPV->getMarker() ? getModuleFromDPI(DPV->getMarker()) : nullptr; } static void PrintCallingConv(unsigned cc, raw_ostream &Out) { @@ -4886,8 +4886,9 @@ void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST, if (F) MST.incorporateFunction(*F); }; - incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent() - : nullptr); + incorporateFunction(Marker && Marker->getParent() + ? Marker->getParent()->getParent() + : nullptr); AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); W.printDPValue(*this); }
[ { "file": "llvm/test/DebugInfo/dpvalue-print-nocrash.ll", "commands": [ "opt -passes=\"instcombine\" -debug %s -o /dev/null 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": ";; Tests that we can debug-print DPValues that have no markers attached.\n; REQUIRES: asserts\n\n\ndefine ptr @func_10(i32 %p_11) {\nentry:\n %conv108 = zext i32 %p_11 to i64\n tail call void @llvm.dbg.value(metadata i64 %conv108, metadata !4, metadata !DIExpression()), !dbg !12\n br label %func_29.exit\n\nfunc_29.exit: ; preds = %entry\n store i64 %conv108, ptr null, align 1\n ret ptr null\n}\n\ndeclare void @llvm.dbg.value(metadata, metadata, metadata)\n\n!llvm.dbg.cu = !{!0}\n!llvm.module.flags = !{!3}\n\n!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: \"clang\", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)\n!1 = !DIFile(filename: \"csmith5961503756960.c\", directory: \"/llvm\")\n!2 = !{}\n!3 = !{i32 2, !\"Debug Info Version\", i32 3}\n!4 = !DILocalVariable(name: \"p_31\", arg: 2, scope: !5, file: !1, line: 148, type: !7)\n!5 = distinct !DISubprogram(name: \"func_29\", scope: !1, file: !1, line: 148, type: !6, scopeLine: 149, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)\n!6 = !DISubroutineType(types: !2)\n!7 = !DIDerivedType(tag: DW_TAG_typedef, name: \"uint64_t\", file: !8, line: 60, baseType: !9)\n!8 = !DIFile(filename: \"/foo/_stdint.h\", directory: \"\")\n!9 = !DIDerivedType(tag: DW_TAG_typedef, name: \"__uint64_t\", file: !10, line: 108, baseType: !11)\n!10 = !DIFile(filename: \"/foo/_default_types.h\", directory: \"\")\n!11 = !DIBasicType(name: \"unsigned long long\", size: 64, encoding: DW_ATE_unsigned)\n!12 = !DILocation(line: 0, scope: !5)", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "opt -passes=\"instcombine\" -debug crashes with non-instrinsic debug-info", "body": "llvm commit: d61864f813e3\r\nReproduce with:\r\n```\r\nopt -passes=\"instcombine\" -debug bbi-92509.ll -o /dev/null\r\n```\r\n[bbi-92509.ll.gz](https://github.com/llvm/llvm-project/files/14329283/bbi-92509.ll.gz)\r\n\r\nResult:\r\n```\r\nINSTCOMBINE ITERATION #1 on func_10\r\nADD: ret ptr null\r\nADD: store i64 %conv108, ptr null, align 1\r\nADD: br label %func_29.exit\r\nADD: %conv108 = zext i32 %p_11 to i64\r\nCLONE: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: ../../main-github/llvm/build-all/bin/opt -passes=instcombine -debug bbi-92509.ll -o /dev/null\r\n #0 0x000055e12968f4a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x3db14a7)\r\n #1 0x000055e12968cf7e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x3daef7e)\r\n #2 0x000055e12968fe6f SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fdf33999630 __restore_rt sigaction.c:0:0\r\n #4 0x000055e12971f8e0 llvm::DPMarker::getParent() const (../../main-github/llvm/build-all/bin/opt+0x3e418e0)\r\n #5 0x000055e129761abf llvm::DPValue::print(llvm::raw_ostream&, bool) const (../../main-github/llvm/build-all/bin/opt+0x3e83abf)\r\n #6 0x000055e12a244957 llvm::InstCombinerImpl::tryToSinkInstructionDPValues(llvm::Instruction*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, false>, llvm::BasicBlock*, llvm::BasicBlock*, llvm::SmallVectorImpl<llvm::DPValue*>&) InstructionCombining.cpp:0:0\r\n #7 0x000055e12a242b0c llvm::InstCombinerImpl::tryToSinkInstruction(llvm::Instruction*, llvm::BasicBlock*) InstructionCombining.cpp:0:0\r\n #8 0x000055e12a2453fc llvm::InstCombinerImpl::run() InstructionCombining.cpp:0:0\r\n #9 0x000055e12a248c79 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, llvm::LoopInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0\r\n#10 0x000055e12a2482ea llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x496a2ea)\r\n#11 0x000055e12a95e5bd llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\r\n#12 0x000055e12989a8e4 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x3fbc8e4)\r\n#13 0x000055e12a9644dd llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\r\n#14 0x000055e12989f9ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x3fc19ae)\r\n#15 0x000055e12a95dd9d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilderPipelines.cpp:0:0\r\n#16 0x000055e129899456 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x3fbb456)\r\n#17 0x000055e12a90a42b 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) (../../main-github/llvm/build-all/bin/opt+0x502c42b)\r\n#18 0x000055e129657a28 optMain (../../main-github/llvm/build-all/bin/opt+0x3d79a28)\r\n#19 0x00007fdf310cc555 __libc_start_main (/lib64/libc.so.6+0x22555)\r\n#20 0x000055e129651369 _start (../../main-github/llvm/build-all/bin/opt+0x3d73369)\r\nSegmentation fault (core dumped)\r\n```\r\n\r\nThis starts happening with a93a4ec7dd205\r\n```\r\nReapply \"[DebugInfo][RemoveDIs] Turn on non-instrinsic debug-info by default\"\r\n```\r\n", "author": "mikaelholmen", "labels": [ "debuginfo", "llvm:crash", "llvm:ir" ], "comments": [ { "author": "SLTozer", "body": "Should be fixed by: [5b342e6](https://github.com/llvm/llvm-project/commit/5b342e6041f8567a39354ae3c5346cf74b3bb84f)" }, { "author": "mikaelholmen", "body": "> Should be fixed by: [5b342e6](https://github.com/llvm/llvm-project/commit/5b342e6041f8567a39354ae3c5346cf74b3bb84f)\r\n\r\nYep, thanks!" } ] }
true
null
126304
https://github.com/llvm/llvm-project/issues/126304
crash
fcbf04e40e66014f455a38b59993be865bc6cdfd
2025-02-07T20:48:01
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "10844fb9b0b78695243391e091e17ec29295872a", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 5596, 5601 ], [ 5626, 5632 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::getReorderingData" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 10844fb9b0b78695243391e091e17ec29295872a Author: Alexey Bataev <[email protected]> Date: Tue Feb 11 13:23:55 2025 -0800 [SLP]Fix attempt to build the reorder mask for non-adjusted reuse mask When building the reorder for non-single use reuse mask, need to check if the size of the mask is multiple of the number of unique scalars. Otherwise, the compiler may crash when trying to reorder nodes. Fixes #126304 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index e1c08077126d..fb1054ee30aa 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -5596,6 +5596,8 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) { ::getNumberOfParts(*TTI, getWidenedType(TE.Scalars.front()->getType(), 2 * TE.getVectorFactor())) == 1) return std::nullopt; + if (TE.ReuseShuffleIndices.size() % Sz != 0) + return std::nullopt; if (!ShuffleVectorInst::isOneUseSingleSourceMask(TE.ReuseShuffleIndices, Sz)) { SmallVector<int> ReorderMask(Sz, PoisonMaskElem); @@ -5626,7 +5628,7 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) { UsedVals.set(Val); for (unsigned K = 0; K < NumParts; ++K) { unsigned Idx = Val + Sz * K; - if (Idx < VF) + if (Idx < VF && I + K < VF) ResOrder[Idx] = I + K; } }
[ { "file": "llvm/test/Transforms/SLPVectorizer/SystemZ/reuse-non-power-of-2-reorder.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=systemz -mcpu=z15 < %s -slp-threshold=-100" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(i32 %0, i64 %1, i32 %2, i32 %3, ptr %4) {\n;\n %6 = trunc i64 %1 to i32\n %7 = xor i32 %6, 1\n %8 = xor i32 %6, 1\n %9 = or i32 %7, %8\n %10 = xor i32 %6, 1\n %11 = or i32 %9, %10\n %12 = xor i32 %6, 1\n %13 = or i32 %11, %12\n %14 = xor i32 %6, 1\n %15 = or i32 %13, %14\n %16 = xor i32 %6, 1\n %17 = or i32 %15, %16\n %18 = xor i32 %6, 1\n %19 = or i32 %17, %18\n %20 = xor i32 %6, 1\n %21 = or i32 %19, %20\n %22 = trunc i64 %1 to i32\n %23 = xor i32 %22, 1\n %24 = or i32 %23, %21\n %25 = xor i32 %22, 1\n %26 = or i32 %24, %25\n %27 = xor i32 %22, 1\n %28 = or i32 %26, %27\n %29 = xor i32 %22, 1\n %30 = or i32 %28, %29\n %31 = xor i32 %22, 1\n %32 = or i32 %30, %31\n %33 = xor i32 %22, 1\n %34 = or i32 %32, %33\n %35 = xor i32 %22, 1\n %36 = or i32 %34, %35\n %37 = xor i32 %22, 1\n %38 = or i32 %36, %37\n %39 = trunc i64 %1 to i32\n %40 = xor i32 %39, 1\n %41 = or i32 %40, %38\n %42 = xor i32 %39, 1\n %43 = or i32 %41, %42\n %44 = xor i32 %39, 1\n %45 = or i32 %43, %44\n %46 = xor i32 %39, 1\n %47 = or i32 %45, %46\n %48 = xor i32 %39, 1\n %49 = or i32 %47, %48\n %50 = xor i32 %39, 1\n %51 = or i32 %49, %50\n %52 = xor i32 %39, 1\n %53 = or i32 %51, %52\n %54 = xor i32 %39, 1\n %55 = or i32 %53, %54\n %56 = trunc i64 %1 to i32\n %57 = xor i32 %56, 1\n %58 = or i32 %57, %55\n %59 = xor i32 %56, 1\n %60 = or i32 %58, %59\n %61 = xor i32 %56, 1\n %62 = or i32 %60, %61\n %63 = xor i32 %56, 1\n %64 = or i32 %62, %63\n %65 = xor i32 %56, 1\n %66 = or i32 %64, %65\n %67 = xor i32 %56, 1\n %68 = or i32 %66, %67\n %69 = xor i32 %56, 1\n %70 = or i32 %68, %69\n %71 = xor i32 %56, 1\n %72 = or i32 %70, %71\n %73 = trunc i64 %1 to i32\n %74 = xor i32 %73, 1\n %75 = or i32 %74, %72\n %76 = xor i32 %73, 1\n %77 = or i32 %75, %76\n %78 = xor i32 %73, 1\n %79 = or i32 %77, %78\n %80 = xor i32 %73, 1\n %81 = or i32 %79, %80\n %82 = xor i32 %73, 1\n %83 = or i32 %81, %82\n %84 = xor i32 %73, 1\n %85 = or i32 %83, %84\n %86 = xor i32 %73, 1\n %87 = or i32 %85, %86\n %88 = xor i32 %0, %73\n %89 = or i32 %87, %88\n %90 = xor i32 %0, %2\n %91 = or i32 %90, %89\n %92 = xor i32 %0, %2\n %93 = or i32 %91, %92\n %94 = xor i32 %0, %2\n %95 = or i32 %93, %94\n %96 = xor i32 %0, %2\n %97 = or i32 %95, %96\n %98 = trunc i64 %1 to i32\n %99 = xor i32 %98, 1\n %100 = xor i32 %98, 1\n %101 = or i32 %99, %100\n %102 = xor i32 %98, 1\n %103 = or i32 %101, %102\n %104 = xor i32 %98, 1\n %105 = or i32 %103, %104\n %106 = xor i32 %98, 1\n %107 = or i32 %105, %106\n %108 = xor i32 %98, 1\n %109 = or i32 %107, %108\n %110 = xor i32 %98, 1\n %111 = or i32 %109, %110\n %112 = xor i32 %0, %98\n %113 = or i32 %111, %112\n %114 = xor i32 %0, %3\n %115 = or i32 %113, %114\n %116 = xor i32 %0, %3\n %117 = or i32 %115, %116\n %118 = xor i32 %0, %3\n %119 = or i32 %117, %118\n %120 = xor i32 %0, %3\n %121 = or i32 %119, %120\n %122 = xor i32 %0, %3\n %123 = or i32 %121, %122\n %124 = xor i32 %0, %3\n %125 = or i32 %123, %124\n %126 = xor i32 %0, %3\n %127 = or i32 %125, %126\n %128 = xor i32 %0, %3\n %129 = or i32 %127, %128\n %130 = or i32 %129, %97\n store i32 %130, ptr %4, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP] llvm::BitVector::set(unsigned int): Assertion `Idx < Size && \"access in bound\"' failed.", "body": "[crash41.tar.gz](https://github.com/user-attachments/files/18712696/crash41.tar.gz)\n\nclang -O3 -march=z15 crash41.i -o a.out -w -mllvm -inline-threshold=450\n\nllvm/include/llvm/ADT/BitVector.h:358: llvm::BitVector& llvm::BitVector::set(unsigned int): Assertion `Idx < Size && \"access in bound\"' failed.\n\n#11 0x000002aa03b45768 llvm::SLPVectorizerPass::vectorizeHorReduction\n\n@alexey-bataev \n", "author": "JonPsson1", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
91883
https://github.com/llvm/llvm-project/issues/91883
crash
90109d444839683b09f0aafdc50b749cb4b3203b
2024-05-12T12:03:48
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "67d840b60fbd75ca1b52d77bd3353771ec853735", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": [ [ 246, 252 ] ], "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": [ "VPTransformState::get" ], "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 67d840b60fbd75ca1b52d77bd3353771ec853735 Author: Florian Hahn <[email protected]> Date: Tue May 14 19:10:48 2024 +0100 [VPlan] Relax over-aggressive assertion in VPTransformState::get(). There are cases where a vector value has some users that demand the the single scalar value only (NeedsScalar), while other users demand the vector value (see attached test cases). In those cases, the NeedsScalar users should only demand the first lane. Fixes https://github.com/llvm/llvm-project/issues/91883. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index 999236ae8489..27f8e239b1c0 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -246,7 +246,7 @@ Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) { Value *VPTransformState::get(VPValue *Def, unsigned Part, bool NeedsScalar) { if (NeedsScalar) { - assert((VF.isScalar() || Def->isLiveIn() || + assert((VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def, Part) || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && "Trying to access a single scalar per part but has multiple scalars "
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/widened-value-used-as-scalar-and-first-lane.ll", "commands": [ "opt -S -passes=loop-vectorize -mcpu=skylake-avx512 -mtriple=x86_64-apple-macosx -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\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\"\n\n; Test cases based on https://github.com/llvm/llvm-project/issues/91883.\ndefine void @iv.4_used_as_vector_and_first_lane(ptr %src, ptr noalias %dst) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %g.src = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %g.src\n %iv.4 = add nuw nsw i64 %iv, 4\n %c = icmp ule i64 %l, 128\n br i1 %c, label %loop.then, label %loop.latch\n\nloop.then:\n %or = or disjoint i64 %iv.4, 1\n %g.dst = getelementptr inbounds i64, ptr %dst, i64 %or\n store i64 %iv.4, ptr %g.dst, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond = icmp eq i64 %iv.next, 32\n br i1 %exitcond, label %exit, label %loop.header\n\nexit:\n ret void\n}\n\ndefine void @iv.4_used_as_first_lane(ptr %src, ptr noalias %dst) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %g.src = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %g.src\n %iv.4 = add nuw nsw i64 %iv, 4\n %c = icmp ule i64 %l, 128\n br i1 %c, label %loop.then, label %loop.latch\n\nloop.then:\n %or = or disjoint i64 %iv.4, 1\n %g.dst = getelementptr inbounds i64, ptr %dst, i64 %or\n store i64 %l, ptr %g.dst, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond = icmp eq i64 %iv.next, 32\n br i1 %exitcond, label %exit, label %loop.header\n\nexit:\n ret void\n}\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "New LLVM vectorizer crash in assertion", "body": "@fhahn hits an assertion introduced in https://github.com/llvm/llvm-project/pull/80271\r\n\r\nInput file: https://gist.github.com/cheshire/e504c63db9bdb300fbdcc1df2e183bd8\r\n\r\nRepro:\r\n\r\n```\r\nopt -S -passes=loop-vectorize -mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-avx512pf,-tsxldtrk,-ptwrite,-widekl,-sm3,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-avx512er,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-prefetchwt1,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a -mcpu=skylake-avx512 /tmp/minimized_crash.ll\r\n```", "author": "cheshire", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
80289
https://github.com/llvm/llvm-project/issues/80289
miscompilation
f7b05e055fa63e1c4b5ae5e391b654b57161a0e4
2024-02-01T13:14:59
[ "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "62ae7d976f494f3dbd297331b19cd1204750de6f", "components": [ "LoopUnrollRuntime" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": [ [ 776, 782 ] ], "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": [ "llvm::UnrollRuntimeLoopRemainder" ], "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 62ae7d976f494f3dbd297331b19cd1204750de6f Author: Nikita Popov <[email protected]> Date: Thu Feb 1 16:06:58 2024 +0100 [LoopUnroll] Fix missing sign extension For integers larger than 64-bit, this would zero-extend a -1 value, instead of sign-extending it. Fixes https://github.com/llvm/llvm-project/issues/80289. diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp index 612f69970881..650f055356c0 100644 --- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp @@ -776,7 +776,7 @@ bool llvm::UnrollRuntimeLoopRemainder( !isGuaranteedNotToBeUndefOrPoison(TripCount, AC, PreHeaderBR, DT)) { TripCount = B.CreateFreeze(TripCount); BECount = - B.CreateAdd(TripCount, ConstantInt::get(TripCount->getType(), -1)); + B.CreateAdd(TripCount, Constant::getAllOnesValue(TripCount->getType())); } else { // If we don't need to freeze, use SCEVExpander for BECount as well, to // allow slightly better value reuse.
[ { "file": "llvm/test/Transforms/LoopUnroll/runtime-i128.ll", "commands": [ "opt -S -passes=loop-unroll -unroll-runtime < %s" ], "tests": [ { "test_name": "test", "test_body": "declare void @foo()\n\ndefine void @test(i128 %n, i128 %m) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i128 [ 0, %entry ], [ %iv.next, %loop ]\n call void @foo()\n %iv.next = add i128 %iv, 1\n %cmp = icmp ne i128 %iv.next, %n\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "WRONG code: LoopUnroll / SCEVExpander with i128 induction variable.", "body": "This reduced (csmith) test case seems well-defined, and should print '6':\r\n\r\n```\r\nchar C = 0;\r\n__int128 IW = 0;\r\nint *IPtr1, *IPtr2;\r\n\r\nstruct S2 { int f3; };\r\nvolatile struct S2 g_1100;\r\n\r\nint main() {\r\n for (; C <= 5; C += 1)\r\n for (; IW <= 5; IW += 1) {\r\n IPtr1 = IPtr2;\r\n g_1100;\r\n }\r\n int crc = IW;\r\n printf(\"checksum = %d\\n\", crc);\r\n}\r\n```\r\n```\r\n\r\nclang -target s390x-linux-gnu -march=z16 -O3 -mllvm -enable-load-pre=false -o ./a.out -mllvm -unroll-max-count=3; ./a.out\r\nchecksum = 7\r\nclang -target s390x-linux-gnu -march=z16 -O3 -mllvm -enable-load-pre=false -o ./a.out -mllvm -unroll-max-count=2; ./a.out\r\nchecksum = 6\r\n```\r\n\r\nHowever, when unrolled 3 times (not 2 or 4), the LoopUnroller creates a prologue loop, which is supposed to run extra iterations, as computed in the preheader (LoopUnrollRuntime.cpp:766):\r\n\r\n```\r\nfor.body5.preheader: ; preds = %for.cond2thread-pre-split\r\n %2 = sub i128 6, %.pr121517\r\n %3 = freeze i128 %2\r\n %4 = add i128 %3, 18446744073709551615\r\n %5 = urem i128 %4, 3\r\n %6 = add i128 %5, 1\r\n %xtraiter = urem i128 %6, 3\r\n %lcmp.mod = icmp ne i128 %xtraiter, 0\r\n br i1 %lcmp.mod, label %for.body5.prol.preheader, label %for.body5.prol.loopexit\r\n```\r\n\r\nThe constant used for %4 is actually is supposed to be i128 '-1', so UINT64_MAX (i64 -1) doesn't make sense.\r\n\r\ni128 <> i64, after LoopUnroller:\r\n```\r\n\r\nfor.body5.preheader: for.body5.preheader: \r\n %2 = sub i128 6, %.pr121517 | %2 = sub i64 6, %.pr121517\r\n %3 = freeze i128 %2 | %3 = freeze i64 %2\r\n %4 = add i128 %3, 18446744073709551615 | %4 = add i64 %3, -1\r\n %5 = urem i128 %4, 3 | %5 = urem i64 %4, 3\r\n %6 = add i128 %5, 1 | %6 = add i64 %5, 1\r\n %xtraiter = urem i128 %6, 3 | %xtraiter = urem i64 %6, 3\r\n %lcmp.mod = icmp ne i128 %xtraiter, 0 | %lcmp.mod = icmp ne i64 %xtraiter, 0\r\n br i1 %lcmp.mod, label %for.body5.prol.preh br i1 %lcmp.mod, label %for.body5.prol.preh\r\n```\r\n\r\n%4 is later optimized to a sub i128 with a folded constant of 18446744073709551621, which really should be '5'.\r\n\r\n@nikic @boxu-zhang @xiangzh1 @preames @uweigand \r\n\r\n\r\n", "author": "JonPsson1", "labels": [ "miscompilation", "loopoptim" ], "comments": [ { "author": "nikic", "body": "Classic mistake, https://github.com/llvm/llvm-project/blob/f956e7fbf161447b9236f7c4448a9d02d3564261/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp#L779 create an unsigned `-1` value." }, { "author": "nikic", "body": "As this is a recurring problem, I've started working on some sanity checks for APInt to solve this once and for all: https://github.com/llvm/llvm-project/pull/80309" } ] }
true
null
125357
https://github.com/llvm/llvm-project/issues/125357
crash
cdeeb390a9ea21540fc44ba10dede66fbc0b2fc8
2025-02-01T20:11:30
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "0c70a26f46e4efd5a29eb281ff99d2cf7f04c6f6", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 20147, 20153 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 0c70a26f46e4efd5a29eb281ff99d2cf7f04c6f6 Author: Alexey Bataev <[email protected]> Date: Mon Feb 3 04:37:49 2025 -0800 [SLP]Clear root node reordering only if the root node is not re-used in graph The reordering of the root node can be safely cleared only if the root node is not reused, otherwise the graph might be broken Fixes #125357 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4f83b9cfa18d..539c9227af7e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -20147,7 +20147,7 @@ public: } V.reorderTopToBottom(); // No need to reorder the root node at all. - V.reorderBottomToTop(/*IgnoreReorder=*/true); + V.reorderBottomToTop(!V.doesRootHaveInTreeUses()); // Keep extracted other reduction values, if they are used in the // vectorization trees. BoUpSLP::ExtraValueToDebugLocsMap LocalExternallyUsedValues(
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/root-node-reordered-reused.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "; ModuleID = 'test.ll'\nsource_filename = \"test.c\"\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i32 %0) {\nentry:\n %tobool.not = icmp eq i32 %0, 0\n br i1 %tobool.not, label %if.end6, label %if.then\n\nif.then: ; preds = %entry\n br i1 %tobool.not, label %if.end, label %i\n\nif.end: ; preds = %if.then\n br i1 %tobool.not, label %if.end6, label %i\n\nif.end6: ; preds = %if.end, %entry\n %h.0 = phi i32 [ %0, %if.end ], [ 0, %entry ]\n br i1 %tobool.not, label %i, label %if.end13\n\ni: ; preds = %if.end13, %if.end6, %if.end, %if.then\n %h.1 = phi i32 [ %0, %if.then ], [ %h.2, %if.end13 ], [ %0, %if.end ], [ %h.0, %if.end6 ]\n %j.0 = phi i32 [ undef, %if.then ], [ %j.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %k.0 = phi i32 [ undef, %if.then ], [ %k.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %l.0 = phi i32 [ undef, %if.then ], [ %l.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %or = or i32 %j.0, %h.1\n %or9 = or i32 %or, %k.0\n %or10 = or i32 %or9, %l.0\n %tobool11.not = icmp eq i32 %or10, 0\n br i1 %tobool11.not, label %if.end13, label %land.rhs\n\nland.rhs: ; preds = %i\n br label %if.end13\n\nif.end13: ; preds = %i, %land.rhs, %if.end6\n %h.2 = phi i32 [ %h.0, %if.end6 ], [ %h.1, %land.rhs ], [ %h.1, %i ]\n %j.1 = phi i32 [ %0, %if.end6 ], [ %j.0, %land.rhs ], [ %j.0, %i ]\n %k.1 = phi i32 [ %0, %if.end6 ], [ %k.0, %land.rhs ], [ %k.0, %i ]\n %l.1 = phi i32 [ %0, %if.end6 ], [ %l.0, %land.rhs ], [ %l.0, %i ]\n br i1 true, label %if.end15, label %i\n\nif.end15: ; preds = %if.end13\n ret i32 0\n\n; uselistorder directives\n uselistorder i32 %k.0, { 1, 2, 0 }\n uselistorder i32 %l.0, { 1, 2, 0 }\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `TE->isSame(VL) && \"Expected same scalars.\"' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/6ca9841xE\n\n```\n[512] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 7612dcc6e8d8e7f19b364084effbb01946294720)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[513] % \n[513] % clangtk -O3 small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3011: llvm::slpvectorizer::BoUpSLP::TreeEntry* llvm::slpvectorizer::BoUpSLP::getVectorizedOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int): Assertion `TE->isSame(VL) && \"Expected same scalars.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250201-clangtk-m64-O3-build-174536/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250201-clangtk-m64-O3-build-174536/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/21 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-b035e7.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x00005596296c84af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x479d4af)\n #1 0x00005596296c5c84 SignalHandler(int) Signals.cpp:0:0\n #2 0x00007fe817057420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007fe816a8e00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007fe816a6d859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007fe816a6d729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007fe816a6d729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007fe816a7efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x000055962b1df5c7 llvm::slpvectorizer::BoUpSLP::getSpillCost() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x62b45c7)\n #9 0x000055962b243030 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6318030)\n#10 0x000055962b247f34 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#11 0x000055962b24a205 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x631f205)\n#12 0x000055962b24ee25 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6323e25)\n#13 0x000055962b24fedb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#14 0x000055962b253720 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6328720)\n#15 0x000055962b259f46 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\n#16 0x000055962b25aaa3 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x632faa3)\n#17 0x000055962ac7c7e6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5d517e6)\n#18 0x000055962903ed49 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4113d49)\n#19 0x000055962693a376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1a0f376)\n#20 0x000055962903d5b2 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x41125b2)\n#21 0x0000559626938aa6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1a0daa6)\n#22 0x000055962903cfd1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4111fd1)\n#23 0x0000559629991596 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#24 0x0000559629995253 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4a6a253)\n#25 0x000055962a09f2ce clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51742ce)\n#26 0x000055962ba0f29c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6ae429c)\n#27 0x000055962a09f708 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5174708)\n#28 0x000055962a3719d9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x54469d9)\n#29 0x000055962a2f25be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x53c75be)\n#30 0x000055962a466746 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x553b746)\n#31 0x00005596264d4a87 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a9a87)\n#32 0x00005596264cc33a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x00005596264d0471 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a5471)\n#34 0x00005596263bb29b main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x149029b)\n#35 0x00007fe816a6f083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#36 0x00005596264cbdce _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a0dce)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 7612dcc6e8d8e7f19b364084effbb01946294720)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-401f68.c\nclangtk: note: diagnostic msg: /tmp/small-401f68.sh\nclangtk: note: diagnostic msg: \n\n********************\n[514] % \n[514] % cat small.c\nint a, b, c, d, e;\nvolatile int f;\nint main() {\n int h = 0, j, k, l;\n if (d) {\n h = c;\n if (f)\n goto i;\n if (f)\n goto i;\n }\n l = j = k = d;\n if (!b)\n i:\n (l | (h | j) | k) && f;\n if (a != e)\n goto i;\n return 0;\n}\n```\n\n\n", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/TWadzP8Gc\n" } ] }
true
null
97330
https://github.com/llvm/llvm-project/issues/97330
miscompilation
fdcfb277465e4530e5837fb8a95031794e58cb9b
2024-07-01T17:37:19
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "b558ac0eef57a3737b1e27844115fa91e0b32582", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [ [ 545, 554 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ [ 91, 98 ], [ 124, 173 ], [ 1105, 1117 ], [ 1119, 1131 ] ], "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ "InstCombinerImpl::SimplifyDemandedBits", "InstCombinerImpl::SimplifyDemandedUseBits" ], "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit b558ac0eef57a3737b1e27844115fa91e0b32582 Author: Nikita Popov <[email protected]> Date: Tue Jul 2 10:08:45 2024 +0200 [InstCombine] Fix context for multi-use demanded bits simplification When simplifying a multi-use root value, the demanded bits were reset to full, but we also need to reset the context extract. To make this convenient (without requiring by-value passing of SimplifyQuery), move the logic that that handles constants and dispatches to SimplifyDemandedUseBits/SimplifyMultipleUseDemandedBits into SimplifyDemandedBits. The SimplifyDemandedInstructionBits caller starts with full demanded bits and an appropriate context anyway. The different context instruction does mean that the ephemeral value protection no longer triggers in some cases, as the changes to assume tests show. An alternative, which I will explore in a followup, is to always use SimplifyMultipleUseDemandedBits() -- the previous root special case is only really intended for SimplifyDemandedInstructionBits(), which now no longer shares this code path. Fixes https://github.com/llvm/llvm-project/issues/97330. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 318c455fd7ef..64fbcc80e0ed 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -545,10 +545,11 @@ public: ConstantInt *&Less, ConstantInt *&Equal, ConstantInt *&Greater); - /// Attempts to replace V with a simpler value based on the demanded + /// Attempts to replace I with a simpler value based on the demanded /// bits. - Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known, - unsigned Depth, const SimplifyQuery &Q); + Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask, + KnownBits &Known, unsigned Depth, + const SimplifyQuery &Q); using InstCombiner::SimplifyDemandedBits; bool SimplifyDemandedBits(Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 6cf2e71363ab..b1d03786f321 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -91,8 +91,47 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { Use &U = I->getOperandUse(OpNo); - Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known, - Depth, Q); + Value *V = U.get(); + if (isa<Constant>(V)) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Known.resetAll(); + if (DemandedMask.isZero()) { + // Not demanding any bits from V. + replaceUse(U, UndefValue::get(V->getType())); + return true; + } + + if (Depth == MaxAnalysisRecursionDepth) + return false; + + Instruction *VInst = dyn_cast<Instruction>(V); + if (!VInst) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Value *NewVal; + if (VInst->hasOneUse()) { + // If the instruction has one use, we can directly simplify it. + NewVal = SimplifyDemandedUseBits(VInst, DemandedMask, Known, Depth, Q); + } else if (Depth != 0) { + // If there are multiple uses of this instruction and we aren't at the root, + // then we can simplify VInst to some other value, but not modify the + // instruction. + NewVal = + SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); + } else { + // If this is the root being simplified, allow it to have multiple uses, + // just set the DemandedMask to all bits and reset the context instruction. + // This allows visitTruncInst (for example) to simplify the operand of a + // trunc without duplicating all the SimplifyDemandedUseBits() logic. + NewVal = + SimplifyDemandedUseBits(VInst, APInt::getAllOnes(Known.getBitWidth()), + Known, Depth, Q.getWithInstruction(VInst)); + } if (!NewVal) return false; if (Instruction* OpInst = dyn_cast<Instruction>(U)) salvageDebugInfo(*OpInst); @@ -124,50 +163,21 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, /// operands based on the information about what bits are demanded. This returns /// some other non-null value if it found out that V is equal to another value /// in the context where the specified bits are demanded, but not for all users. -Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, +Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, + const APInt &DemandedMask, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { - assert(V != nullptr && "Null pointer of Value???"); + assert(I != nullptr && "Null pointer of Value???"); assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); uint32_t BitWidth = DemandedMask.getBitWidth(); - Type *VTy = V->getType(); + Type *VTy = I->getType(); assert( (!VTy->isIntOrIntVectorTy() || VTy->getScalarSizeInBits() == BitWidth) && Known.getBitWidth() == BitWidth && "Value *V, DemandedMask and Known must have same BitWidth"); - if (isa<Constant>(V)) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; - } - - Known.resetAll(); - if (DemandedMask.isZero()) // Not demanding any bits from V. - return UndefValue::get(VTy); - - if (Depth == MaxAnalysisRecursionDepth) - return nullptr; - - Instruction *I = dyn_cast<Instruction>(V); - if (!I) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; // Only analyze instructions. - } - - // If there are multiple uses of this value and we aren't at the root, then - // we can't do any simplifications of the operands, because DemandedMask - // only reflects the bits demanded by *one* of the users. - if (Depth != 0 && !I->hasOneUse()) - return SimplifyMultipleUseDemandedBits(I, DemandedMask, Known, Depth, Q); - KnownBits LHSKnown(BitWidth), RHSKnown(BitWidth); - // If this is the root being simplified, allow it to have multiple uses, - // just set the DemandedMask to all bits so that we can try to simplify the - // operands. This allows visitTruncInst (for example) to simplify the - // operand of a trunc without duplicating all the logic below. - if (Depth == 0 && !V->hasOneUse()) - DemandedMask.setAllBits(); // Update flags after simplifying an operand based on the fact that some high // order bits are not demanded. @@ -1105,13 +1115,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, } if (!KnownBitsComputed) - llvm::computeKnownBits(V, Known, Depth, Q); + llvm::computeKnownBits(I, Known, Depth, Q); break; } } - if (V->getType()->isPointerTy()) { - Align Alignment = V->getPointerAlignment(DL); + if (I->getType()->isPointerTy()) { + Align Alignment = I->getPointerAlignment(DL); Known.Zero.setLowBits(Log2(Alignment)); } @@ -1119,13 +1129,14 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // constant. We can't directly simplify pointers as a constant because of // pointer provenance. // TODO: We could return `(inttoptr const)` for pointers. - if (!V->getType()->isPointerTy() && DemandedMask.isSubsetOf(Known.Zero | Known.One)) + if (!I->getType()->isPointerTy() && + DemandedMask.isSubsetOf(Known.Zero | Known.One)) return Constant::getIntegerValue(VTy, Known.One); if (VerifyKnownBits) { - KnownBits ReferenceKnown = llvm::computeKnownBits(V, Depth, Q); + KnownBits ReferenceKnown = llvm::computeKnownBits(I, Depth, Q); if (Known != ReferenceKnown) { - errs() << "Mismatched known bits for " << *V << " in " + errs() << "Mismatched known bits for " << *I << " in " << I->getFunction()->getName() << "\n"; errs() << "computeKnownBits(): " << ReferenceKnown << "\n"; errs() << "SimplifyDemandedBits(): " << Known << "\n";
[ { "file": "llvm/test/Transforms/InstCombine/assume-inseltpoison.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "PR40940", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i32 @PR40940(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 1, i32 1, i32 2, i32 3>\n %t2 = bitcast <4 x i8> %shuf to i32\n %t3 = icmp ult i32 %t2, 65536\n call void @llvm.assume(i1 %t3)\n ret i32 %t2\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/assume.ll", "commands": [ "opt < %s -passes=instcombine -S", "opt < %s -passes=instcombine --enable-knowledge-retention -S", "opt < %s -passes=instcombine -S --try-experimental-debuginfo-iterators", "opt < %s -passes=instcombine --enable-knowledge-retention -S --try-experimental-debuginfo-iterators" ], "tests": [ { "test_name": "PR40940", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i32 @PR40940(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 1, i32 1, i32 2, i32 3>\n %t2 = bitcast <4 x i8> %shuf to i32\n %t3 = icmp ult i32 %t2, 65536\n call void @llvm.assume(i1 %t3)\n ret i32 %t2\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n\n!llvm.dbg.cu = !{}\n!llvm.module.flags = !{!0, !1, !2, !3}\n\n!0 = !{i32 2, !\"Dwarf Version\", i32 4}\n!1 = !{i32 2, !\"Debug Info Version\", i32 3}\n!2 = !{i32 1, !\"wchar_size\", i32 4}\n!3 = !{i32 8, !\"PIC Level\", i32 2}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/InstCombine/known-bits.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "simplifydemanded_context", "test_body": "define i8 @simplifydemanded_context(i8 %x, i8 %y) {\n %and1 = and i8 %x, 1\n call void @dummy()\n %x.lobits = and i8 %x, 3\n %precond = icmp eq i8 %x.lobits, 0\n call void @llvm.assume(i1 %precond)\n %and2 = and i8 %and1, %y\n ret i8 %and2\n}\n\ndeclare void @dummy()\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr97330", "test_body": "define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) {\nentry:\n %v = load i64, ptr %p1, align 8\n %conv = trunc i64 %v to i16\n br i1 %c, label %exit, label %if\n\nif: ; preds = %entry\n %cmp = icmp ne i16 %conv, 1\n %conv2 = zext i1 %cmp to i32\n store i32 %conv2, ptr %p2, align 4\n %cmp2 = icmp eq i64 %v, 1\n call void @llvm.assume(i1 %cmp2)\n unreachable\n\nexit: ; preds = %entry\n ret i16 %conv\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Miscompilation with llvm.assume in unreachable blocks", "body": "Reproducer: https://alive2.llvm.org/ce/z/zKvpXV\r\n```\r\n; bin/opt -passes=instcombine reduced.ll -S\r\ndefine i16 @src(i16 %g, ptr %e, ptr %d) {\r\nentry:\r\n %0 = load i64, ptr %d, align 8\r\n %conv = trunc i64 %0 to i16\r\n %tobool.not.i = icmp eq i16 %g, 0\r\n br i1 %tobool.not.i, label %i.exit, label %for.cond.preheader.i\r\n\r\nfor.cond.preheader.i:\r\n %cmp5.i = icmp ne i16 %g, %conv\r\n %conv6.i = zext i1 %cmp5.i to i32\r\n store i32 %conv6.i, ptr %e, align 4\r\n %cmp7.i = icmp eq i64 %0, 1\r\n call void @llvm.assume(i1 %cmp7.i)\r\n unreachable\r\n\r\ni.exit:\r\n ret i16 %conv\r\n}\r\n```\r\n```\r\ndefine i16 @tgt(i16 %g, ptr %e, ptr %d) {\r\nentry:\r\n %tobool.not.i = icmp eq i16 %g, 0\r\n br i1 %tobool.not.i, label %i.exit, label %for.cond.preheader.i\r\n\r\nfor.cond.preheader.i: ; preds = %entry\r\n unreachable\r\n\r\ni.exit: ; preds = %entry\r\n ret i16 1\r\n}\r\n```\r\n\r\nllvm version: a8e1c3e1239604ac787b6a2d39b5278ddec8aa8a\r\n\r\ncc @nikic", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reverting https://github.com/llvm/llvm-project/commit/11484cb817bcc2a6e2ef9572be982a1a5a4964ec fixes this issue.\r\n" }, { "author": "nikic", "body": "I've applied two fixes for this. https://github.com/llvm/llvm-project/commit/86b37944a70229b07626e63bdb9a46b4bc3d1460 tries to stick closer to the current logic, while https://github.com/llvm/llvm-project/commit/05670b42f5b45710bfdba48dcb7e8c30c8c7478f is a more thorough fix on top of that." }, { "author": "dtcxzyw", "body": "Confirmed that the original case has been fixed. Thank you!\r\n" }, { "author": "chapuni", "body": "@nikic Fixed, thanks!" } ] }
true
null
108698
https://github.com/llvm/llvm-project/issues/108698
miscompilation
ba8e4246e2f17030788e8a4954bf5c290332206f
2024-09-14T13:16:53
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "87663fdab9d0e7bcc0b963ea078da9e2eb574908", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 2597, 2607 ], [ 2628, 2634 ] ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::shrinkType" ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 87663fdab9d0e7bcc0b963ea078da9e2eb574908 Author: Yingwei Zheng <[email protected]> Date: Sun Sep 15 18:38:06 2024 +0800 [VectorCombine] Don't shrink lshr if the shamt is not less than bitwidth (#108705) Consider the following case: ``` define <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) { %19 = icmp eq <2 x i64> %vec.ind16, zeroinitializer %20 = zext <2 x i1> %19 to <2 x i32> %21 = lshr <2 x i32> %20, %broadcast.splat20 ret <2 x i32> %21 } ``` After https://github.com/llvm/llvm-project/pull/104606, we shrink the lshr into: ``` define <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) { %1 = icmp eq <2 x i64> %vec.ind16, zeroinitializer %2 = trunc <2 x i32> %broadcast.splat20 to <2 x i1> %3 = lshr <2 x i1> %1, %2 %4 = zext <2 x i1> %3 to <2 x i32> ret <2 x i32> %4 } ``` It is incorrect since `lshr i1 X, 1` returns `poison`. This patch adds additional check on the shamt operand. The lshr will get shrunk iff we ensure that the shamt is less than bitwidth of the smaller type. As `computeKnownBits(&I, *DL).countMaxActiveBits() > BW` always evaluates to true for `lshr(zext(X), Y)`, this check will only apply to bitwise logical instructions. Alive2: https://alive2.llvm.org/ce/z/j_RmTa Fixes https://github.com/llvm/llvm-project/issues/108698. diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index d7afe2f426d3..58701bfa60a3 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -2597,11 +2597,19 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) { auto *SmallTy = cast<FixedVectorType>(ZExted->getType()); unsigned BW = SmallTy->getElementType()->getPrimitiveSizeInBits(); - // Check that the expression overall uses at most the same number of bits as - // ZExted - KnownBits KB = computeKnownBits(&I, *DL); - if (KB.countMaxActiveBits() > BW) - return false; + if (I.getOpcode() == Instruction::LShr) { + // Check that the shift amount is less than the number of bits in the + // smaller type. Otherwise, the smaller lshr will return a poison value. + KnownBits ShAmtKB = computeKnownBits(I.getOperand(1), *DL); + if (ShAmtKB.getMaxValue().uge(BW)) + return false; + } else { + // Check that the expression overall uses at most the same number of bits as + // ZExted + KnownBits KB = computeKnownBits(&I, *DL); + if (KB.countMaxActiveBits() > BW) + return false; + } // Calculate costs of leaving current IR as it is and moving ZExt operation // later, along with adding truncates if needed @@ -2628,7 +2636,7 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) { return false; // Check if we can propagate ZExt through its other users - KB = computeKnownBits(UI, *DL); + KnownBits KB = computeKnownBits(UI, *DL); if (KB.countMaxActiveBits() > BW) return false;
[ { "file": "llvm/test/Transforms/VectorCombine/AArch64/shrink-types.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "pr108698", "test_body": "target triple = \"aarch64\"\n\ndefine <2 x i32> @pr108698(<2 x i64> %x, <2 x i32> %y) {\n %cmp = icmp eq <2 x i64> %x, zeroinitializer\n %ext = zext <2 x i1> %cmp to <2 x i32>\n %lshr = lshr <2 x i32> %ext, %y\n ret <2 x i32> %lshr\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "wrong code at -O{2,3} on x86_64-linux-gnu", "body": "It appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier. \r\n\r\nCompiler Explorer: https://godbolt.org/z/EGasYh8x1\r\n\r\n```\r\n[691] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 223e2efa5e886502a9467b7ef700ebce9b7886e8)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[692] % \r\n[692] % clangtk -O1 small.c; ./a.out\r\n[693] % \r\n[693] % clangtk -O2 small.c\r\n[694] % ./a.out\r\nAborted\r\n[695] % \r\n[695] % cat small.c\r\nchar a[8];\r\nint b = 1, c;\r\nint main() {\r\n for (; c < 8; c++)\r\n a[c] = !c >> b;\r\n if (a[0] != 0)\r\n __builtin_abort();\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "miscompilation", "vectorizers" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/5SkPZS\r\n```\r\n; bin/opt -passes=vector-combine test.ll -S\r\n\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 <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) {\r\n %19 = icmp eq <2 x i64> %vec.ind16, zeroinitializer\r\n %20 = zext <2 x i1> %19 to <2 x i32>\r\n %21 = lshr <2 x i32> %20, %broadcast.splat20\r\n ret <2 x i32> %21\r\n}\r\n```\r\n```\r\ndefine <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) {\r\n %1 = icmp eq <2 x i64> %vec.ind16, zeroinitializer\r\n %2 = trunc <2 x i32> %broadcast.splat20 to <2 x i1>\r\n %3 = lshr <2 x i1> %1, %2\r\n %4 = zext <2 x i1> %3 to <2 x i32>\r\n ret <2 x i32> %4\r\n}\r\n```" }, { "author": "dtcxzyw", "body": "Related PR: https://github.com/llvm/llvm-project/pull/104606\r\n" } ] }
true
null
134085
https://github.com/llvm/llvm-project/issues/134085
crash
f475ccd3794ebce22950b707ad390fae7e235b46
2025-04-02T13:46:38
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "843ef77dc22afd1923b891acd4c46c8f8c8c93ae", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 14335, 14341 ], [ 14552, 14557 ], [ 14596, 14601 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledSingleRegisterEntry" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 843ef77dc22afd1923b891acd4c46c8f8c8c93ae Author: Alexey Bataev <[email protected]> Date: Wed Apr 2 11:44:36 2025 -0700 [SLP]Update mapping between values and their matching entries upon selection Need to update the mapping between gathered values and their matching entries, if the list of the entries is updated and only some of them are selected for final shuffling. Fixes #134085 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 838e952c024c..b82a66ca3b88 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14335,7 +14335,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( // single vector. If we have 2 different sets, we're in situation where we // have a permutation of 2 input vectors. SmallVector<SmallPtrSet<const TreeEntry *, 4>> UsedTEs; - DenseMap<Value *, int> UsedValuesEntry; + SmallDenseMap<Value *, int> UsedValuesEntry; SmallPtrSet<const Value *, 16> VisitedValue; auto CheckAndUseSameNode = [&](const TreeEntry *TEPtr) { // The node is reused - exit. @@ -14552,6 +14552,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( // No perfect match, just shuffle, so choose the first tree node from the // tree. Entries.push_back(FirstEntries.front()); + // Update mapping between values and corresponding tree entries. + for_each(UsedValuesEntry, [&](auto &P) { P.second = 0; }); VF = FirstEntries.front()->getVectorFactor(); } else { // Try to find nodes with the same vector factor. @@ -14596,6 +14598,18 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( } else { VF = Entries.front()->getVectorFactor(); } + SmallVector<SmallPtrSet<Value *, 8>> ValuesToEntries; + for (const TreeEntry *E : Entries) + ValuesToEntries.emplace_back().insert(E->Scalars.begin(), + E->Scalars.end()); + // Update mapping between values and corresponding tree entries. + for_each(UsedValuesEntry, [&](auto &P) { + for (unsigned Idx : seq<unsigned>(ValuesToEntries.size())) + if (ValuesToEntries[Idx].contains(P.first)) { + P.second = Idx; + break; + } + }); } bool IsSplatOrUndefs = isSplat(VL) || all_of(VL, IsaPred<UndefValue>);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/matched-nodes-updated.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i32 %s.0) {\nentry:\n br label %k\n\nk: ; preds = %t, %entry\n %.pre = phi i32 [ 0, %entry ], [ %.pre4053, %t ]\n br label %o\n\nif.end3: ; No predecessors!\n br label %if.end6\n\nif.end6: ; preds = %o, %if.end3\n %.pre43 = phi i32 [ 0, %if.end3 ], [ 0, %o ]\n %0 = phi i32 [ 0, %if.end3 ], [ 0, %o ]\n %1 = phi i32 [ 0, %if.end3 ], [ 0, %o ]\n %h.4 = phi i32 [ 0, %if.end3 ], [ %h.6, %o ]\n %i.4 = phi i32 [ 0, %if.end3 ], [ %i.7, %o ]\n %j.4 = phi i32 [ 0, %if.end3 ], [ %j.5, %o ]\n %l.4 = phi i32 [ 0, %if.end3 ], [ 0, %o ]\n %not8 = xor i32 %i.4, 0\n %not9 = xor i32 %h.4, 0\n br i1 false, label %if.end24, label %if.then11\n\nif.then11: ; preds = %if.end6\n br label %if.end24\n\nif.then18: ; No predecessors!\n br label %t\n\nt: ; preds = %o, %if.then18\n %.pre40 = phi i32 [ %.pre4053, %o ], [ 0, %if.then18 ]\n %i.5 = phi i32 [ 0, %o ], [ 0, %if.then18 ]\n %l.5 = phi i32 [ %l.7, %o ], [ 0, %if.then18 ]\n %r.2 = phi i32 [ %r.4, %o ], [ 0, %if.then18 ]\n %s.2 = phi i32 [ %s.4, %o ], [ 0, %if.then18 ]\n br i1 false, label %if.end24, label %k\n\nif.end24: ; preds = %t, %if.then11, %if.end6\n %.pre4050 = phi i32 [ 0, %if.then11 ], [ 0, %if.end6 ], [ %.pre40, %t ]\n %.pre42 = phi i32 [ 0, %if.then11 ], [ %.pre43, %if.end6 ], [ %.pre40, %t ]\n %2 = phi i32 [ 0, %if.then11 ], [ %0, %if.end6 ], [ %.pre40, %t ]\n %3 = phi i32 [ 0, %if.then11 ], [ %1, %if.end6 ], [ %.pre40, %t ]\n %i.6 = phi i32 [ %i.4, %if.then11 ], [ %i.7, %if.end6 ], [ %i.5, %t ]\n %l.6 = phi i32 [ 0, %if.then11 ], [ %l.4, %if.end6 ], [ %l.5, %t ]\n %r.3 = phi i32 [ %j.4, %if.then11 ], [ %not8, %if.end6 ], [ %r.2, %t ]\n %s.3 = phi i32 [ 0, %if.then11 ], [ %not9, %if.end6 ], [ %s.2, %t ]\n br label %o\n\no: ; preds = %if.end24, %k\n %.pre4053 = phi i32 [ 0, %k ], [ %.pre4050, %if.end24 ]\n %.pre46 = phi i32 [ 0, %k ], [ %.pre42, %if.end24 ]\n %4 = phi i32 [ 0, %k ], [ %2, %if.end24 ]\n %5 = phi i32 [ 0, %k ], [ %3, %if.end24 ]\n %h.6 = phi i32 [ 0, %k ], [ %r.3, %if.end24 ]\n %i.7 = phi i32 [ 0, %k ], [ %i.6, %if.end24 ]\n %j.5 = phi i32 [ 0, %k ], [ %s.3, %if.end24 ]\n %l.7 = phi i32 [ %.pre, %k ], [ %l.6, %if.end24 ]\n %r.4 = phi i32 [ 0, %k ], [ %r.3, %if.end24 ]\n %s.4 = phi i32 [ %s.0, %k ], [ %s.3, %if.end24 ]\n br i1 false, label %t, label %if.end6\n\n; uselistorder directives\n uselistorder i32 %.pre4053, { 1, 0 }\n uselistorder i32 %i.7, { 1, 0 }\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes at -O{s,2,3} on x86_64-linux-gnu: Assertion `idx < size()' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 20.1.0.\n\nCompiler Explorer: https://godbolt.org/z/nKW8o5f8a\n\n```\n[516] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 842785adf7349f07a91320d49ff8a10971e04409)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[517] % \n[517] % clangtk -O3 small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/ADT/SmallVector.h:291: T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) [with T = const llvm::slpvectorizer::BoUpSLP::TreeEntry*; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::reference = const llvm::slpvectorizer::BoUpSLP::TreeEntry*&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250402-clangtk-m64-O3-build-141643/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250402-clangtk-m64-O3-build-141643/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/21 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-1ffa5d.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x000055aa281b4bff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x459bbff)\n #1 0x000055aa281b23b4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007f3259793420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007f32591ca00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007f32591a9859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007f32591a9729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007f32591a9729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007f32591bafd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x000055aa29cd9e82 llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::MutableArrayRef<int>, llvm::SmallVectorImpl<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>&, unsigned int, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60c0e82)\n #9 0x000055aa29cda9f8 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60c19f8)\n#10 0x000055aa29cdb803 llvm::slpvectorizer::BoUpSLP::findReusedOrderedScalars(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60c2803)\n#11 0x000055aa29d11537 llvm::slpvectorizer::BoUpSLP::getReorderingData(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60f8537)\n#12 0x000055aa29d15fc6 llvm::slpvectorizer::BoUpSLP::reorderBottomToTop(bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60fcfc6)\n#13 0x000055aa29d236d8 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x610a6d8)\n#14 0x000055aa29d28bdd bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#15 0x000055aa29d2a5d1 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x61115d1)\n#16 0x000055aa29d3268e 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\n#17 0x000055aa29d33253 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x611a253)\n#18 0x000055aa2979da56 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5b84a56)\n#19 0x000055aa27b29009 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3f10009)\n#20 0x000055aa253f1e66 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x17d8e66)\n#21 0x000055aa27b27882 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3f0e882)\n#22 0x000055aa253ef826 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x17d6826)\n#23 0x000055aa27b272a1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3f0e2a1)\n#24 0x000055aa28473351 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#25 0x000055aa28476c41 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x485dc41)\n#26 0x000055aa28b92391 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f79391)\n#27 0x000055aa2a56658c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x694d58c)\n#28 0x000055aa28b927c8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f797c8)\n#29 0x000055aa28e8fcb9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5276cb9)\n#30 0x000055aa28e0f98e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51f698e)\n#31 0x000055aa28f86ae6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x536dae6)\n#32 0x000055aa24f83afd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x136aafd)\n#33 0x000055aa24f7b08a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#34 0x000055aa24f7f312 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1366312)\n#35 0x000055aa24e62f8b main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1249f8b)\n#36 0x00007f32591ab083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#37 0x000055aa24f7ab1e _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1361b1e)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 842785adf7349f07a91320d49ff8a10971e04409)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-a83f08.c\nclangtk: note: diagnostic msg: /tmp/small-a83f08.sh\nclangtk: note: diagnostic msg: \n\n********************\n[518] % \n[518] % cat small.c\nint printf(const char *, ...);\nint a, b, c, d;\nint main() {\n int g = 1, h = 0, i, j;\nk:\n if (g) {\n int l = a, n;\n m:\n n = d;\n if (n)\n goto o;\n j = l;\n }\n int p = a / ~b;\n if (g)\n q:\n b = a;\n c = p;\n int r = g ? 0 : ~i, s = ~h;\n if (g) {\n r = j;\n if (b && 0 <= i) {\n if (h) {\n g = 0;\n goto m;\n }\n i = a = -a;\n if (a)\n printf(\"0\");\n t:\n j = 0;\n if (d)\n goto k;\n }\n }\n h = r;\n j = s;\n if (a) {\n o:\n if (a && i)\n goto t;\n goto q;\n }\n return 0;\n}\n```", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/E7zsza3bT" } ] }
true
null
140345
https://github.com/llvm/llvm-project/issues/140345
crash
3702d64801c872bf41a29b0aabda868ab3e26f12
2025-05-17T04:00:17
[ "llvm/test/Transforms/FunctionAttrs" ]
{ "fix_commit": "e44fbea0a17f468d45de5eaef158642f067f678c", "components": [ "FunctionAttrs" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": [ [ 675, 688 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": [ "getArgumentAccessInfo" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit e44fbea0a17f468d45de5eaef158642f067f678c Author: Shivam Gupta <[email protected]> Date: Tue Jul 1 18:34:52 2025 +0530 [FunctionAttrs] Handle ConstantRange overflow in memset initializes inference (#145739) Avoid constructing invalid ConstantRange when Offset + Length in memset overflows signed 64-bit integer space. This prevents assertion failures when inferring the initializes attribute. Fixes #140345 diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index f918d7e059b6..f43202eea630 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -675,14 +675,24 @@ ArgumentAccessInfo getArgumentAccessInfo(const Instruction *I, [](Value *Length, std::optional<int64_t> Offset) -> std::optional<ConstantRange> { auto *ConstantLength = dyn_cast<ConstantInt>(Length); - if (ConstantLength && Offset && - ConstantLength->getValue().isStrictlyPositive()) { - return ConstantRange( - APInt(64, *Offset, true), - APInt(64, *Offset + ConstantLength->getSExtValue(), true)); + if (ConstantLength && Offset) { + int64_t Len = ConstantLength->getSExtValue(); + + // Reject zero or negative lengths + if (Len <= 0) + return std::nullopt; + + APInt Low(64, *Offset, true); + bool Overflow; + APInt High = Low.sadd_ov(APInt(64, Len, true), Overflow); + if (Overflow) + return std::nullopt; + + return ConstantRange(Low, High); } return std::nullopt; }; + if (auto *SI = dyn_cast<StoreInst>(I)) { if (SI->isSimple() && &SI->getOperandUse(1) == ArgUse.U) { // Get the fixed type size of "SI". Since the access range of a write
[ { "file": "llvm/test/Transforms/FunctionAttrs/initializes.ll", "commands": [ "opt -passes=function-attrs -S < %s" ], "tests": [ { "test_name": "range_overflows_signed_64_bit_int", "test_body": "define void @range_overflows_signed_64_bit_int(ptr %arg) {\n %getelementptr = getelementptr i8, ptr %arg, i64 9223372036854775804\n store i32 0, ptr %getelementptr, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "memset_large_offset_nonzero_size", "test_body": "define void @memset_large_offset_nonzero_size(ptr %dst) {\n %offset = getelementptr inbounds i8, ptr %dst, i64 9223372036854775805\n call void @llvm.memset.p0.i64(ptr %offset, i8 0, i64 3, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i64(ptr writeonly captures(none), i8, i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Assertion `NewRange.getLower().slt(NewRange.getUpper())' failed.", "body": "Reproducer:\nhttps://godbolt.org/z/zYorscvnP\n```c\ntypedef __SIZE_TYPE__ size_t;\nvoid *memset(void *, int, size_t);\n\nvoid foo(char *p) {\n size_t idx = __PTRDIFF_MAX__ - 3;\n\n ++idx;\n memset(p + idx, 0, 3);\n}\n```\n\nThe original reproducer of this issue is the following:\nhttps://github.com/gcc-mirror/gcc/blob/master/gcc/testsuite/gcc.dg/Wstringop-overflow-50.c\n\nBacktrace:\n```console\nclang: /root/llvm-project/llvm/lib/IR/ConstantRangeList.cpp:41: void llvm::ConstantRangeList::insert(const llvm::ConstantRange&): Assertion `NewRange.getLower().slt(NewRange.getUpper())' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O1 <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,libcalls-shrinkwrap,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,loop-deletion,loop-unroll-full),sroa<modify-cfg>,memcpyopt,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,coro-elide,adce,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide)),function(invalidate<should-not-run-function-passes>),cgscc(devirt<4>())\" on module \"<source>\"\n4.\tRunning pass \"cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,libcalls-shrinkwrap,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,loop-deletion,loop-unroll-full),sroa<modify-cfg>,memcpyopt,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,coro-elide,adce,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide))\" on module \"<source>\"\n #0 0x0000000003f99d48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f99d48)\n #1 0x0000000003f979d4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f979d4)\n #2 0x0000000003edc608 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007ddca6042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007ddca60969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007ddca6042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007ddca60287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007ddca602871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007ddca6039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00000000037b41bb llvm::ConstantRangeList::insert(llvm::ConstantRange const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37b41bb)\n#10 0x000000000583e1cb inferInitializes(llvm::Argument&, llvm::Function&) FunctionAttrs.cpp:0:0\n#11 0x000000000583ef15 addArgumentAttrs(llvm::SmallSetVector<llvm::Function*, 8u> const&, llvm::SmallSet<llvm::Function*, 8u, std::less<llvm::Function*>>&, bool) FunctionAttrs.cpp:0:0\n#12 0x000000000584282e llvm::PostOrderFunctionAttrsPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x584282e)\n#13 0x000000000504fbae llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PostOrderFunctionAttrsPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x504fbae)\n#14 0x0000000002dd1dd2 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2dd1dd2)\n#15 0x00000000051aface llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x51aface)\n#16 0x0000000002dd74a6 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2dd74a6)\n#17 0x00000000051afaee llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x51afaee)\n#18 0x0000000002dd5376 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2dd5376)\n#19 0x00000000051afaae llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x51afaae)\n#20 0x00000000039326b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39326b0)\n#21 0x000000000589c503 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x589c503)\n#22 0x000000000504fb7e llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x504fb7e)\n#23 0x00000000039326b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39326b0)\n#24 0x000000000425330a (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#25 0x0000000004256381 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4256381)\n#26 0x0000000004944bd0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4944bd0)\n#27 0x000000000662d34c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x662d34c)\n#28 0x0000000004944fd8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4944fd8)\n#29 0x0000000004c3cea5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c3cea5)\n#30 0x0000000004bbbb3e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bbbb3e)\n#31 0x0000000004d30a49 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d30a49)\n#32 0x0000000000dac29f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdac29f)\n#33 0x0000000000da246a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#34 0x00000000049ac2c9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#35 0x0000000003edcaa4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3edcaa4)\n#36 0x00000000049ac8df clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#37 0x000000000496e6ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x496e6ad)\n#38 0x000000000496f73e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x496f73e)\n#39 0x0000000004977a25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4977a25)\n#40 0x0000000000da8208 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda8208)\n#41 0x0000000000c2df44 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc2df44)\n#42 0x00007ddca6029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#43 0x00007ddca6029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#44 0x0000000000da1f15 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda1f15)\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\nCompiler returned: 134\n```\n", "author": "k-arrows", "labels": [ "ipo", "crash", "regression:20" ], "comments": [ { "author": "shafik", "body": "Looks like a clang-20 regression: https://godbolt.org/z/Ya5zc8bf3" }, { "author": "xgupta", "body": "The crash started after - 4d6e69143dc449814884ac649583d3b35bc4ae91" } ] }
true
null
97452
https://github.com/llvm/llvm-project/issues/97452
crash
5c204b1d2619cbad7b7ad228b62feae08781a6db
2024-07-02T17:49:01
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2b3b405b09a0d965a4aff1f92958418ddbf1e7f6", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6813, 6818 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInstructionCost" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 2b3b405b09a0d965a4aff1f92958418ddbf1e7f6 Author: Florian Hahn <[email protected]> Date: Thu Jul 4 11:44:50 2024 +0100 [LV] Don't vectorize first-order recurrence with VF <vscale x 1 x ..> The assertion added as part of https://github.com/llvm/llvm-project/pull/93395 surfaced cases where first-order recurrences are vectorized with <vscale x 1 x ..>. If vscale is 1, then we are unable to extract the penultimate value (second to last lane). Previously this case got mis-compiled, trying to extract from an invalid lane (-1) https://llvm.godbolt.org/z/3adzYYcf9. Fixes https://github.com/llvm/llvm-project/issues/97452. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f9c0c66e6e0a..d7b0240fd8a8 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6813,6 +6813,11 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF, // First-order recurrences are replaced by vector shuffles inside the loop. if (VF.isVector() && Legal->isFixedOrderRecurrence(Phi)) { + // For <vscale x 1 x i64>, if vscale = 1 we are unable to extract the + // penultimate value of the recurrence. + // TODO: Consider vscale_range info. + if (VF.isScalable() && VF.getKnownMinValue() == 1) + return InstructionCost::getInvalid(); SmallVector<int> Mask(VF.getKnownMinValue()); std::iota(Mask.begin(), Mask.end(), VF.getKnownMinValue() - 1); return TTI.getShuffleCost(TargetTransformInfo::SK_Splice,
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/first-order-recurrence-scalable-vf1.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n; Make sure we do not pick <vscale x 1 x i64> as VF for a loop with a\n; first-order recurrence.\ndefine i64 @pr97452_scalable_vf1_for(ptr %src) #0 {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i64 [ 0, %entry ], [ %l, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep, align 8\n %ec = icmp eq i64 %iv, 22\n br i1 %ec, label %exit, label %loop\n\nexit:\n %res = phi i64 [ %for, %loop ]\n ret i64 %res\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl128b,+zvl256b\" }\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-scalable-vf1.ll", "commands": [ "opt -p loop-vectorize -scalable-vectorization=on -force-vector-width=1 -force-target-supports-scalable-vectors=true -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n\ndefine i64 @pr97452_scalable_vf1_for_live_out(ptr %src) {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i64 [ 0, %entry ], [ %l, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep, align 8\n %ec = icmp eq i64 %iv, 22\n br i1 %ec, label %exit, label %loop\n\nexit:\n %res = phi i64 [ %for, %loop ]\n ret i64 %res\n}\n\n\ndefine void @pr97452_scalable_vf1_for_no_live_out(ptr %src, ptr noalias %dst) {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i64 [ 0, %entry ], [ %l, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep, align 8\n %gep.dst = getelementptr inbounds i64, ptr %dst, i64 %iv\n store i64 %l, ptr %gep.dst\n %ec = icmp eq i64 %iv, 22\n br i1 %ec, label %exit, label %loop\n\nexit:\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize] Assertion `Offset <= State.VF.getKnownMinValue() && \"invalid offset to extract from\"' failed.", "body": "Reduced testcase:\r\n```llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main() #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %.lcssa17 = phi i64 [ %0, %for.body ]\r\n ret i32 0\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %0 = phi i64 [ 0, %entry ], [ %1, %for.body ]\r\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\r\n %indvars.iv.next = add i64 %indvars.iv, 1\r\n %1 = load i64, ptr null, align 8\r\n %exitcond.not = icmp eq i64 %indvars.iv, 22\r\n br i1 %exitcond.not, label %for.cond.cleanup, label %for.body\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl128b,+zvl256b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```bash\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll\r\nWARNING: You're attempting to print out a bitcode file.\r\nThis is inadvisable as it may cause display problems. If\r\nyou REALLY want to taste LLVM bitcode first-hand, you\r\ncan force output with the `-f' option.\r\n\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp:569: llvm::Value* llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int): Assertion `Offset <= State.VF.getKnownMinValue() && \"invalid offset to extract from\"' 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. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000055972ae01800 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ed2800)\r\n #1 0x000055972adfec0f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ecfc0f)\r\n #2 0x000055972adfed65 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000728161442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007281614969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007281614969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007281614969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000728161442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007281614287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000072816142871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000728161439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000559729f62d80 llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2033d80)\r\n#12 0x0000559729f63155 llvm::VPInstruction::execute(llvm::VPTransformState&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2034155)\r\n#13 0x0000559729f2de47 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffee47)\r\n#14 0x0000559729f2e141 llvm::VPIRBasicBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fff141)\r\n#15 0x0000559729f30286 llvm::VPlan::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2001286)\r\n#16 0x0000559729e2380a llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ef480a)\r\n#17 0x0000559729e34a7c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f05a7c)\r\n#18 0x0000559729e36f7e llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f07f7e)\r\n#19 0x0000559729e380a0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f090a0)\r\n#20 0x0000559728cc6dc6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xd97dc6)\r\n#21 0x000055972ac1ce46 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2cede46)\r\n#22 0x0000559728cc9f56 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xd9af56)\r\n#23 0x000055972ac1bbcb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2cecbcb)\r\n#24 0x0000559728cc6526 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xd97526)\r\n#25 0x000055972ac19d02 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2cead02)\r\n#26 0x0000559728520136 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) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5f1136)\r\n#27 0x0000559728511d51 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e2d51)\r\n#28 0x0000728161429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#29 0x0000728161429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#30 0x0000728161429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#31 0x0000559728507b85 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5d8b85)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nGodbolt: https://godbolt.org/z/ojz8sMa1r\r\n\r\nFound via fuzzer", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "svs-quic", "body": "Bisected to #93395 \r\ncc: @fhahn " }, { "author": "fhahn", "body": "Thanks for the test case. Should be fixed now. The assertion highlighted a case where we previously miscompiled for the case where VF is <vscale x 1 x ..>; in that case we are unable to extract the penultimate value (second-to-last) if vscale = 1" } ] }
true
null
126581
https://github.com/llvm/llvm-project/issues/126581
crash
c81139f417a209dbd2a4e06465483d4b0951a9ac
2025-02-10T19:26:42
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "d18b1ebef5f5e355d6cee2b2f48789a159a5d616", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 18467, 18474 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::computeMinimumValueSizes" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit d18b1ebef5f5e355d6cee2b2f48789a159a5d616 Author: Alexey Bataev <[email protected]> Date: Thu Feb 13 09:39:56 2025 -0800 [SLP]Check if vector user exist before accessing it Need to check if vector user exist before accessing it to avoid compiler crash. Fixes #126581 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index a337ab7410f7..fb72a112b9ac 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -18467,8 +18467,8 @@ void BoUpSLP::computeMinimumValueSizes() { any_of( VectorizableTree[NodeIdx]->UserTreeIndices, [&](const EdgeInfo &EI) { - return (EI.UserTE->hasState() && - EI.UserTE->getOpcode() == Instruction::ICmp) && + return EI.UserTE && EI.UserTE->hasState() && + EI.UserTE->getOpcode() == Instruction::ICmp && any_of(EI.UserTE->Scalars, [&](Value *V) { auto *IC = dyn_cast<ICmpInst>(V); return IC &&
[ { "file": "llvm/test/Transforms/SLPVectorizer/RISCV/check-node-without-vector-user.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr=+v < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@r = external global [8 x i8]\n\ndefine void @test(i64 %0, ptr %1) {\n;\n %3 = load i8, ptr @r, align 1\n %4 = trunc i8 %3 to i1\n %5 = select i1 %4, i64 %0, i64 0\n %6 = getelementptr i8, ptr @r, i64 %5\n %7 = load i8, ptr %6, align 1\n %8 = icmp ule i8 %3, %7\n %9 = sext i1 %8 to i32\n %10 = load i8, ptr getelementptr (i8, ptr @r, i64 -8049), align 1\n %11 = trunc i8 %10 to i1\n %12 = select i1 %11, i64 %0, i64 0\n %13 = getelementptr i8, ptr @r, i64 %12\n %14 = load i8, ptr %13, align 1\n %15 = icmp ule i8 %10, %14\n %16 = sext i1 %15 to i32\n %17 = add i32 %9, %16\n %18 = load i8, ptr getelementptr (i8, ptr @r, i64 -16098), align 1\n %19 = trunc i8 %18 to i1\n %20 = select i1 %19, i64 %0, i64 0\n %21 = getelementptr i8, ptr @r, i64 %20\n %22 = load i8, ptr %21, align 1\n %23 = icmp ule i8 %18, %22\n %24 = sext i1 %23 to i32\n %25 = add i32 %17, %24\n %26 = load i8, ptr getelementptr (i8, ptr @r, i64 -24147), align 1\n %27 = trunc i8 %26 to i1\n %28 = select i1 %27, i64 %0, i64 0\n %29 = getelementptr i8, ptr @r, i64 %28\n %30 = load i8, ptr %29, align 1\n %31 = icmp ule i8 %26, %30\n %32 = sext i1 %31 to i32\n %33 = add i32 %25, %32\n store i32 %33, ptr %1, align 4\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Segmentation Fault using opt \"-passes=lto<O3>\"", "body": "Testcase:\n```llvm ir\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n@a = external global i32\n@g = internal global i16 -8049\n@r = external global [8 x i8]\n\ndefine internal void @c(i16 %g, ptr %r) #0 {\nentry:\n br label %for.cond16.preheader.us.us.us.us\n\nfor.cond16.preheader.us.us.us.us: ; preds = %for.cond.cleanup20.split.us.us.us.us.us, %entry\n %indvars.iv133 = phi i64 [ %indvars.iv.next134, %for.cond.cleanup20.split.us.us.us.us.us ], [ 0, %entry ]\n br label %for.body21.us.us.us.us.us\n\nfor.body21.us.us.us.us.us: ; preds = %for.body21.us.us.us.us.us, %for.cond16.preheader.us.us.us.us\n %sub74.us.us.us.us124.us = phi i32 [ 0, %for.cond16.preheader.us.us.us.us ], [ %sub74.us.us.us.us.us, %for.body21.us.us.us.us.us ]\n %w.0109.us.us.us.us.us = phi i16 [ 0, %for.cond16.preheader.us.us.us.us ], [ %add77.us.us.us.us.us, %for.body21.us.us.us.us.us ]\n %idxprom38.us.us.us.us.us = sext i16 %w.0109.us.us.us.us.us to i64\n %arrayidx48.us.us.us.us.us = getelementptr i8, ptr %r, i64 %idxprom38.us.us.us.us.us\n %0 = load i8, ptr %arrayidx48.us.us.us.us.us, align 1\n %loadedv49.us.us.us.us.us = trunc i8 %0 to i1\n %cond71.in.in.v.us.us.us.us.us = select i1 %loadedv49.us.us.us.us.us, i64 %indvars.iv133, i64 0\n %cond71.in.in.us.us.us.us.us = getelementptr i8, ptr %r, i64 %cond71.in.in.v.us.us.us.us.us\n %cond71.in.us.us.us.us.us = load i8, ptr %cond71.in.in.us.us.us.us.us, align 1\n %cmp72.us.us.us.us.us = icmp ule i8 %0, %cond71.in.us.us.us.us.us\n %conv73.neg.us.us.us.us.us = sext i1 %cmp72.us.us.us.us.us to i32\n %sub74.us.us.us.us.us = add i32 %sub74.us.us.us.us124.us, %conv73.neg.us.us.us.us.us\n store i32 %sub74.us.us.us.us124.us, ptr @a, align 4\n %add77.us.us.us.us.us = add i16 %w.0109.us.us.us.us.us, %g\n %cmp18.us.us.us.us.us = icmp slt i16 %add77.us.us.us.us.us, 0\n br i1 %cmp18.us.us.us.us.us, label %for.body21.us.us.us.us.us, label %for.cond.cleanup20.split.us.us.us.us.us\n\nfor.cond.cleanup20.split.us.us.us.us.us: ; preds = %for.body21.us.us.us.us.us\n %indvars.iv.next134 = add i64 %indvars.iv133, 1\n %1 = and i64 %indvars.iv133, 2147483648\n %cmp12.us.us.us.us = icmp eq i64 %1, 0\n br i1 %cmp12.us.us.us.us, label %for.cond16.preheader.us.us.us.us, label %for.cond5.loopexit.split.us.us.us.us\n\nfor.cond5.loopexit.split.us.us.us.us: ; preds = %for.cond.cleanup20.split.us.us.us.us.us\n ret void\n}\n\ndefine i32 @main() {\nentry:\n %0 = load i16, ptr @g, align 2\n call void @c(i16 %0, ptr @r)\n ret i32 0\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-b,-e,-experimental-sdext,-experimental-sdtrig,-experimental-smctr,-experimental-ssctr,-experimental-svukte,-experimental-xqcia,-experimental-xqciac,-experimental-xqcicli,-experimental-xqcicm,-experimental-xqcics,-experimental-xqcicsr,-experimental-xqciint,-experimental-xqcilo,-experimental-xqcilsm,-experimental-xqcisls,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xmipscmove,-xmipslsp,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zabha,-zacas,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\n```\n\n\nCommand/backtrace:\n```\n$ /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt \"-passes=lto<O3>\" reduced.ll\nWARNING: You're attempting to print out a bitcode file.\nThis is inadvisable as it may cause display problems. If\nyou REALLY want to taste LLVM bitcode first-hand, you\ncan force output with the `-f' option.\n\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: /scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt -passes=lto<O3> reduced.ll\n1. Running pass \"function<eager-inv>(loop-mssa(licm<allowspeculation>),gvn<>,memcpyopt,dse,move-auto-init,mldst-motion<no-split-footer-bb>,loop(indvars,loop-deletion,loop-unroll-full),loop-distribute,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,sccp,instcombine<max-iterations=1;no-verify-fixpoint>,bdce,slp-vectorizer,vector-combine,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,jump-threading)\" on module \"reduced.ll\"\n2. Running pass \"slp-vectorizer\" on function \"c\"\n #0 0x000064a320d6dd02 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x34a8d02)\n #1 0x000064a320d6ad3f llvm::sys::RunSignalHandlers() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x34a5d3f)\n #2 0x000064a320d6ae84 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x00007fe3fee45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x000064a31fc28b80 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes()::'lambda1'(llvm::slpvectorizer::BoUpSLP::EdgeInfo const&)::operator()(llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) const (.isra.0) SLPVectorizer.cpp:0:0\n #5 0x000064a31fcdc0bb llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes() (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24170bb)\n #6 0x000064a31fcf9808 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n #7 0x000064a31fcfc9ae llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24379ae)\n #8 0x000064a31fd00c41 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x243bc41)\n #9 0x000064a31fd04e32 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x243fe32)\n#10 0x000064a31fd0c6e0 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x24476e0)\n#11 0x000064a31fd0d336 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x2448336)\n#12 0x000064a31e87b285 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfb6285)\n#13 0x000064a320b5976a llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x329476a)\n#14 0x000064a31e87d0d5 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfb80d5)\n#15 0x000064a320b5807c llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x329307c)\n#16 0x000064a31e879675 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0xfb4675)\n#17 0x000064a320b5865d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x329365d)\n#18 0x000064a31e01d465 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) (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x758465)\n#19 0x000064a31e00d6ee optMain (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x7486ee)\n#20 0x00007fe3fee2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\n#21 0x00007fe3fee2a28b call_init ./csu/../csu/libc-start.c:128:20\n#22 0x00007fe3fee2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5\n#23 0x000064a31e003f45 _start (/scratch/ewlu/daily-upstream-build/build-gcv/build-llvm-linux/bin/opt+0x73ef45)\nSegmentation fault (core dumped)\n```\n\nGodbolt: https://godbolt.org/z/P3sGYsGYc\n\nFound via fuzzer (C program before reduction)", "author": "ewlu", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
113526
https://github.com/llvm/llvm-project/issues/113526
crash
8c4bc1e75de27adfbaead34b895b0efbaf17bd02
2024-10-24T06:14:03
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "e724226da753f10fd36fbb0ea392f04ab0fdbdab", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 1524, 1529 ] ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPWidenCastRecipe::computeCost" ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit e724226da753f10fd36fbb0ea392f04ab0fdbdab Author: Florian Hahn <[email protected]> Date: Fri Oct 25 12:35:33 2024 +0100 [VPlan] Return cost of 0 for VPWidenCastRecipe without underlying value. In some cases, VPWidenCastRecipes are created but not considered in the legacy cost model, including truncates/extends when evaluating a reduction in a smaller type. Return 0 for such casts for now, to avoid divergences between VPlan and legacy cost models. Fixes https://github.com/llvm/llvm-project/issues/113526. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 0eb4f7c7c88c..2080b77157b6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -1524,6 +1524,11 @@ void VPWidenCastRecipe::execute(VPTransformState &State) { InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF, VPCostContext &Ctx) const { + // TODO: In some cases, VPWidenCastRecipes are created but not considered in + // the legacy cost model, including truncates/extends when evaluating a + // reduction in a smaller type. + if (!getUnderlyingValue()) + return 0; // Computes the CastContextHint from a recipes that may access memory. auto ComputeCCH = [&](const VPRecipeBase *R) -> TTI::CastContextHint { if (VF.isScalar())
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": [ "opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S" ], "tests": [ { "test_name": "narrowed_reduction", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {\nentry:\n %conv = zext i1 %cmp to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]\n %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]\n %and = and i32 %or13, 1\n %or = or i32 %and, %conv\n %inc = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %or\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cost_assume", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @cost_assume(ptr %end, i64 %N) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = phi i64 [ 0, %entry ], [ %1, %loop ]\n %1 = add i64 %0, 1\n %iv.next = add nsw i64 %iv, 1\n %c = icmp ne i64 %N, 0\n tail call void @llvm.assume(i1 %c)\n %gep = getelementptr nusw [9 x i8], ptr null, i64 %iv.next\n %ec = icmp eq ptr %gep, %end\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i64 %1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "PR27826", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine float @PR27826(ptr nocapture readonly %a, ptr nocapture readonly %b, i32 %n) {\nentry:\n %cmp = icmp sgt i32 %n, 0\n br i1 %cmp, label %preheader, label %for.end\n\npreheader: ; preds = %entry\n %t0 = sext i32 %n to i64\n br label %for\n\nfor: ; preds = %for, %preheader\n %indvars.iv = phi i64 [ 0, %preheader ], [ %indvars.iv.next, %for ]\n %s.02 = phi float [ 0.000000e+00, %preheader ], [ %add4, %for ]\n %arrayidx = getelementptr inbounds float, ptr %a, i64 %indvars.iv\n %t1 = load float, ptr %arrayidx, align 4\n %arrayidx3 = getelementptr inbounds float, ptr %b, i64 %indvars.iv\n %t2 = load float, ptr %arrayidx3, align 4\n %add = fadd fast float %t1, %s.02\n %add4 = fadd fast float %add, %t2\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 32\n %cmp1 = icmp slt i64 %indvars.iv.next, %t0\n br i1 %cmp1, label %for, label %loopexit\n\nloopexit: ; preds = %for\n %add4.lcssa = phi float [ %add4, %for ]\n br label %for.end\n\nfor.end: ; preds = %loopexit, %entry\n %s.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add4.lcssa, %loopexit ]\n ret float %s.0.lcssa\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "reduction_store", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine void @reduction_store(ptr noalias %src, ptr %dst, i1 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %red = phi i32 [ 0, %entry ], [ %red.next, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i32, ptr %src, i32 %iv\n %l = load i32, ptr %gep.src, align 4\n %l.and = and i32 %l, 3\n store i32 %l.and, ptr %dst, align 4\n %x.ext = zext i1 %x to i64\n %lshr = lshr i64 %x.ext, 12\n %t = trunc i64 %lshr to i32\n %red.next = and i32 %red, %t\n store i32 %red.next, ptr %dst, align 4\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 29\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"znver3\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cost_loop_invariant_recipes", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @cost_loop_invariant_recipes(i1 %x, i64 %y) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.i.i.i, %loop ]\n %red = phi i64 [ 1, %entry ], [ %red.mul, %loop ]\n %not.x = xor i1 %x, true\n %ext = zext i1 %not.x to i64\n %shl = shl i64 %y, %ext\n %red.mul = mul i64 %shl, %red\n %iv.next.i.i.i = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i64 %red.mul\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "multi_exit", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine void @multi_exit(ptr %dst, ptr %src.1, ptr %src.2, i64 %A, i64 %B) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop.latch, %entry\n %iv.1.wide = phi i64 [ 0, %entry ], [ %iv.1.next.wide, %loop.latch ]\n %iv.1 = phi i32 [ 0, %entry ], [ %iv.1.next, %loop.latch ]\n %ec.1 = icmp ult i64 %iv.1.wide, %A\n br i1 %ec.1, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop\n %l.1 = load i64, ptr %src.1, align 8\n %l.2 = load i64, ptr %src.2, align 8\n %cmp55.us = icmp eq i64 %l.1, 0\n %cmp.i.us = icmp ne i64 %l.2, 0\n %and = and i1 %cmp.i.us, %cmp55.us\n %ext = zext i1 %and to i8\n store i8 %ext, ptr %dst, align 1\n %iv.1.next = add i32 %iv.1, 1\n %iv.1.next.wide = zext i32 %iv.1.next to i64\n %ec.2 = icmp ult i64 %iv.1.next.wide, %B\n br i1 %ec.2, label %loop, label %exit\n\nexit: ; preds = %loop.latch, %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cost_model_1", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\n@c = external global [2048 x i32], align 16\n@b = external global [2048 x i32], align 16\n@d = external global [2048 x i32], align 16\n@a = external global [2048 x i32], align 16\n\n; Function Attrs: noinline nounwind ssp uwtable\ndefine void @cost_model_1() #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\n %0 = shl nsw i64 %indvars.iv, 1\n %arrayidx = getelementptr inbounds [2048 x i32], ptr @c, i64 0, i64 %0\n %1 = load i32, ptr %arrayidx, align 8\n %idxprom1 = sext i32 %1 to i64\n %arrayidx2 = getelementptr inbounds [2048 x i32], ptr @b, i64 0, i64 %idxprom1\n %2 = load i32, ptr %arrayidx2, align 4\n %arrayidx4 = getelementptr inbounds [2048 x i32], ptr @d, i64 0, i64 %indvars.iv\n %3 = load i32, ptr %arrayidx4, align 4\n %idxprom5 = sext i32 %3 to i64\n %arrayidx6 = getelementptr inbounds [2048 x i32], ptr @a, i64 0, i64 %idxprom5\n store i32 %2, ptr %arrayidx6, align 4\n %indvars.iv.next = add i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, 256\n br i1 %exitcond, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { noinline nounwind ssp uwtable }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "any_of_cost", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i1 @any_of_cost(ptr %start, ptr %end) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %any.of = phi i1 [ false, %entry ], [ %any.of.next, %loop ]\n %ptr.iv = phi ptr [ %start, %entry ], [ %ptr.iv.next, %loop ]\n %gep = getelementptr i8, ptr %ptr.iv, i64 8\n %l = load ptr, ptr %gep, align 8\n %cmp13.not.not = icmp eq ptr %l, null\n %any.of.next = select i1 %cmp13.not.not, i1 %any.of, i1 false\n %ptr.iv.next = getelementptr inbounds i8, ptr %ptr.iv, i64 40\n %cmp.not = icmp eq ptr %ptr.iv, %end\n br i1 %cmp.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i1 %any.of.next\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cost_duplicate_recipe_for_sinking", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine void @cost_duplicate_recipe_for_sinking(ptr %A, i64 %N) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %iv.shl = shl nsw i64 %iv, 2\n %gep.0 = getelementptr nusw double, ptr %A, i64 %iv.shl\n %l = load double, ptr %gep.0, align 8\n %c = fcmp oeq double %l, 0.000000e+00\n br i1 %c, label %if.then, label %loop.latch\n\nif.then: ; preds = %loop.header\n %gep.1 = getelementptr double, ptr %A, i64 %iv.shl\n store double 0.000000e+00, ptr %gep.1, align 8\n br label %loop.latch\n\nloop.latch: ; preds = %if.then, %loop.header\n %iv.next = add nsw i64 %iv, 1\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"znver3\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "avx512_cond_load_cost", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @avx512_cond_load_cost(ptr %src, i32 %a, i64 %b, i32 %c, i32 %d) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c.1 = icmp slt i32 %iv, 0\n br i1 %c.1, label %if.then, label %loop.latch\n\nif.then: ; preds = %loop.header\n %0 = urem i32 %a, %c\n %mul = sub i32 0, %0\n %div = udiv i32 %c, %d\n %or = or i32 %div, %mul\n %ext = sext i32 %or to i64\n %gep = getelementptr { i64, i64, i64 }, ptr %src, i64 %ext, i32 2\n %l = load i64, ptr %gep, align 8\n %or.2 = or i64 %l, %b\n br label %loop.latch\n\nloop.latch: ; preds = %if.then, %loop.header\n %res = phi i64 [ 0, %loop.header ], [ %or.2, %if.then ]\n %iv.next = add i32 %iv, 1\n %ec = icmp ult i32 %iv, %c\n br i1 %ec, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret i64 %res\n}\n\nattributes #0 = { \"target-features\"=\"+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "live_in_known_1_via_scev", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @live_in_known_1_via_scev() {\nentry:\n %sel = select i1 false, i32 3, i32 0\n br label %ph\n\nph: ; preds = %entry\n %p = phi i32 [ 1, %entry ]\n %N = add nuw nsw i32 %sel, 6\n %p.ext = zext nneg i32 %p to i64\n br label %loop\n\nloop: ; preds = %loop, %ph\n %iv = phi i32 [ 0, %ph ], [ %iv.next, %loop ]\n %red = phi i64 [ 3, %ph ], [ %red.mul, %loop ]\n %red.mul = mul nsw i64 %red, %p.ext\n %iv.next = add nuw nsw i32 %iv, 1\n %ec = icmp eq i32 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %res = phi i64 [ %red.mul, %loop ]\n ret i64 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes at -O{s,2,3} on x86_64-linux-gnu: Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed ", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\r\n\r\nCompiler Explorer: https://godbolt.org/z/jPaW9fnKj\r\n\r\n```\r\n[531] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git a9050525954cbe11d45b415e2248d9e25e004bfe)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\nFound CUDA installation: /usr/local/cuda, version 11.8\r\n[532] %\r\n[532] % clangtk -O3 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7519: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20241024-clangtk-m64-Os-build-062114/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241024-clangtk-m64-Os-build-062114/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-22743c.o -x c small.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000056385e381f80 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x43e3f80)\r\n #1 0x000056385e37f38f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x43e138f)\r\n #2 0x000056385e37f4e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fe699585520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007fe6995d9a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\r\n #5 0x00007fe699585476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #6 0x00007fe69956b7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #7 0x00007fe69956b71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #8 0x00007fe69957ce96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #9 0x000056385fd39986 llvm::LoopVectorizationPlanner::computeBestVF() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5d9b986)\r\n#10 0x000056385fd50d8c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5db2d8c)\r\n#11 0x000056385fd53ea1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5db5ea1)\r\n#12 0x000056385fd54517 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5db6517)\r\n#13 0x000056385f8a7d86 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5909d86)\r\n#14 0x000056385dd0d52f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3d6f52f)\r\n#15 0x000056385b779146 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x17db146)\r\n#16 0x000056385dd0b8bb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3d6d8bb)\r\n#17 0x000056385b777be6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x17d9be6)\r\n#18 0x000056385dd0c41d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3d6e41d)\r\n#19 0x000056385e6253b6 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#20 0x000056385e628d53 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x468ad53)\r\n#21 0x000056385eceb3f5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4d4d3f5)\r\n#22 0x0000563860a56ffc clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6ab8ffc)\r\n#23 0x000056385efcbdd9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x502ddd9)\r\n#24 0x000056385ef45205 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4fa7205)\r\n#25 0x000056385f0aa403 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x510c403)\r\n#26 0x000056385b330b57 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1392b57)\r\n#27 0x000056385b3275ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x000056385b32b96f clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x138d96f)\r\n#29 0x000056385b21ef2b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1280f2b)\r\n#30 0x00007fe69956cd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#31 0x00007fe69956ce40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#32 0x000056385b326d15 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1388d15)\r\nclangtk: error: unable to execute command: Aborted\r\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git a9050525954cbe11d45b415e2248d9e25e004bfe)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nclangtk: note: diagnostic msg:\r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclangtk: note: diagnostic msg: /tmp/small-ed84bf.c\r\nclangtk: note: diagnostic msg: /tmp/small-ed84bf.sh\r\nclangtk: note: diagnostic msg:\r\n\r\n********************\r\n[533] %\r\n[533] % cat small.c\r\nint a, b, c;\r\nint main() {\r\n for (; a; a++) {\r\n c &= 1;\r\n c |= b == 1;\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "zhendongsu", "body": "@fhahn " } ] }
true
null
76852
https://github.com/llvm/llvm-project/issues/76852
crash
4d11f04b20f0bd7488e19e8f178ba028412fa519
2024-01-03T19:32:37
[ "llvm/test/Transforms/LoopDeletion" ]
{ "fix_commit": "a0b911745494e3c2f53a27f23c536314818ce0b1", "components": [ "LoopDeletion" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": [ [ 452, 457 ], [ 487, 499 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": [ "deleteLoopIfDead" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a0b911745494e3c2f53a27f23c536314818ce0b1 Author: Manish Kausik H <[email protected]> Date: Fri Jan 19 20:00:20 2024 +0530 LoopDeletion: Move EH pad check before the isLoopNeverExecuted Check (#78189) This commit modifies `LoopDeletion::deleteLoopIfDead` to check if the exit block of a loop is an EH pad before checking if the loop gets executed. This handles the case where an unreachable loop has a landingpad as an Exit block, and the loop gets deleted, leaving leaving the landingpad without an edge from an unwind clause. Fixes #76852. diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp index c041e3621a16..bfe9374cf2f8 100644 --- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp @@ -452,6 +452,13 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT, BasicBlock *ExitBlock = L->getUniqueExitBlock(); + // We can't directly branch to an EH pad. Don't bother handling this edge + // case. + if (ExitBlock && ExitBlock->isEHPad()) { + LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n"); + return LoopDeletionResult::Unmodified; + } + if (ExitBlock && isLoopNeverExecuted(L)) { LLVM_DEBUG(dbgs() << "Loop is proven to never execute, delete it!\n"); // We need to forget the loop before setting the incoming values of the exit @@ -487,13 +494,6 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT, return LoopDeletionResult::Unmodified; } - // We can't directly branch to an EH pad. Don't bother handling this edge - // case. - if (ExitBlock && ExitBlock->isEHPad()) { - LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n"); - return LoopDeletionResult::Unmodified; - } - // Finally, we have to check that the loop really is dead. bool Changed = false; if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader, LI)) {
[ { "file": "llvm/test/Transforms/LoopDeletion/loop-with-ehpad-not-executed.ll", "commands": [ "opt %s -passes=loop-deletion -S" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @wombat() personality ptr null {\n;\nbb:\n br i1 false, label %bb1, label %bb4\n\nbb1: ; preds = %bb\n br label %bb2\n\nbb2: ; preds = %bb1, %bb2\n %invoke = invoke double null()\n to label %bb2 unwind label %bb3\n\nbb3: ; preds = %bb2\n %landingpad = landingpad { ptr, i32 }\n cleanup\n ret void\n\nbb4: ; preds = %bb\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": " LLVM ERROR: Broken module found, compilation aborted!", "body": "The bug was found by FuzzGen IR test generator\r\n\r\nRun opt with -passes=loop-deletion \r\nhttps://godbolt.org/z/16zoTYEqx\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() gc \"statepoint-example\" personality ptr null {\r\nbb:\r\n br i1 false, label %bb1, label %bb4\r\n\r\nbb1: ; preds = %bb\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb1, %bb2\r\n %invoke = invoke double null(i64 0)\r\n to label %bb2 unwind label %bb3\r\n\r\nbb3: ; preds = %bb2\r\n %landingpad = landingpad { ptr, i32 }\r\n cleanup\r\n ret void\r\n\r\nbb4: ; preds = %bb\r\n ret void\r\n}\r\n```\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-deletion <source>\r\n #0 0x0000000003597b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3597b18)\r\n #1 0x000000000359526c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fee38042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007fee380969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007fee38042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007fee380287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007905f3 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x00000000034dea68 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x34dea68)\r\n #8 0x0000000002f6f993 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f6f993)\r\n #9 0x000000000088bbae llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x88bbae)\r\n#10 0x0000000002f34d6c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f34d6c)\r\n#11 0x0000000000895cca llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x895cca)\r\n#12 0x000000000079c483 main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x79c483)\r\n#13 0x00007fee38029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007fee38029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x000000000088af1e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x88af1e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "loopoptim", "crash" ], "comments": [ { "author": "Nirhar", "body": "Just looked at the IR after loop deletion and before the verify pass, and looks like loop-deletion incorrectly considered the block with the landingpad as the exit block of the loop:\r\n```\r\ndefine void @wombat() gc \"statepoint-example\" personality ptr null {\r\nbb:\r\n br i1 false, label %bb1, label %bb4\r\n\r\nbb1: ; preds = %bb\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb1\r\n %landingpad = landingpad { ptr, i32 }\r\n cleanup\r\n ret void\r\n\r\nbb4: ; preds = %bb\r\n ret void\r\n}\r\n\r\n$28 = void\r\n```\r\nThe problem seems to be with `Loop::getUniqueExitBlock` from https://github.com/llvm/llvm-project/blob/b6fc463d4c0b00e0741776f9d41b47f532a80b9e/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L453\r\n\r\nwhich returns the landingpad as the exit block of the loop. Perhaps this must be altered to consider that unwind edges are not real edges in the DAG. \r\n\r\n\r\n" }, { "author": "Nirhar", "body": "I'm not sure who are the right persons to consult on this. @EugeneZelenko I leave it to you for you to add them." }, { "author": "nikic", "body": "@Nirhar Isn't this already guarded by https://github.com/llvm/llvm-project/blob/b6fc463d4c0b00e0741776f9d41b47f532a80b9e/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L492?" }, { "author": "nikic", "body": "Ah, this case hits the isLoopNeverExecuted() branch. So that check should just get moved higher, so it covers that case as well." }, { "author": "Nirhar", "body": "@nikic Ah yes that makes sense. I'll land a patch for this soon!\r\n" }, { "author": "Nirhar", "body": "@nikic On second thought, moving the landing pad check higher will not delete the loop, given that this loop never gets executed as well. Isn't it a better solution to delete the loop as well as delete the landing pad instruction?\r\n\r\nEssentially I propose to first check if the loop never gets executed. If yes, delete the loop. Next check if the exit block is a landing pad used exclusively by the loop. If yes, delete the landing pad as well. Is this solution acceptable to you?\r\n\r\nAlso is it correct to call the landing pad as an `ExitBlock`? In my opinion, semantically the landingpad should not be the block that `L->getUniqueExitBlock` returns given that the landingpad is not a part of the loop's logic. Thus in this case according to me `L->getUniqueExitBlock` should have returned a nullptr, and we should have hit the branch https://github.com/llvm/llvm-project/blob/b6fc463d4c0b00e0741776f9d41b47f532a80b9e/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L485 " }, { "author": "nikic", "body": "> On second thought, moving the landing pad check higher will not delete the loop, given that this loop never gets executed as well. Isn't it a better solution to delete the loop as well as delete the landing pad instruction?\r\n\r\nThis is a degenerate case, it is not worthwhile to try and optimize it. It's possible to handle this case, but it's much harder than you think. The current code will always replace a loop with a branch to the exit, even if the loop is known to never execute, because this preserves the outer loop structure. If we replaced the entire loop with unreachable (which is what would really be necessary to handle the landingpad case) we may also break an outer loop and would have to perform corresponding loop info updates.\r\n\r\n> Also is it correct to call the landing pad as an ExitBlock? \r\n\r\nNote that ExitBlock and ExitingBlock are different things. And ExitingBlock is part of the loop and branches to an ExitBlock not part of the loop. So yes, landingpad is a valid ExitBlock here." }, { "author": "Nirhar", "body": "Understood, thanks for the clarification @nikic !" } ] }
true
null
108098
https://github.com/llvm/llvm-project/issues/108098
crash
b8239e1201f5871bed5b633b76fa9536672f287f
2024-09-10T21:48:37
[ "llvm/test/Analysis/CostModel", "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "ea83e1c05a5adee5d8f9e680356ee57556ba64a1", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 1182, 1194 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "setWideningDecision" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit ea83e1c05a5adee5d8f9e680356ee57556ba64a1 Author: Florian Hahn <[email protected]> Date: Wed Sep 11 21:04:33 2024 +0100 [LV] Assign cost to all interleave members when not interleaving. At the moment, the full cost of all interleave group members is assigned to the instruction at the group's insert position, even if the decision was to not form an interleave group. This can lead to inaccurate cost estimates, e.g. if the instruction at the insert position is dead. If the decision is to not vectorize but scalarize or scather/gather, then the cost will be to total cost for all members. In those cases, assign individual the cost per member, to more closely reflect to choice per instruction. This fixes a divergence between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/108098. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 640a7bf3d672..3b6b154b9660 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1182,13 +1182,23 @@ public: InstructionCost Cost) { assert(VF.isVector() && "Expected VF >=2"); /// Broadcast this decicion to all instructions inside the group. - /// But the cost will be assigned to one instruction only. + /// When interleaving, the cost will only be assigned one instruction, the + /// insert position. For other cases, add the appropriate fraction of the + /// total cost to each instruction. This ensures accurate costs are used, + /// even if the insert position instruction is not used. + InstructionCost InsertPosCost = Cost; + InstructionCost OtherMemberCost = 0; + if (W != CM_Interleave) + OtherMemberCost = InsertPosCost = Cost / Grp->getNumMembers(); + ; for (unsigned Idx = 0; Idx < Grp->getFactor(); ++Idx) { if (auto *I = Grp->getMember(Idx)) { if (Grp->getInsertPos() == I) - WideningDecisions[std::make_pair(I, VF)] = std::make_pair(W, Cost); + WideningDecisions[std::make_pair(I, VF)] = + std::make_pair(W, InsertPosCost); else - WideningDecisions[std::make_pair(I, VF)] = std::make_pair(W, 0); + WideningDecisions[std::make_pair(I, VF)] = + std::make_pair(W, OtherMemberCost); } } }
[ { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f32-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x float], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.4\n %v0 = load float, ptr %in0, align 4\n %v1 = load float, ptr %in1, align 4\n %v2 = load float, ptr %in2, align 4\n %v3 = load float, ptr %in3, align 4\n %v4 = load float, ptr %in4, align 4\n %reduce.add.0 = fadd float %v0, %v1\n %reduce.add.1 = fadd float %reduce.add.0, %v2\n %reduce.add.2 = fadd float %reduce.add.1, %v3\n %reduce.add.3 = fadd float %reduce.add.2, %v4\n %reduce.add.3.narrow = fptoui float %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f32-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x float], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.6\n %v0 = load float, ptr %in0, align 4\n %v1 = load float, ptr %in1, align 4\n %v2 = load float, ptr %in2, align 4\n %v3 = load float, ptr %in3, align 4\n %v4 = load float, ptr %in4, align 4\n %v5 = load float, ptr %in5, align 4\n %v6 = load float, ptr %in6, align 4\n %reduce.add.0 = fadd float %v0, %v1\n %reduce.add.1 = fadd float %reduce.add.0, %v2\n %reduce.add.2 = fadd float %reduce.add.1, %v3\n %reduce.add.3 = fadd float %reduce.add.2, %v4\n %reduce.add.4 = fadd float %reduce.add.3, %v5\n %reduce.add.5 = fadd float %reduce.add.4, %v6\n %reduce.add.5.narrow = fptoui float %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f32-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x float], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.7\n %v0 = load float, ptr %in0, align 4\n %v1 = load float, ptr %in1, align 4\n %v2 = load float, ptr %in2, align 4\n %v3 = load float, ptr %in3, align 4\n %v4 = load float, ptr %in4, align 4\n %v5 = load float, ptr %in5, align 4\n %v6 = load float, ptr %in6, align 4\n %v7 = load float, ptr %in7, align 4\n %reduce.add.0 = fadd float %v0, %v1\n %reduce.add.1 = fadd float %reduce.add.0, %v2\n %reduce.add.2 = fadd float %reduce.add.1, %v3\n %reduce.add.3 = fadd float %reduce.add.2, %v4\n %reduce.add.4 = fadd float %reduce.add.3, %v5\n %reduce.add.5 = fadd float %reduce.add.4, %v6\n %reduce.add.6 = fadd float %reduce.add.5, %v7\n %reduce.add.6.narrow = fptoui float %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-2.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.0.narrow = fptoui double %reduce.add.0 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.0.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 2\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-3.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.1.narrow = fptoui double %reduce.add.1 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.1.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 3\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-4.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.2.narrow = fptoui double %reduce.add.2 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.2.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 4\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.3.narrow = fptoui double %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-6.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.5\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %v5 = load double, ptr %in5, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.4 = fadd double %reduce.add.3, %v5\n %reduce.add.4.narrow = fptoui double %reduce.add.4 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.4.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 6\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.6\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %v5 = load double, ptr %in5, align 8\n %v6 = load double, ptr %in6, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.4 = fadd double %reduce.add.3, %v5\n %reduce.add.5 = fadd double %reduce.add.4, %v6\n %reduce.add.5.narrow = fptoui double %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.7\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %v5 = load double, ptr %in5, align 8\n %v6 = load double, ptr %in6, align 8\n %v7 = load double, ptr %in7, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.4 = fadd double %reduce.add.3, %v5\n %reduce.add.5 = fadd double %reduce.add.4, %v6\n %reduce.add.6 = fadd double %reduce.add.5, %v7\n %reduce.add.6.narrow = fptoui double %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i16-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i16], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.4\n %v0 = load i16, ptr %in0, align 2\n %v1 = load i16, ptr %in1, align 2\n %v2 = load i16, ptr %in2, align 2\n %v3 = load i16, ptr %in3, align 2\n %v4 = load i16, ptr %in4, align 2\n %reduce.add.0 = add i16 %v0, %v1\n %reduce.add.1 = add i16 %reduce.add.0, %v2\n %reduce.add.2 = add i16 %reduce.add.1, %v3\n %reduce.add.3 = add i16 %reduce.add.2, %v4\n %reduce.add.3.narrow = trunc i16 %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i16-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i16], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.6\n %v0 = load i16, ptr %in0, align 2\n %v1 = load i16, ptr %in1, align 2\n %v2 = load i16, ptr %in2, align 2\n %v3 = load i16, ptr %in3, align 2\n %v4 = load i16, ptr %in4, align 2\n %v5 = load i16, ptr %in5, align 2\n %v6 = load i16, ptr %in6, align 2\n %reduce.add.0 = add i16 %v0, %v1\n %reduce.add.1 = add i16 %reduce.add.0, %v2\n %reduce.add.2 = add i16 %reduce.add.1, %v3\n %reduce.add.3 = add i16 %reduce.add.2, %v4\n %reduce.add.4 = add i16 %reduce.add.3, %v5\n %reduce.add.5 = add i16 %reduce.add.4, %v6\n %reduce.add.5.narrow = trunc i16 %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i16-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i16], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.7\n %v0 = load i16, ptr %in0, align 2\n %v1 = load i16, ptr %in1, align 2\n %v2 = load i16, ptr %in2, align 2\n %v3 = load i16, ptr %in3, align 2\n %v4 = load i16, ptr %in4, align 2\n %v5 = load i16, ptr %in5, align 2\n %v6 = load i16, ptr %in6, align 2\n %v7 = load i16, ptr %in7, align 2\n %reduce.add.0 = add i16 %v0, %v1\n %reduce.add.1 = add i16 %reduce.add.0, %v2\n %reduce.add.2 = add i16 %reduce.add.1, %v3\n %reduce.add.3 = add i16 %reduce.add.2, %v4\n %reduce.add.4 = add i16 %reduce.add.3, %v5\n %reduce.add.5 = add i16 %reduce.add.4, %v6\n %reduce.add.6 = add i16 %reduce.add.5, %v7\n %reduce.add.6.narrow = trunc i16 %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-4-indices-01uu.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, 0\n %reduce.add.2 = add i32 %reduce.add.1, 0\n %reduce.add.2.narrow = trunc i32 %reduce.add.2 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.2.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv, 4\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.4\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %v2 = load i32, ptr %in2, align 4\n %v3 = load i32, ptr %in3, align 4\n %v4 = load i32, ptr %in4, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, %v2\n %reduce.add.2 = add i32 %reduce.add.1, %v3\n %reduce.add.3 = add i32 %reduce.add.2, %v4\n %reduce.add.3.narrow = trunc i32 %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.6\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %v2 = load i32, ptr %in2, align 4\n %v3 = load i32, ptr %in3, align 4\n %v4 = load i32, ptr %in4, align 4\n %v5 = load i32, ptr %in5, align 4\n %v6 = load i32, ptr %in6, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, %v2\n %reduce.add.2 = add i32 %reduce.add.1, %v3\n %reduce.add.3 = add i32 %reduce.add.2, %v4\n %reduce.add.4 = add i32 %reduce.add.3, %v5\n %reduce.add.5 = add i32 %reduce.add.4, %v6\n %reduce.add.5.narrow = trunc i32 %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.7\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %v2 = load i32, ptr %in2, align 4\n %v3 = load i32, ptr %in3, align 4\n %v4 = load i32, ptr %in4, align 4\n %v5 = load i32, ptr %in5, align 4\n %v6 = load i32, ptr %in6, align 4\n %v7 = load i32, ptr %in7, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, %v2\n %reduce.add.2 = add i32 %reduce.add.1, %v3\n %reduce.add.3 = add i32 %reduce.add.2, %v4\n %reduce.add.4 = add i32 %reduce.add.3, %v5\n %reduce.add.5 = add i32 %reduce.add.4, %v6\n %reduce.add.6 = add i32 %reduce.add.5, %v7\n %reduce.add.6.narrow = trunc i32 %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-2.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.0.narrow = trunc i64 %reduce.add.0 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.0.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 2\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-3.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.1.narrow = trunc i64 %reduce.add.1 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.1.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 3\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-4.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.2.narrow = trunc i64 %reduce.add.2 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.2.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 4\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.3.narrow = trunc i64 %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-6.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.5\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %v5 = load i64, ptr %in5, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.4 = add i64 %reduce.add.3, %v5\n %reduce.add.4.narrow = trunc i64 %reduce.add.4 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.4.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 6\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.6\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %v5 = load i64, ptr %in5, align 8\n %v6 = load i64, ptr %in6, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.4 = add i64 %reduce.add.3, %v5\n %reduce.add.5 = add i64 %reduce.add.4, %v6\n %reduce.add.5.narrow = trunc i64 %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.7\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %v5 = load i64, ptr %in5, align 8\n %v6 = load i64, ptr %in6, align 8\n %v7 = load i64, ptr %in7, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.4 = add i64 %reduce.add.3, %v5\n %reduce.add.5 = add i64 %reduce.add.4, %v6\n %reduce.add.6 = add i64 %reduce.add.5, %v7\n %reduce.add.6.narrow = trunc i64 %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i8-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.4\n %v0 = load i8, ptr %in0, align 1\n %v1 = load i8, ptr %in1, align 1\n %v2 = load i8, ptr %in2, align 1\n %v3 = load i8, ptr %in3, align 1\n %v4 = load i8, ptr %in4, align 1\n %reduce.add.0 = add i8 %v0, %v1\n %reduce.add.1 = add i8 %reduce.add.0, %v2\n %reduce.add.2 = add i8 %reduce.add.1, %v3\n %reduce.add.3 = add i8 %reduce.add.2, %v4\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i8-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.6\n %v0 = load i8, ptr %in0, align 1\n %v1 = load i8, ptr %in1, align 1\n %v2 = load i8, ptr %in2, align 1\n %v3 = load i8, ptr %in3, align 1\n %v4 = load i8, ptr %in4, align 1\n %v5 = load i8, ptr %in5, align 1\n %v6 = load i8, ptr %in6, align 1\n %reduce.add.0 = add i8 %v0, %v1\n %reduce.add.1 = add i8 %reduce.add.0, %v2\n %reduce.add.2 = add i8 %reduce.add.1, %v3\n %reduce.add.3 = add i8 %reduce.add.2, %v4\n %reduce.add.4 = add i8 %reduce.add.3, %v5\n %reduce.add.5 = add i8 %reduce.add.4, %v6\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i8-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.7\n %v0 = load i8, ptr %in0, align 1\n %v1 = load i8, ptr %in1, align 1\n %v2 = load i8, ptr %in2, align 1\n %v3 = load i8, ptr %in3, align 1\n %v4 = load i8, ptr %in4, align 1\n %v5 = load i8, ptr %in5, align 1\n %v6 = load i8, ptr %in6, align 1\n %v7 = load i8, ptr %in7, align 1\n %reduce.add.0 = add i8 %v0, %v1\n %reduce.add.1 = add i8 %reduce.add.0, %v2\n %reduce.add.2 = add i8 %reduce.add.1, %v3\n %reduce.add.3 = add i8 %reduce.add.2, %v4\n %reduce.add.4 = add i8 %reduce.add.3, %v5\n %reduce.add.5 = add i8 %reduce.add.4, %v6\n %reduce.add.6 = add i8 %reduce.add.5, %v7\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-store-f64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x double], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %v.narrow = load i8, ptr %in, align 1\n %v = uitofp i8 %v.narrow to double\n %v0 = fadd double %v, 0.000000e+00\n %v1 = fadd double %v, 1.000000e+00\n %v2 = fadd double %v, 2.000000e+00\n %v3 = fadd double %v, 3.000000e+00\n %v4 = fadd double %v, 4.000000e+00\n %v5 = fadd double %v, 5.000000e+00\n %v6 = fadd double %v, 6.000000e+00\n %v7 = fadd double %v, 7.000000e+00\n %out0 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.0\n %out1 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.1\n %out2 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.2\n %out3 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.3\n %out4 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.4\n %out5 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.5\n %out6 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.6\n %out7 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.7\n store double %v0, ptr %out0, align 8\n store double %v1, ptr %out1, align 8\n store double %v2, ptr %out2, align 8\n store double %v3, ptr %out3, align 8\n store double %v4, ptr %out4, align 8\n store double %v5, ptr %out5, align 8\n store double %v6, ptr %out6, align 8\n store double %v7, ptr %out7, align 8\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-store-i64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i64], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %v.narrow = load i8, ptr %in, align 1\n %v = zext i8 %v.narrow to i64\n %v0 = add i64 %v, 0\n %v1 = add i64 %v, 1\n %v2 = add i64 %v, 2\n %v3 = add i64 %v, 3\n %v4 = add i64 %v, 4\n %v5 = add i64 %v, 5\n %v6 = add i64 %v, 6\n %v7 = add i64 %v, 7\n %out0 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.0\n %out1 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.1\n %out2 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.2\n %out3 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.3\n %out4 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.4\n %out5 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.5\n %out6 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.6\n %out7 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.7\n store i64 %v0, ptr %out0, align 8\n store i64 %v1, ptr %out1, align 8\n store i64 %v2, ptr %out2, align 8\n store i64 %v3, ptr %out3, align 8\n store i64 %v4, ptr %out4, align 8\n store i64 %v5, ptr %out5, align 8\n store i64 %v6, ptr %out6, align 8\n store i64 %v7, ptr %out7, align 8\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/masked-interleaved-store-i16.ll", "commands": [ "opt -passes=loop-vectorize -enable-interleaved-mem-accesses -prefer-predicate-over-epilogue=predicate-dont-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -enable-interleaved-mem-accesses -enable-masked-interleaved-mem-accesses -prefer-predicate-over-epilogue=predicate-dont-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test2", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test2(ptr noalias nocapture %points, i32 %numPoints, ptr noalias nocapture readonly %x, ptr noalias nocapture readonly %y) {\nentry:\n %cmp15 = icmp sgt i32 %numPoints, 0\n br i1 %cmp15, label %for.body.preheader, label %for.end\n\nfor.body.preheader: ; preds = %entry\n %wide.trip.count = zext i32 %numPoints to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.preheader\n %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %arrayidx = getelementptr inbounds i16, ptr %x, i64 %indvars.iv\n %0 = load i16, ptr %arrayidx, align 2\n %1 = shl nsw i64 %indvars.iv, 2\n %arrayidx2 = getelementptr inbounds i16, ptr %points, i64 %1\n store i16 %0, ptr %arrayidx2, align 2\n %arrayidx4 = getelementptr inbounds i16, ptr %y, i64 %indvars.iv\n %2 = load i16, ptr %arrayidx4, align 2\n %3 = or disjoint i64 %1, 1\n %arrayidx7 = getelementptr inbounds i16, ptr %points, i64 %3\n store i16 %2, ptr %arrayidx7, align 2\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count\n br i1 %exitcond.not, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test1", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test1(ptr noalias nocapture %points, ptr noalias nocapture readonly %x, ptr noalias nocapture readonly %y) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\n %arrayidx = getelementptr inbounds i16, ptr %x, i64 %indvars.iv\n %0 = load i16, ptr %arrayidx, align 2\n %1 = shl nuw nsw i64 %indvars.iv, 2\n %arrayidx2 = getelementptr inbounds i16, ptr %points, i64 %1\n store i16 %0, ptr %arrayidx2, align 2\n %arrayidx4 = getelementptr inbounds i16, ptr %y, i64 %indvars.iv\n %2 = load i16, ptr %arrayidx4, align 2\n %3 = or disjoint i64 %1, 1\n %arrayidx7 = getelementptr inbounds i16, ptr %points, i64 %3\n store i16 %2, ptr %arrayidx7, align 2\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %exitcond.not = icmp eq i64 %indvars.iv.next, 1024\n br i1 %exitcond.not, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/interleaved-vs-scalar.ll", "commands": [ "opt < %s -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize -S --debug-only=loop-vectorize 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64--linux-gnu\"\n\n%pair = type { i8, i8 }\n\ndefine void @test(ptr %p, ptr %q, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr %pair, ptr %p, i64 %i, i32 0\n %tmp1 = load i8, ptr %tmp0, align 1\n %tmp2 = getelementptr %pair, ptr %p, i64 %i, i32 1\n %tmp3 = load i8, ptr %tmp2, align 1\n %add = add i8 %tmp1, %tmp3\n %qi = getelementptr i8, ptr %q, i64 %i\n store i8 %add, ptr %qi, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp eq i64 %i.next, %n\n br i1 %cond, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/interleaved_cost.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=2 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=4 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=8 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=16 -debug-only=loop-vectorize -disable-output < %s 2>&1" ], "tests": [ { "test_name": "i8_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i8.2 = type { i8, i8 }\n\ndefine void @i8_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i8, ptr %tmp0, align 1\n %tmp3 = load i8, ptr %tmp1, align 1\n store i8 %tmp2, ptr %tmp0, align 1\n store i8 %tmp3, ptr %tmp1, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i16_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i16.2 = type { i16, i16 }\n\ndefine void @i16_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i16, ptr %tmp0, align 2\n %tmp3 = load i16, ptr %tmp1, align 2\n store i16 %tmp2, ptr %tmp0, align 2\n store i16 %tmp3, ptr %tmp1, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i32_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i32.2 = type { i32, i32 }\n\ndefine void @i32_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i32, ptr %tmp0, align 4\n %tmp3 = load i32, ptr %tmp1, align 4\n store i32 %tmp2, ptr %tmp0, align 4\n store i32 %tmp3, ptr %tmp1, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i64_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i64.2 = type { i64, i64 }\n\ndefine void @i64_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i64, ptr %tmp0, align 8\n %tmp3 = load i64, ptr %tmp1, align 8\n store i64 %tmp2, ptr %tmp0, align 8\n store i64 %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i64_factor_8", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i64.8 = type { i64, i64, i64, i64, i64, i64, i64, i64 }\n\ndefine void @i64_factor_8(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.8, ptr %data, i64 %i, i32 2\n %tmp1 = getelementptr inbounds %i64.8, ptr %data, i64 %i, i32 6\n %tmp2 = load i64, ptr %tmp0, align 8\n %tmp3 = load i64, ptr %tmp1, align 8\n store i64 %tmp2, ptr %tmp0, align 8\n store i64 %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/ARM/mve-interleaved-cost.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=2 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=4 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=8 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=16 -debug-only=loop-vectorize -disable-output < %s 2>&1" ], "tests": [ { "test_name": "i16_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i16.3 = type { i16, i16, i16 }\n\ndefine void @i16_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i16.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i16, ptr %tmp0, align 2\n %tmp4 = load i16, ptr %tmp1, align 2\n %tmp5 = load i16, ptr %tmp2, align 2\n store i16 %tmp3, ptr %tmp0, align 2\n store i16 %tmp4, ptr %tmp1, align 2\n store i16 %tmp5, ptr %tmp2, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f16_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f16.2 = type { half, half }\n\ndefine void @f16_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f16.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f16.2, ptr %data, i64 %i, i32 1\n %tmp2 = load half, ptr %tmp0, align 2\n %tmp3 = load half, ptr %tmp1, align 2\n store half %tmp2, ptr %tmp0, align 2\n store half %tmp3, ptr %tmp1, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i32_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i32.2 = type { i32, i32 }\n\ndefine void @i32_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i32, ptr %tmp0, align 4\n %tmp3 = load i32, ptr %tmp1, align 4\n store i32 %tmp2, ptr %tmp0, align 4\n store i32 %tmp3, ptr %tmp1, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i64_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i64.4 = type { i64, i64, i64, i64 }\n\ndefine void @i64_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i64, ptr %tmp0, align 8\n %tmp5 = load i64, ptr %tmp1, align 8\n %tmp6 = load i64, ptr %tmp2, align 8\n %tmp7 = load i64, ptr %tmp3, align 8\n store i64 %tmp4, ptr %tmp0, align 8\n store i64 %tmp5, ptr %tmp1, align 8\n store i64 %tmp6, ptr %tmp2, align 8\n store i64 %tmp7, ptr %tmp3, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f32_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f32.3 = type { float, float, float }\n\ndefine void @f32_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f32.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f32.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f32.3, ptr %data, i64 %i, i32 2\n %tmp3 = load float, ptr %tmp0, align 4\n %tmp4 = load float, ptr %tmp1, align 4\n %tmp5 = load float, ptr %tmp2, align 4\n store float %tmp3, ptr %tmp0, align 4\n store float %tmp4, ptr %tmp1, align 4\n store float %tmp5, ptr %tmp2, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i64_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i64.3 = type { i64, i64, i64 }\n\ndefine void @i64_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i64.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i64, ptr %tmp0, align 8\n %tmp4 = load i64, ptr %tmp1, align 8\n %tmp5 = load i64, ptr %tmp2, align 8\n store i64 %tmp3, ptr %tmp0, align 8\n store i64 %tmp4, ptr %tmp1, align 8\n store i64 %tmp5, ptr %tmp2, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f16_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f16.3 = type { half, half, half }\n\ndefine void @f16_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f16.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f16.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f16.3, ptr %data, i64 %i, i32 2\n %tmp3 = load half, ptr %tmp0, align 2\n %tmp4 = load half, ptr %tmp1, align 2\n %tmp5 = load half, ptr %tmp2, align 2\n store half %tmp3, ptr %tmp0, align 2\n store half %tmp4, ptr %tmp1, align 2\n store half %tmp5, ptr %tmp2, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i8_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i8.3 = type { i8, i8, i8 }\n\ndefine void @i8_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i8.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i8, ptr %tmp0, align 1\n %tmp4 = load i8, ptr %tmp1, align 1\n %tmp5 = load i8, ptr %tmp2, align 1\n store i8 %tmp3, ptr %tmp0, align 1\n store i8 %tmp4, ptr %tmp1, align 1\n store i8 %tmp5, ptr %tmp2, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f32_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f32.2 = type { float, float }\n\ndefine void @f32_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f32.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f32.2, ptr %data, i64 %i, i32 1\n %tmp2 = load float, ptr %tmp0, align 4\n %tmp3 = load float, ptr %tmp1, align 4\n store float %tmp2, ptr %tmp0, align 4\n store float %tmp3, ptr %tmp1, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i8_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i8.4 = type { i8, i8, i8, i8 }\n\ndefine void @i8_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i8, ptr %tmp0, align 1\n %tmp5 = load i8, ptr %tmp1, align 1\n %tmp6 = load i8, ptr %tmp2, align 1\n %tmp7 = load i8, ptr %tmp3, align 1\n store i8 %tmp4, ptr %tmp0, align 1\n store i8 %tmp5, ptr %tmp1, align 1\n store i8 %tmp6, ptr %tmp2, align 1\n store i8 %tmp7, ptr %tmp3, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i16_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i16.2 = type { i16, i16 }\n\ndefine void @i16_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i16, ptr %tmp0, align 2\n %tmp3 = load i16, ptr %tmp1, align 2\n store i16 %tmp2, ptr %tmp0, align 2\n store i16 %tmp3, ptr %tmp1, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i16_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i16.4 = type { i16, i16, i16, i16 }\n\ndefine void @i16_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i16, ptr %tmp0, align 2\n %tmp5 = load i16, ptr %tmp1, align 2\n %tmp6 = load i16, ptr %tmp2, align 2\n %tmp7 = load i16, ptr %tmp3, align 2\n store i16 %tmp4, ptr %tmp0, align 2\n store i16 %tmp5, ptr %tmp1, align 2\n store i16 %tmp6, ptr %tmp2, align 2\n store i16 %tmp7, ptr %tmp3, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f64_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f64.3 = type { double, double, double }\n\ndefine void @f64_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f64.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f64.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f64.3, ptr %data, i64 %i, i32 2\n %tmp3 = load double, ptr %tmp0, align 8\n %tmp4 = load double, ptr %tmp1, align 8\n %tmp5 = load double, ptr %tmp2, align 8\n store double %tmp3, ptr %tmp0, align 8\n store double %tmp4, ptr %tmp1, align 8\n store double %tmp5, ptr %tmp2, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i8_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i8.2 = type { i8, i8 }\n\ndefine void @i8_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i8, ptr %tmp0, align 1\n %tmp3 = load i8, ptr %tmp1, align 1\n store i8 %tmp2, ptr %tmp0, align 1\n store i8 %tmp3, ptr %tmp1, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i32_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i32.4 = type { i32, i32, i32, i32 }\n\ndefine void @i32_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i32, ptr %tmp0, align 4\n %tmp5 = load i32, ptr %tmp1, align 4\n %tmp6 = load i32, ptr %tmp2, align 4\n %tmp7 = load i32, ptr %tmp3, align 4\n store i32 %tmp4, ptr %tmp0, align 4\n store i32 %tmp5, ptr %tmp1, align 4\n store i32 %tmp6, ptr %tmp2, align 4\n store i32 %tmp7, ptr %tmp3, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i32_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i32.3 = type { i32, i32, i32 }\n\ndefine void @i32_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i32.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i32, ptr %tmp0, align 4\n %tmp4 = load i32, ptr %tmp1, align 4\n %tmp5 = load i32, ptr %tmp2, align 4\n store i32 %tmp3, ptr %tmp0, align 4\n store i32 %tmp4, ptr %tmp1, align 4\n store i32 %tmp5, ptr %tmp2, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f64_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f64.2 = type { double, double }\n\ndefine void @f64_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f64.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f64.2, ptr %data, i64 %i, i32 1\n %tmp2 = load double, ptr %tmp0, align 8\n %tmp3 = load double, ptr %tmp1, align 8\n store double %tmp2, ptr %tmp0, align 8\n store double %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f16_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f16.4 = type { half, half, half, half }\n\ndefine void @f16_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 3\n %tmp4 = load half, ptr %tmp0, align 2\n %tmp5 = load half, ptr %tmp1, align 2\n %tmp6 = load half, ptr %tmp2, align 2\n %tmp7 = load half, ptr %tmp3, align 2\n store half %tmp4, ptr %tmp0, align 2\n store half %tmp5, ptr %tmp1, align 2\n store half %tmp6, ptr %tmp2, align 2\n store half %tmp7, ptr %tmp3, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "i64_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i64.2 = type { i64, i64 }\n\ndefine void @i64_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i64, ptr %tmp0, align 8\n %tmp3 = load i64, ptr %tmp1, align 8\n store i64 %tmp2, ptr %tmp0, align 8\n store i64 %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f64_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f64.4 = type { double, double, double, double }\n\ndefine void @f64_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 3\n %tmp4 = load double, ptr %tmp0, align 8\n %tmp5 = load double, ptr %tmp1, align 8\n %tmp6 = load double, ptr %tmp2, align 8\n %tmp7 = load double, ptr %tmp3, align 8\n store double %tmp4, ptr %tmp0, align 8\n store double %tmp5, ptr %tmp1, align 8\n store double %tmp6, ptr %tmp2, align 8\n store double %tmp7, ptr %tmp3, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "f32_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f32.4 = type { float, float, float, float }\n\ndefine void @f32_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 3\n %tmp4 = load float, ptr %tmp0, align 4\n %tmp5 = load float, ptr %tmp1, align 4\n %tmp6 = load float, ptr %tmp2, align 4\n %tmp7 = load float, ptr %tmp3, align 4\n store float %tmp4, ptr %tmp0, align 4\n store float %tmp5, ptr %tmp1, align 4\n store float %tmp6, ptr %tmp2, align 4\n store float %tmp7, ptr %tmp3, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll", "commands": [ "opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s" ], "tests": [ { "test_name": "dead_load", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cost_of_exit_branch_and_cond_insts", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.umax.i16(i16, i16) #0\n\ndefine i32 @cost_of_exit_branch_and_cond_insts(ptr %a, ptr %b, i1 %c, i16 %x) #1 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.exiting\n\nthen: ; preds = %loop.header\n %gep = getelementptr inbounds i32, ptr %b, i32 %iv\n store i1 false, ptr %a, align 1\n store i32 0, ptr %gep, align 4\n br label %loop.exiting\n\nloop.exiting: ; preds = %then, %loop.header\n %iv.next = add i32 %iv, 1\n %umax = tail call i16 @llvm.umax.i16(i16 %x, i16 111)\n %umax.ext = zext i16 %umax to i32\n %sub = sub i32 770, %umax.ext\n %ec = icmp slt i32 %iv, %sub\n br i1 %ec, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop.exiting\n br label %loop.header\n\nexit: ; preds = %loop.exiting\n br label %return\n\nreturn: ; preds = %exit\n ret i32 0\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { \"target-features\"=\"+64bit,+v\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "gather_interleave_group_with_dead_insert_pos", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @gather_interleave_group_with_dead_insert_pos(i64 %N, ptr noalias %src, ptr noalias %dst) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]\n %gep.src.0 = getelementptr i8, ptr %src, i64 %iv\n %l.dead = load i8, ptr %gep.src.0, align 1\n %iv.1 = add i64 %iv, 1\n %gep.src.1 = getelementptr i8, ptr %src, i64 %iv.1\n %l.1 = load i8, ptr %gep.src.1, align 1\n %ext = zext i8 %l.1 to i32\n %gep.dst = getelementptr i32, ptr %dst, i64 %iv\n store i32 %ext, ptr %gep.dst, align 4\n %iv.next = add nsw i64 %iv, 4\n %ec = icmp slt i64 %iv, %N\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_phi_in_latch_redundant", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_phi_in_latch_redundant(ptr %dst, i32 %a) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %not.a = xor i32 %a, -1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i32 [ %not.a, %then ], [ 0, %loop.header ]\n %gep = getelementptr i32, ptr %dst, i64 %iv\n store i32 %p, ptr %gep, align 4\n %iv.next = add i64 %iv, 9\n %ec = icmp slt i64 %iv, 322\n br i1 %ec, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dead_live_out_due_to_scalar_epilogue_required", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i8 @dead_live_out_due_to_scalar_epilogue_required(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %idxprom = sext i32 %iv to i64\n %gep.src = getelementptr i8, ptr %src, i64 %idxprom\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %idxprom\n store i8 0, ptr %gep.dst, align 1\n %iv.next = add i32 %iv, 4\n %cmp = icmp ult i32 %iv, 1001\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n %r = phi i8 [ %l, %loop ]\n ret i8 %r\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/SystemZ/mem-interleaving-costs-03.ll", "commands": [ "opt -mtriple=s390x-unknown-linux -mcpu=z16 -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-width=4 -disable-output < %s 2>&1" ], "tests": [ { "test_name": "fun", "test_body": "define noundef i32 @fun(i32 %argc, ptr nocapture readnone %argv) {\nentry:\n %l_4774.i = alloca [4 x [2 x i128]], align 8\n call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %l_4774.i)\n br label %for.cond4.preheader.i\n\nfor.cond4.preheader.i: ; preds = %for.cond4.preheader.i, %entry\n %indvars.iv8.i = phi i64 [ 0, %entry ], [ %indvars.iv.next9.i, %for.cond4.preheader.i ]\n %arrayidx10.i = getelementptr inbounds [4 x [2 x i128]], ptr %l_4774.i, i64 0, i64 %indvars.iv8.i, i64 0\n store i128 8721036757475490113, ptr %arrayidx10.i, align 8\n %arrayidx10.i.c = getelementptr inbounds [4 x [2 x i128]], ptr %l_4774.i, i64 0, i64 %indvars.iv8.i, i64 1\n store i128 8721036757475490113, ptr %arrayidx10.i.c, align 8\n %indvars.iv.next9.i = add nuw nsw i64 %indvars.iv8.i, 1\n %exitcond.not.i = icmp eq i64 %indvars.iv.next9.i, 4\n br i1 %exitcond.not.i, label %func_1.exit, label %for.cond4.preheader.i\n\nfunc_1.exit: ; preds = %for.cond4.preheader.i\n %arrayidx195.i = getelementptr inbounds [4 x [2 x i128]], ptr %l_4774.i, i64 0, i64 1\n %0 = load i128, ptr %arrayidx195.i, align 8\n %cmp200.i = icmp ne i128 %0, 0\n %conv202.i = zext i1 %cmp200.i to i64\n %call203.i = tail call i64 @safe_sub_func_int64_t_s_s(i64 noundef %conv202.i, i64 noundef 9139899272418802852)\n call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %l_4774.i)\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %func_1.exit\n br label %for.cond\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0\n\ndeclare dso_local i64 @safe_sub_func_int64_t_s_s(i64, i64)\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using: 15106c26662a WITH commits from #107894 cherry-picked on top.\r\n```\r\n> git log --oneline\r\n2bfba9bc7d37 (HEAD -> main) !fixup add TODO\r\n28acd6af75ff Add initial loop-invariant code motion transform.\r\n15106c26662a (origin/main, origin/HEAD) [flang][runtime] Fix odd \"invalid descriptor\" runtime crash\r\n```\r\nTestcase:\r\n```c\r\nchar a;\r\nextern int b[];\r\nshort c;\r\nchar d[1];\r\nvoid checksum() {\r\n for (long e = 0; e < 3;)\r\n for (long f = 0; e < 3; e = 709692)\r\n for (; f < c; f += 4) {\r\n a = d[f];\r\n b[f] = d[f - 1];\r\n }\r\n}\r\n```\r\n`clang -march=rv64gcv -O3 red.c`\r\n\r\nTestcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @g(i64 %conv) #0 {\r\nentry:\r\n br label %for.body8.us23\r\n\r\nfor.body8.us23: ; preds = %for.body8.us23, %entry\r\n %f.121.us24 = phi i64 [ %add.us30, %for.body8.us23 ], [ 0, %entry ]\r\n %arrayidx.us25 = getelementptr [1 x i8], ptr null, i64 0, i64 %f.121.us24\r\n %0 = load i8, ptr %arrayidx.us25, align 1\r\n %sub.us26 = add i64 %f.121.us24, 1\r\n %arrayidx9.us27 = getelementptr [1 x i8], ptr null, i64 0, i64 %sub.us26\r\n %1 = load i8, ptr %arrayidx9.us27, align 1\r\n %conv10.us28 = zext i8 %1 to i32\r\n %arrayidx11.us29 = getelementptr [0 x i32], ptr null, i64 0, i64 %f.121.us24\r\n store i32 %conv10.us28, ptr null, align 4\r\n %add.us30 = add nsw i64 %f.121.us24, 4\r\n %cmp6.us31 = icmp slt i64 %f.121.us24, %conv\r\n br i1 %cmp6.us31, label %for.body8.us23, label %for.cond.cleanup.split.us\r\n\r\nfor.cond.cleanup.split.us: ; preds = %for.body8.us23\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt --passes loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7394: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' 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. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt --passes loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"g\"\r\n #0 0x00005fabff5a9d80 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3072d80)\r\n #1 0x00005fabff5a718f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x307018f)\r\n #2 0x00005fabff5a72e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fe3d2042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007fe3d20969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007fe3d20969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007fe3d20969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007fe3d2042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007fe3d20287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007fe3d202871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007fe3d2039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005fabfe550a26 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2019a26)\r\n#12 0x00005fabfe5678fb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20308fb)\r\n#13 0x00005fabfe56a911 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2033911)\r\n#14 0x00005fabfe56af87 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2033f87)\r\n#15 0x00005fabfd3adf96 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe76f96)\r\n#16 0x00005fabff3b51ef llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e7e1ef)\r\n#17 0x00005fabfd3b11c6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe7a1c6)\r\n#18 0x00005fabff3b357b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e7c57b)\r\n#19 0x00005fabfd3ad376 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe76376)\r\n#20 0x00005fabff3b40dd llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e7d0dd)\r\n#21 0x00005fabfcbd49db 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) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x69d9db)\r\n#22 0x00005fabfcbc6701 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x68f701)\r\n#23 0x00007fe3d2029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007fe3d2029e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007fe3d2029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005fabfcbbcc65 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x685c65)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/TTchhsf9h\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/107473\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
97586
https://github.com/llvm/llvm-project/issues/97586
crash
be7239e5a60927f5b4932f995dc4b57423ea8534
2024-07-03T14:47:17
[ "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "cff8d716bdf017a2af8eb8623257fd33ee43f30e", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": [ [ 8412, 8418 ] ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::visitAndClearUsers" ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit cff8d716bdf017a2af8eb8623257fd33ee43f30e Author: v01dXYZ <[email protected]> Date: Tue Jul 9 09:14:33 2024 +0200 [SCEV] forgetValue: support (with-overflow-inst op0, op1) (#98015) The use-def walk in forgetValue() was skipping instructions with non-SCEVable types. However, SCEV may look past with.overflow intrinsics returning aggregates. Fixes #97586. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 430e1c6d8f8c..51cffac80876 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8412,7 +8412,7 @@ void ScalarEvolution::visitAndClearUsers( SmallVectorImpl<const SCEV *> &ToForget) { while (!Worklist.empty()) { Instruction *I = Worklist.pop_back_val(); - if (!isSCEVable(I->getType())) + if (!isSCEVable(I->getType()) && !isa<WithOverflowInst>(I)) continue; ValueExprMapType::iterator It =
[ { "file": "llvm/test/Transforms/LoopUnroll/peel-loop-scev-invalidate-with-overflow-inst.ll", "commands": [ "opt < %s -S -passes='print<scalar-evolution>,loop-unroll<peeling;full-unroll-max=0>,print<scalar-evolution>' 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": ";\n; This test ensures that (extractvalue 0 (with-overflow-inst op0, op1))\n; is invalidated by LoopPeel when the operands of with-overflow-inst\n; are changed.\n;\n; In the following case, LoopPeel modifies the CFG into another one\n; with %bb7 not dominating %bb2 and %bb3 although %extractvalue is\n; still the step for the %bb3 loop. %call has been modified and uses\n; different operands but the SCEV value for %extractvalue has not been\n; invalidated and still refers to %load in its SCEV operands\n; (SCEV(%extractvalue) := -2 + -2 * %load).\n;\n; When LoopUnroll tries to compute the SCEV for the %bb3 Phi, the\n; stale data for %extractvalue is used whereas %load is not available\n; in %bb3 which is wrong.\n;\n; for more details and nice pictures: https://github.com/llvm/llvm-project/issues/97586\n;\n; Although the reason for the bug was in forgetValue, it is still relevant to\n; test if LoopPeel invalidates %extractvalue after changing %call.\n;\n; forgetValue only walks the users, so calling it on the IV Phis does not\n; invalidate %extractvalue (thus forgetLoop does not invalidate it too).\n; It has to be done by LoopPeel itself.\n\n\ndefine void @loop_peeling_smul_with_overflow() {\n; before loop-unroll\n; after loop-unroll\n;\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %phi = phi i32 [ 0, %bb ], [ %phi4, %bb3 ]\n br label %bb5\n\nbb2: ; preds = %bb7\n %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8, i32 -2)\n %extractvalue = extractvalue { i32, i1 } %call, 0\n br label %bb3\n\nbb3: ; preds = %bb3, %bb2\n %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]\n %add = add i32 %extractvalue, %phi4\n br i1 false, label %bb3, label %bb1\n\nbb5: ; preds = %bb7, %bb1\n %phi6 = phi i32 [ 1, %bb1 ], [ 0, %bb7 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %bb9, label %bb7\n\nbb7: ; preds = %bb5\n %load = load i32, ptr addrspace(1) null, align 4\n %add8 = add i32 %load, 1\n br i1 false, label %bb2, label %bb5\n\nbb9: ; preds = %bb5\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion Failure in `getSCEV` during loop unroll", "body": "```\r\n; ModuleID = '<stdin>'\r\nsource_filename = \"<stdin>\"\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-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @ham() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb3, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %phi4, %bb3 ]\r\n br label %bb5\r\n\r\nbb2: ; preds = %bb7\r\n %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8, i32 -2)\r\n %extractvalue = extractvalue { i32, i1 } %call, 0\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb3, %bb2\r\n %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]\r\n %add = add i32 %extractvalue, %phi4\r\n br i1 false, label %bb3, label %bb1\r\n\r\nbb5: ; preds = %bb7, %bb1\r\n %phi6 = phi i32 [ 1, %bb1 ], [ 0, %bb7 ]\r\n %icmp = icmp eq i32 %phi, 0\r\n br i1 %icmp, label %bb9, label %bb7\r\n\r\nbb7: ; preds = %bb5\r\n %load = load i32, ptr addrspace(1) null, align 4\r\n %add8 = add i32 %load, 1\r\n br i1 false, label %bb2, label %bb5\r\n\r\nbb9: ; preds = %bb5\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\ncrashes with the below backtrace when run with `opt --passes=\"print<scalar-evolution>,loop-unroll<no-partial;peeling;no-runtime;no-upperbound;no-profile-peeling;full-unroll-max=0;O3> <filename.ll>\"` \r\n```\r\nopt: /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:3678: const llvm::SCEV* llvm::ScalarEvolution::getAddRecExpr(llvm::SmallVectorImpl<const llvm::SCEV*>&, const llvm::Loop*, llvm::SCEV::NoWrapFlags): Assertion `isAvailableAtLoopEntry(Operands[i], L) && \"SCEVAddRecExpr operand is not available at loop entry!\"' 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: /home/manishkh/Workspace7/orcaInstall/installDA/bin/opt --passes=print<scalar-evolution>,loop-unroll<no-partial;peeling;no-runtime;no-upperbound;no-profile-peeling;full-unroll-max=0;O3> reduced2.ll -disable-output\r\n #0 0x00007f272f49aa72 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/manishkh/Workspace7/orca/llvm/lib/Support/Unix/Signals.inc:723:0\r\n #1 0x00007f272f49aeaf PrintStackTraceSignalHandler(void*) /home/manishkh/Workspace7/orca/llvm/lib/Support/Unix/Signals.inc:798:0\r\n #2 0x00007f272f498793 llvm::sys::RunSignalHandlers() /home/manishkh/Workspace7/orca/llvm/lib/Support/Signals.cpp:105:0\r\n #3 0x00007f272f49a459 SignalHandler(int) /home/manishkh/Workspace7/orca/llvm/lib/Support/Unix/Signals.inc:413:0\r\n #4 0x00007f2738fd7630 __restore_rt sigaction.c:0:0\r\n #5 0x00007f272b893387 raise (/lib64/libc.so.6+0x36387)\r\n #6 0x00007f272b894a78 abort (/lib64/libc.so.6+0x37a78)\r\n #7 0x00007f272b88c1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)\r\n #8 0x00007f272b88c252 (/lib64/libc.so.6+0x2f252)\r\n #9 0x00007f2732031da6 llvm::ScalarEvolution::getAddRecExpr(llvm::SmallVectorImpl<llvm::SCEV const*>&, llvm::Loop const*, llvm::SCEV::NoWrapFlags) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:3677:0\r\n#10 0x00007f2732031b29 llvm::ScalarEvolution::getAddRecExpr(llvm::SCEV const*, llvm::SCEV const*, llvm::Loop const*, llvm::SCEV::NoWrapFlags) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:3660:0\r\n#11 0x00007f2732039c11 llvm::ScalarEvolution::createSimpleAffineAddRec(llvm::PHINode*, llvm::Value*, llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:5776:0\r\n#12 0x00007f2732039f65 llvm::ScalarEvolution::createAddRecFromPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:5831:0\r\n#13 0x00007f273203aadf llvm::ScalarEvolution::createNodeForPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:6025:0\r\n#14 0x00007f273204562a llvm::ScalarEvolution::createSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8069:0\r\n#15 0x00007f2732042338 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:7447:0\r\n#16 0x00007f2732035a05 llvm::ScalarEvolution::getSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:4572:0\r\n#17 0x00007f273203ab71 llvm::ScalarEvolution::createNodeForPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:6029:0\r\n#18 0x00007f273204562a llvm::ScalarEvolution::createSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8069:0\r\n#19 0x00007f2732042338 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:7447:0\r\n#20 0x00007f2732035a05 llvm::ScalarEvolution::getSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:4572:0\r\n#21 0x00007f2732039fcf llvm::ScalarEvolution::createAddRecFromPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:5840:0\r\n#22 0x00007f273203aadf llvm::ScalarEvolution::createNodeForPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:6025:0\r\n#23 0x00007f273204562a llvm::ScalarEvolution::createSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8069:0\r\n#24 0x00007f2732042338 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:7447:0\r\n#25 0x00007f2732035a05 llvm::ScalarEvolution::getSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:4572:0\r\n#26 0x00007f273204a26a llvm::ScalarEvolution::computeExitLimitFromICmp(llvm::Loop const*, llvm::ICmpInst*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:9117:0\r\n#27 0x00007f273204971e llvm::ScalarEvolution::computeExitLimitFromCondImpl(llvm::ScalarEvolution::ExitLimitCache&, llvm::Loop const*, llvm::Value*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8975:0\r\n#28 0x00007f273204955b llvm::ScalarEvolution::computeExitLimitFromCondCached(llvm::ScalarEvolution::ExitLimitCache&, llvm::Loop const*, llvm::Value*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8958:0\r\n#29 0x00007f27320491a4 llvm::ScalarEvolution::computeExitLimitFromCond(llvm::Loop const*, llvm::Value*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8914:0\r\n#30 0x00007f2732048f49 llvm::ScalarEvolution::computeExitLimit(llvm::Loop const*, llvm::BasicBlock*, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8888:0\r\n#31 0x00007f27320488db llvm::ScalarEvolution::computeBackedgeTakenCount(llvm::Loop const*, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8797:0\r\n#32 0x00007f27320469fb llvm::ScalarEvolution::getBackedgeTakenInfo(llvm::Loop const*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8358:0\r\n#33 0x00007f27320464ab llvm::ScalarEvolution::getExitCount(llvm::Loop const*, llvm::BasicBlock const*, llvm::ScalarEvolution::ExitCountKind) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8270:0\r\n#34 0x00007f27320460c6 llvm::ScalarEvolution::getSmallConstantTripCount(llvm::Loop const*, llvm::BasicBlock const*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8203:0\r\n#35 0x00007f273146141a tryToUnrollLoop(llvm::Loop*, llvm::DominatorTree&, llvm::LoopInfo*, llvm::ScalarEvolution&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, bool, int, bool, bool, bool, std::optional<unsigned int>, std::optional<unsigned int>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<unsigned int>, llvm::AAResults*) /home/manishkh/Workspace7/orca/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp:1259:0\r\n#36 0x00007f2731462e2c llvm::LoopUnrollPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp:1658:0\r\n#37 0x00007f27339727ac llvm::detail::PassModel<llvm::Function, llvm::LoopUnrollPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManagerInternal.h:91:0\r\n#38 0x00007f272f831f82 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManager.h:228:0\r\n#39 0x00007f27331d1e32 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManagerInternal.h:91:0\r\n#40 0x00007f272f830d12 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/manishkh/Workspace7/orca/llvm/lib/IR/PassManager.cpp:128:0\r\n#41 0x00007f27331d1d96 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManagerInternal.h:91:0\r\n#42 0x00007f272f831c5a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManager.h:228:0\r\n#43 0x00000000004acc3e 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) /home/manishkh/Workspace7/orca/llvm/tools/opt/NewPMDriver.cpp:559:0\r\n#44 0x0000000000477a33 optMain /home/manishkh/Workspace7/orca/llvm/tools/opt/optdriver.cpp:756:0\r\n#45 0x000000000047540f main /home/manishkh/Workspace7/orca/llvm/tools/opt/opt.cpp:25:0\r\n#46 0x00007f272b87f555 __libc_start_main (/lib64/libc.so.6+0x22555)\r\n#47 0x00000000004752c9 _start (/home/manishkh/Workspace7/orcaInstall/installDA/bin/opt+0x4752c9)\r\n```\r\n\r\nas demonstrated by this godbolt example: https://godbolt.org/z/be3a4Yr9e", "author": "Nirhar", "labels": [ "llvm:crash", "llvm:SCEV" ], "comments": [ { "author": "Nirhar", "body": "I did some preliminary analysis on this bug, and here is what I found:\r\nThe IR at the point of crash looks like this:\r\n```\r\ndefine zing void @ham() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1.loopexit: ; preds = %bb3\r\n %phi4.lcssa = phi i32 [ %phi4, %bb3 ]\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1.loopexit, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %phi4.lcssa, %bb1.loopexit ]\r\n br label %bb5.peel.begin\r\n\r\nbb5.peel.begin: ; preds = %bb1\r\n br label %bb5.peel\r\n\r\nbb5.peel: ; preds = %bb5.peel.begin, exiting\r\n %icmp.peel = icmp eq i32 %phi, 0\r\n br i1 %icmp.peel, label %bb9.loopexit2, label %bb7.peel\r\n\r\nbb7.peel: ; preds = %bb5.peel\r\n %load.peel = load i32, ptr addrspace(1) null, align 4\r\n %add8.peel = add i32 %load.peel, 1\r\n br i1 false, label %bb2, label %bb5.peel.next\r\n\r\nbb5.peel.next: ; preds = %bb7.peel\r\n br label %bb5.peel.next1\r\n\r\nbb5.peel.next1: ; preds = %bb5.peel.next\r\n br label %bb1.peel.newph\r\n\r\nbb1.peel.newph: ; preds = %bb5.peel.next1\r\n br label %bb5\r\n\r\nbb2.loopexit: ; preds = %bb7\r\n %add8.lcssa.ph = phi i32 [ %add8, %bb7 ]\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb2.loopexit, %bb7.peel\r\n %add8.lcssa = phi i32 [ %add8.peel, %bb7.peel ], [ %add8.lcssa.ph, %bb2.loopexit ]\r\n %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8.lcssa, i32 -2)\r\n %extractvalue = extractvalue { i32, i1 } %call, 0\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb3, %bb2\r\n %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]\r\n %add = add i32 %extractvalue, %phi4\r\n br i1 false, label %bb3, label %bb1.loopexit\r\n\r\nbb5: ; preds = %bb7, %bb1.peel.newph, exiting\r\n br i1 false, label %bb9.loopexit, label %bb7\r\n\r\nbb7: ; preds = %bb5\r\n %load = load i32, ptr addrspace(1) null, align 4 \r\n %add8 = add i32 %load, 1\r\n br i1 false, label %bb2.loopexit, label %bb5, !llvm.loop !0\r\n\r\nbb9.loopexit: ; preds = %bb5\r\n br label %bb9\r\n\r\nbb9.loopexit2: ; preds = %bb5.peel\r\n br label %bb9\r\n\r\nbb9: ; preds = %bb9.loopexit2, %bb9.loopexit\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\nWe have 3 loops in this this IR(1 outer and 2 inner, out of which the bb5-bb7 loop has been peeled.):\r\n```\r\nLoop at depth 1 containing: %bb1<header>,%bb5<exiting>,%bb7,%bb2,%bb3,%bb1.loopexit<latch>,%bb5.peel.begin,%bb5.peel.next,%bb1.peel.newph,%bb5.peel<exiting>,%bb7.peel,%bb5.peel.next1\r\n Loop at depth 2 containing: %bb5<header><exiting>,%bb7<latch><exiting>\r\n Loop at depth 2 containing: %bb3<header><latch><exiting>\r\n``` \r\nHere is the CFG for this IR:\r\n![Screenshot 2024-07-03 at 8 24 52 PM](https://github.com/llvm/llvm-project/assets/46352931/02e57740-9ef6-4945-868e-62a645325552)\r\n\r\nThe assertion fails because SCEV expects bb7 to properly dominate bb3, which it does in the old IR, but after peeling, it does not. This seems to arise from the fact that SCEVs in %bb2 have not been invalidated after the peeling. I see that the SCEV for `%extractvalue` comes from the ValueExprMap instead of being recomputed, following the peel, and the use of this invalid SCEV is what I think is causing the problem.\r\n\r\n\r\n" }, { "author": "Nirhar", "body": "Perhaps these updates to SE are not enough?\r\nhttps://github.com/llvm/llvm-project/blob/86d456ad8f2aef6edcc36d44d26119025331981e/llvm/lib/Transforms/Utils/LoopPeel.cpp#L1088-L1090" }, { "author": "Nirhar", "body": "@nikic @fhahn @RKSimon is `forgetTopmostLoop` supposed to forget SCEV of all SSA values inside the loop(ie, header, latch and other blocks) ? I see that its implementation does not do that currently." }, { "author": "nikic", "body": "@Nirhar Generally no. It forgets information about induction variables (things based on loop header phis), as well as information pertaining to the loop (such as BECounts, exit values etc), but not of literally everything defined in the loop." }, { "author": "nikic", "body": "From a super quick look, the issue here might be that the exit phi forgetValue() calls don't invalidate enough values due to the condition at https://github.com/llvm/llvm-project/blob/e55585fd7bddf5bb3824a53cbe2971206d3c20c6/llvm/lib/Analysis/ScalarEvolution.cpp#L8415, which means that we will stop at the aggregate results of with.overflow intrinsics, even though SCEV can look through them. It might be that they need special handling." }, { "author": "v01dXYZ", "body": "When replacing the `smul.with.overflow + extractvalue` by a `mul`, it doesn't abort.\r\nWhen removing the SCEVable check, it doesn't abort.\r\n\r\nThe function that allows to traverse unSCEVable when creating the SCEV is `MatchBinaryOp` (cf `createSimpleAffineRec`). We could make this function returns a subset of the use-def to SCEVable or have another function that do the reverse with a def-use matching." }, { "author": "Nirhar", "body": "I think that the issue might be something else. From my analysis, here is how the control flow goes:\r\n1. When we hit `forgetTopmostLoop`, we try to forget the SCEV values of the loop:\r\n```\r\nLoop at depth 1 containing: %bb1<header>,%bb5<exiting>,%bb7,%bb2,%bb3,%bb1.loopexit<latch>,%bb5.peel.begin,%bb5.peel.next,%bb1.peel.newph,%bb5.peel<exiting>,%bb7.peel,%bb5.peel.next1\r\n Loop at depth 2 containing: %bb5<header><exiting>,%bb7<latch><exiting>\r\n Loop at depth 2 containing: %bb3<header><latch><exiting>\r\n```\r\nWe first take the phi node in the header `%phi = phi i32 [ 0, %bb ], [ %phi4.lcssa, %bb1.loopexit ]` and start the DFS from there. From here, we go to the following nodes:(` %icmp.peel = icmp eq i32 %phi, 0` , ` br i1 %icmp.peel, label %bb9.loopexit2, label %bb7.peel` and now non existent `%icmp = icmp eq i32 %phi, 0` , `br i1 %icmp, label %bb9, label %bb7`. The DFS for the outer loop ends here.\r\n\r\n2. Next we traverse the inner loop:\r\n```\r\nLoop at depth 2 containing: %bb3<header><latch><exiting>\r\n```\r\nHere we start with phi node in the header `%phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]` and then traverse through the nodes: `%add = add i32 %extractvalue, %phi4` and `%phi4.lcssa = phi i32 [ %phi4, %bb3 ]`, after which we quit traversal.\r\n\r\n3. Finally we visit the inner loop:\r\n```\r\nLoop at depth 2 containing: %bb5<header><exiting>,%bb7<latch><exiting>\r\n```\r\nWe start and end DFS at (now non-existent)`%phi6 = phi i32 [ 0, %bb1.peel.newph ], [ 0, %bb7 ]`.\r\n\r\n**_TLDR_**; Throughout the entire traversal, we never visit the basic block bb2, and never invalidate its SCEV values. We don't even visit smul intrinsic call to forget its SCEV. Perhaps one needs to consider use-def chains to forget SCEV values, similar to the now considered def-use chain.\r\n\r\nNote: The IR at the point of crash is slightly different from the IR after the previous loop-peel. I've used the term `now non-existent` to mean that that node is not present in the IR at the crash point." }, { "author": "nikic", "body": "@Nirhar The forgetTopmostLoop() call is not what is responsible for the invalidation here, it's the forgetValue() call on the LCSSA phis in https://github.com/llvm/llvm-project/blob/27ccc8835e5163484234549fa6128eeb00d7432d/llvm/lib/Transforms/Utils/LoopPeel.cpp#L862" }, { "author": "Nirhar", "body": "Aah sorry, I missed that. Thanks for pointing it out!" } ] }
true
null
123550
https://github.com/llvm/llvm-project/issues/123550
miscompilation
a3aa452a21f983237873fa85c866b9f0224789bd
2025-01-20T06:37:58
[ "llvm/test/Analysis/ScalarEvolution" ]
{ "fix_commit": "07efe2c18a63423943a4f9d9daeada23601f84c8", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": [ [ 5917, 5936 ] ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::createAddRecFromPHI" ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 07efe2c18a63423943a4f9d9daeada23601f84c8 Author: Nikita Popov <[email protected]> Date: Wed Jan 29 09:09:14 2025 +0100 [SCEV] Check correct value for UB (#124302) This is a followup to #117152. That patch introduced a check for UB/poison on BEValue. However, the SCEV we're actually going to use is Shifted. In some cases, it's possible for Shifted to contain UB, while BEValue doesn't. In the test case the values are: BEValue: (-1 * (zext i8 (-83 + ((-83 /u {1,+,1}<%loop>) * {-1,+,-1}<%loop>)) to i32))<nuw><nsw> Shifted: (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))<nuw><nsw>)<nuw><nsw> Fixes https://github.com/llvm/llvm-project/issues/123550. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7d7d37b3d228..2ce40877b523 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5917,20 +5917,18 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) { // PHI(f(0), f({1,+,1})) --> f({0,+,1}) // Do not allow refinement in rewriting of BEValue. - if (isGuaranteedNotToCauseUB(BEValue)) { - const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this); - const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false); - if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() && - ::impliesPoison(BEValue, Start)) { - const SCEV *StartVal = getSCEV(StartValueV); - if (Start == StartVal) { - // Okay, for the entire analysis of this edge we assumed the PHI - // to be symbolic. We now need to go back and purge all of the - // entries for the scalars that use the symbolic expression. - forgetMemoizedResults(SymbolicName); - insertValueToMap(PN, Shifted); - return Shifted; - } + const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this); + const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false); + if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() && + isGuaranteedNotToCauseUB(Shifted) && ::impliesPoison(Shifted, Start)) { + const SCEV *StartVal = getSCEV(StartValueV); + if (Start == StartVal) { + // Okay, for the entire analysis of this edge we assumed the PHI + // to be symbolic. We now need to go back and purge all of the + // entries for the scalars that use the symbolic expression. + forgetMemoizedResults(SymbolicName); + insertValueToMap(PN, Shifted); + return Shifted; } } }
[ { "file": "llvm/test/Analysis/ScalarEvolution/pr123550.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @src() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n %phi = phi i32 [ -173, %bb ], [ %sub, %bb4 ]\n %phi2 = phi i32 [ 1, %bb ], [ %add, %bb4 ]\n %srem = srem i32 729259140, %phi\n %trunc = trunc i32 %phi2 to i8\n %urem = urem i8 -83, %trunc\n %zext = zext i8 %urem to i32\n %sub = sub nsw i32 0, %zext\n br label %bb4\n\nbb4: ; preds = %bb1\n %add = add nuw nsw i32 %phi2, 1\n %icmp = icmp eq i32 %sub, 0\n br i1 %icmp, label %bb5, label %bb1\n\nbb5: ; preds = %bb4\n %phi6 = phi i32 [ %srem, %bb4 ]\n ret i32 %phi6\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[Indvars] Miscompile: SSA value incorrectly simplified", "body": "One can find the incorrect transformation here: https://godbolt.org/z/T9qMhT7rb\nAnd the proof of incorrect transformation here: https://alive2.llvm.org/ce/z/PXjb5J\n\nFor the record, I describe the problem here. Given the IR:\n```\ndefine i32 @widget() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n %phi = phi i32 [ -173, %bb ], [ %sub, %bb4 ]\n %phi2 = phi i32 [ 1, %bb ], [ %add, %bb4 ]\n %srem = srem i32 729259140, %phi\n %trunc = trunc i32 %phi2 to i8\n %urem = urem i8 -83, %trunc\n %zext = zext i8 %urem to i32\n %sub = sub nsw i32 0, %zext\n br label %bb4\n\nbb4: ; preds = %bb1\n %add = add nuw nsw i32 %phi2, 1\n %icmp = icmp eq i32 %sub, 0\n br i1 %icmp, label %bb5, label %bb1\n\nbb5: ; preds = %bb4\n %phi6 = phi i32 [ %srem, %bb4 ]\n ret i32 %phi6\n}\n```\nwhich returns `srem i32 729259140, -173` which is `130`. The above IR under the `indvars` pass transforms to:\n```\ndefine i32 @widget() {\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n br label %bb4\n\nbb4: ; preds = %bb1\n br i1 true, label %bb5, label %bb1\n\nbb5: ; preds = %bb4\n ret i32 729259140\n}\n```\nwhich returns `729259140` which is the wrong answer. ", "author": "Nirhar", "labels": [ "miscompilation", "release:backport", "llvm:SCEV" ], "comments": [ { "author": "nikic", "body": "Slightly cleaned up:\n```\ndefine i32 @test() {\nbb:\n br label %loop \n\nloop: \n %phi = phi i32 [ -173, %bb ], [ %sub, %loop ]\n %iv2 = phi i32 [ 1, %bb ], [ %iv2.inc, %loop ]\n %srem = srem i32 729259140, %phi\n %trunc = trunc i32 %iv2 to i8\n %urem = urem i8 -83, %trunc\n %zext = zext i8 %urem to i32\n %sub = sub i32 0, %zext \n %iv2.inc = add i32 %iv2, 1\n %icmp = icmp eq i32 %zext, 0\n br i1 %icmp, label %exit, label %loop\n\nexit:\n %srem.lcssa = phi i32 [ %srem, %loop ]\n ret i32 %srem.lcssa\n}\n```\n\nIncorrect exit value is computed by SCEV:\n```\n --> (729259140 + (-1 * (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))<nuw><nsw>)<nuw><nsw> * (729259140 /u (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))<nuw><nsw>)<nuw><nsw>)))<nuw><nsw> U: empty-set S: empty-set\t\tExits: 729259140\t\tLoopDispositions: { %loop: Computable }\n```" } ] }
true
null
102994
https://github.com/llvm/llvm-project/issues/102994
hang
15e915a44f0d0bf092214586d3ec86e2bb7636d7
2024-08-13T02:57:21
[ "llvm/test/Transforms/MemCpyOpt" ]
{ "fix_commit": "378daa6c6fd10d3704be449f2fe9c55df522a6e9", "components": [ "MemCpyOptimizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": [ [ 1193, 1198 ] ], "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": [ "MemCpyOptPass::processMemCpyMemCpyDependence" ], "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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 378daa6c6fd10d3704be449f2fe9c55df522a6e9 Author: Yingwei Zheng <[email protected]> Date: Thu Aug 22 17:20:47 2024 +0800 [MemCpyOpt] Avoid infinite loops in `MemCpyOptPass::processMemCpyMemCpyDependence` (#103218) Closes https://github.com/llvm/llvm-project/issues/102994. diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 1d779128e454..3f15fa2163d2 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1193,6 +1193,10 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M, CopySourceAlign = commonAlignment(*CopySourceAlign, MForwardOffset); } + // Avoid infinite loops + if (BAA.isMustAlias(M->getSource(), CopySource)) + return false; + // Verify that the copied-from memory doesn't change in between the two // transfers. For example, in: // memcpy(a <- b)
[ { "file": "llvm/test/Transforms/MemCpyOpt/pr102994.ll", "commands": [ "opt -S -passes=memcpyopt < %s" ], "tests": [ { "test_name": "func2", "test_body": "@g3 = external global i8, align 1\n\ndefine void @func2(ptr %p) {\nentry:\n %gep1 = getelementptr i8, ptr %p, i64 32\n %gep2 = getelementptr i8, ptr %p, i64 34\n %gep3 = getelementptr i8, ptr %p, i64 32\n call void @llvm.memcpy.p0.p0.i64(ptr %gep1, ptr %gep3, i64 32, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr @g3, ptr %gep2, i64 1, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "func", "test_body": "@g1 = external global i8\n@g2 = external global [64 x i8]\n\ndefine void @func() {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g2, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g2, i64 16), i64 20, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr @g1, ptr getelementptr inbounds (i8, ptr @g2, i64 24), i64 1, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[MemcpyOpt] Infinite loops when forwarding memcpy on globals", "body": "Reproducer: https://godbolt.org/z/GKzGEKE18\r\n```\r\n; bin/opt -passes=memcpyopt 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\n%struct.S1 = type { i64, i16, i32, %struct.S0, i8, i32, i8, i32, i8 }\r\n%struct.S0 = type { i32, i32, i32, i32, i16 }\r\n\r\n@g = external global i8\r\n@g_265 = external global %struct.S1\r\n\r\ndefine void @func() {\r\nentry:\r\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr @g_265, i64 24), i64 1, i1 false)\r\n ret void\r\n}\r\n```\r\n```\r\nFound roots: %entry \r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 0 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nMemCpyOptPass: Forwarding memcpy->memcpy src:\r\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr @g_265, i64 24), i64 1, i1 false)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 0 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nMemCpyOptPass: Forwarding memcpy->memcpy src:\r\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 8), i64 1, i1 false)\r\n...\r\n```", "author": "dtcxzyw", "labels": [ "llvm:hang", "llvm:transforms" ], "comments": [] }
true
null
139202
https://github.com/llvm/llvm-project/issues/139202
miscompilation
8bd35ca41253ea36fff78d5acf59956a30b6555b
2025-05-09T03:49:41
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "c807395011a027caae9ac196edfac328fb90443a", "components": [ "LoopAccessAnalysis", "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 1584, 1590 ], [ 2216, 2222 ], [ 3619, 3627 ], [ 5368, 5374 ], [ 5442, 5448 ], [ 5540, 5547 ], [ 5868, 5874 ], [ 5894, 5900 ], [ 5921, 5931 ], [ 6051, 6059 ], [ 6061, 6069 ], [ 6081, 6089 ], [ 6122, 6128 ], [ 6165, 6174 ], [ 6427, 6434 ], [ 6441, 6450 ], [ 6494, 6503 ], [ 7007, 7013 ], [ 7999, 8005 ], [ 8027, 8040 ], [ 8046, 8052 ], [ 8130, 8144 ], [ 8154, 8160 ], [ 8176, 8186 ], [ 8191, 8206 ], [ 8231, 8240 ], [ 8249, 8255 ], [ 8259, 8265 ], [ 8267, 8273 ], [ 8280, 8288 ], [ 8291, 8298 ], [ 8454, 8481 ], [ 8698, 8709 ], [ 9299, 9308 ], [ 10751, 10757 ], [ 11950, 11956 ], [ 18270, 18281 ], [ 21133, 21150 ], [ 21155, 21161 ], [ 21171, 21177 ], [ 21204, 21210 ], [ 21505, 21511 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": [ [ 1541, 1551 ], [ 1570, 1576 ], [ 1585, 1591 ], [ 1594, 1603 ], [ 1616, 1629 ], [ 1654, 1660 ] ], "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": [ [ 853, 863 ] ], "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::canFormVector", "BoUpSLP::canMapToVector", "BoUpSLP::canVectorizeLoads", "BoUpSLP::collectUserStores", "BoUpSLP::findReusedOrderedScalars", "BoUpSLP::getScalarsVectorizationState", "BoUpSLP::transformNodes", "BoUpSLP::tryToVectorizeGatheredLoads", "BoUpSLP::vectorizeTree", "SLPVectorizerPass::vectorizeStores", "buildCompressMask", "clearVectorizedStores", "clusterSortPtrAccesses", "combineOrders", "fixupOrderingIndices", "gatherPossiblyVectorizableLoads", "getPointerDiff", "getShallowScore", "getStores", "insertOrLookup", "isMaskedLoadCompress", "isStridedLoad", "rebase" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": [ "llvm::getPointersDiff", "llvm::getPtrStride", "llvm::isConsecutiveAccess", "llvm::sortPtrAccesses" ], "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit c807395011a027caae9ac196edfac328fb90443a Author: Ramkumar Ramachandra <[email protected]> Date: Thu May 15 10:08:05 2025 +0100 [LAA/SLP] Don't truncate APInt in getPointersDiff (#139941) Change getPointersDiff to return an std::optional<int64_t>, and fill this value with using APInt::trySExtValue. This simple change requires changes to other functions in LAA, and major changes in SLPVectorizer changing types from 32-bit to 64-bit. Fixes #139202. diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h index f715e0ec8dbb..fea2ede8b5ab 100644 --- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h +++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h @@ -853,11 +853,10 @@ getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, /// is a simple API that does not depend on the analysis pass. /// \param StrictCheck Ensure that the calculated distance matches the /// type-based one after all the bitcasts removal in the provided pointers. -std::optional<int> getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, - Value *PtrB, const DataLayout &DL, - ScalarEvolution &SE, - bool StrictCheck = false, - bool CheckType = true); +std::optional<int64_t> +getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, Value *PtrB, + const DataLayout &DL, ScalarEvolution &SE, + bool StrictCheck = false, bool CheckType = true); /// Attempt to sort the pointers in \p VL and return the sorted indices /// in \p SortedIndices, if reordering is required. diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index af1a3c593c51..ab407e945bc5 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1541,11 +1541,11 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, return std::nullopt; } -std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, - Type *ElemTyB, Value *PtrB, - const DataLayout &DL, - ScalarEvolution &SE, bool StrictCheck, - bool CheckType) { +std::optional<int64_t> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, + Type *ElemTyB, Value *PtrB, + const DataLayout &DL, + ScalarEvolution &SE, + bool StrictCheck, bool CheckType) { assert(PtrA && PtrB && "Expected non-nullptr pointers."); // Make sure that A and B are different pointers. @@ -1570,7 +1570,7 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, const Value *PtrB1 = PtrB->stripAndAccumulateConstantOffsets( DL, OffsetB, /*AllowNonInbounds=*/true); - int Val; + std::optional<int64_t> Val; if (PtrA1 == PtrB1) { // Retrieve the address space again as pointer stripping now tracks through // `addrspacecast`. @@ -1585,7 +1585,7 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, OffsetB = OffsetB.sextOrTrunc(IdxWidth); OffsetB -= OffsetA; - Val = OffsetB.getSExtValue(); + Val = OffsetB.trySExtValue(); } else { // Otherwise compute the distance with SCEV between the base pointers. const SCEV *PtrSCEVA = SE.getSCEV(PtrA); @@ -1594,10 +1594,14 @@ std::optional<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, SE.computeConstantDifference(PtrSCEVB, PtrSCEVA); if (!Diff) return std::nullopt; - Val = Diff->getSExtValue(); + Val = Diff->trySExtValue(); } - int Size = DL.getTypeStoreSize(ElemTyA); - int Dist = Val / Size; + + if (!Val) + return std::nullopt; + + int64_t Size = DL.getTypeStoreSize(ElemTyA); + int64_t Dist = *Val / Size; // Ensure that the calculated distance matches the type-based one after all // the bitcasts removal in the provided pointers. @@ -1616,14 +1620,15 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy, // first pointer in the array. Value *Ptr0 = VL[0]; - using DistOrdPair = std::pair<int64_t, int>; + using DistOrdPair = std::pair<int64_t, unsigned>; auto Compare = llvm::less_first(); std::set<DistOrdPair, decltype(Compare)> Offsets(Compare); Offsets.emplace(0, 0); bool IsConsecutive = true; for (auto [Idx, Ptr] : drop_begin(enumerate(VL))) { - std::optional<int> Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE, - /*StrictCheck=*/true); + std::optional<int64_t> Diff = + getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE, + /*StrictCheck=*/true); if (!Diff) return false; @@ -1654,7 +1659,7 @@ bool llvm::isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL, return false; Type *ElemTyA = getLoadStoreType(A); Type *ElemTyB = getLoadStoreType(B); - std::optional<int> Diff = + std::optional<int64_t> Diff = getPointersDiff(ElemTyA, PtrA, ElemTyB, PtrB, DL, SE, /*StrictCheck=*/true, CheckType); return Diff && *Diff == 1; diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d8cf6b82a197..eb339282fdae 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1584,7 +1584,7 @@ static void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask, /// before: 6 9 5 4 9 2 1 0 /// after: 6 3 5 4 7 2 1 0 static void fixupOrderingIndices(MutableArrayRef<unsigned> Order) { - const unsigned Sz = Order.size(); + const size_t Sz = Order.size(); SmallBitVector UnusedIndices(Sz, /*t=*/true); SmallBitVector MaskedIndices(Sz); for (unsigned I = 0; I < Sz; ++I) { @@ -2216,7 +2216,7 @@ public: !LI2->isSimple()) return CheckSameEntryOrFail(); - std::optional<int> Dist = getPointersDiff( + std::optional<int64_t> Dist = getPointersDiff( LI1->getType(), LI1->getPointerOperand(), LI2->getType(), LI2->getPointerOperand(), DL, SE, /*StrictCheck=*/true); if (!Dist || *Dist == 0) { @@ -3619,9 +3619,10 @@ private: /// vector loads/masked gathers instead of regular gathers. Later these loads /// are reshufled to build final gathered nodes. void tryToVectorizeGatheredLoads( - const SmallMapVector<std::tuple<BasicBlock *, Value *, Type *>, - SmallVector<SmallVector<std::pair<LoadInst *, int>>>, - 8> &GatheredLoads); + const SmallMapVector< + std::tuple<BasicBlock *, Value *, Type *>, + SmallVector<SmallVector<std::pair<LoadInst *, int64_t>>>, 8> + &GatheredLoads); /// Helper for `findExternalStoreUsersReorderIndices()`. It iterates over the /// users of \p TE and collects the stores. It returns the map from the store @@ -5368,7 +5369,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE, // patterns. SmallVector<Value *> GatheredScalars(TE.Scalars.begin(), TE.Scalars.end()); Type *ScalarTy = GatheredScalars.front()->getType(); - int NumScalars = GatheredScalars.size(); + size_t NumScalars = GatheredScalars.size(); if (!isValidElementType(ScalarTy)) return std::nullopt; auto *VecTy = getWidenedType(ScalarTy, NumScalars); @@ -5442,7 +5443,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE, unsigned Limit = getNumElems(CurrentOrder.size(), PartSz, I); MutableArrayRef<unsigned> Slice = CurrentOrder.slice(I * PartSz, Limit); // Shuffle of at least 2 vectors - ignore. - if (any_of(Slice, [&](int I) { return I != NumScalars; })) { + if (any_of(Slice, [&](unsigned I) { return I != NumScalars; })) { std::fill(Slice.begin(), Slice.end(), NumScalars); ShuffledSubMasks.set(I); continue; @@ -5540,8 +5541,8 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE, return std::max(Entries[I].front()->getVectorFactor(), Entries[I].back()->getVectorFactor()); }); - int NumUndefs = - count_if(CurrentOrder, [&](int Idx) { return Idx == NumScalars; }); + unsigned NumUndefs = + count_if(CurrentOrder, [&](unsigned Idx) { return Idx == NumScalars; }); if (ShuffledSubMasks.all() || (NumScalars > 2 && NumUndefs >= NumScalars / 2)) return std::nullopt; return std::move(CurrentOrder); @@ -5868,7 +5869,11 @@ static bool buildCompressMask(ArrayRef<Value *> PointerOps, Value *Ptr0 = Order.empty() ? PointerOps.front() : PointerOps[Order.front()]; for (unsigned I : seq<unsigned>(1, Sz)) { Value *Ptr = Order.empty() ? PointerOps[I] : PointerOps[Order[I]]; - unsigned Pos = *getPointersDiff(ScalarTy, Ptr0, ScalarTy, Ptr, DL, SE); + std::optional<int64_t> OptPos = + getPointersDiff(ScalarTy, Ptr0, ScalarTy, Ptr, DL, SE); + if (!OptPos || OptPos > std::numeric_limits<unsigned>::max()) + return false; + unsigned Pos = static_cast<unsigned>(*OptPos); CompressMask[I] = Pos; if (!Stride) continue; @@ -5894,7 +5899,7 @@ static bool isMaskedLoadCompress( VectorType *&LoadVecTy) { InterleaveFactor = 0; Type *ScalarTy = VL.front()->getType(); - const unsigned Sz = VL.size(); + const size_t Sz = VL.size(); auto *VecTy = getWidenedType(ScalarTy, Sz); constexpr TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; SmallVector<int> Mask; @@ -5921,11 +5926,11 @@ static bool isMaskedLoadCompress( Ptr0 = PointerOps[Order.front()]; PtrN = PointerOps[Order.back()]; } - std::optional<int> Diff = + std::optional<int64_t> Diff = getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, DL, SE); if (!Diff) return false; - const unsigned MaxRegSize = + const size_t MaxRegSize = TTI.getRegisterBitWidth(TargetTransformInfo::RGK_FixedWidthVector) .getFixedValue(); // Check for very large distances between elements. @@ -6051,9 +6056,10 @@ static bool isStridedLoad(ArrayRef<Value *> VL, ArrayRef<Value *> PointerOps, ArrayRef<unsigned> Order, const TargetTransformInfo &TTI, const DataLayout &DL, ScalarEvolution &SE, - const bool IsAnyPointerUsedOutGraph, const int Diff) { - const unsigned Sz = VL.size(); - const unsigned AbsoluteDiff = std::abs(Diff); + const bool IsAnyPointerUsedOutGraph, + const int64_t Diff) { + const size_t Sz = VL.size(); + const uint64_t AbsoluteDiff = std::abs(Diff); Type *ScalarTy = VL.front()->getType(); auto *VecTy = getWidenedType(ScalarTy, Sz); if (IsAnyPointerUsedOutGraph || @@ -6061,9 +6067,9 @@ static bool isStridedLoad(ArrayRef<Value *> VL, ArrayRef<Value *> PointerOps, (Sz > MinProfitableStridedLoads || (AbsoluteDiff <= MaxProfitableLoadStride * Sz && AbsoluteDiff % Sz == 0 && has_single_bit(AbsoluteDiff / Sz)))) || - Diff == -(static_cast<int>(Sz) - 1)) { - int Stride = Diff / static_cast<int>(Sz - 1); - if (Diff != Stride * static_cast<int>(Sz - 1)) + Diff == -(static_cast<int64_t>(Sz) - 1)) { + int64_t Stride = Diff / static_cast<int64_t>(Sz - 1); + if (Diff != Stride * static_cast<int64_t>(Sz - 1)) return false; Align Alignment = cast<LoadInst>(Order.empty() ? VL.front() : VL[Order.front()]) @@ -6081,9 +6087,9 @@ static bool isStridedLoad(ArrayRef<Value *> VL, ArrayRef<Value *> PointerOps, } // Iterate through all pointers and check if all distances are // unique multiple of Dist. - SmallSet<int, 4> Dists; + SmallSet<int64_t, 4> Dists; for (Value *Ptr : PointerOps) { - int Dist = 0; + int64_t Dist = 0; if (Ptr == PtrN) Dist = Diff; else if (Ptr != Ptr0) @@ -6122,7 +6128,7 @@ BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0, // Make sure all loads in the bundle are simple - we can't vectorize // atomic or volatile loads. PointerOps.clear(); - const unsigned Sz = VL.size(); + const size_t Sz = VL.size(); PointerOps.resize(Sz); auto *POIter = PointerOps.begin(); for (Value *V : VL) { @@ -6165,10 +6171,10 @@ BoUpSLP::canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0, Ptr0 = PointerOps[Order.front()]; PtrN = PointerOps[Order.back()]; } - std::optional<int> Diff = + std::optional<int64_t> Diff = getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, *DL, *SE); // Check that the sorted loads are consecutive. - if (static_cast<unsigned>(*Diff) == Sz - 1) + if (static_cast<uint64_t>(*Diff) == Sz - 1) return LoadsState::Vectorize; if (isMaskedLoadCompress(VL, PointerOps, Order, *TTI, *DL, *SE, *AC, *DT, *TLI, [&](Value *V) { @@ -6427,8 +6433,9 @@ static bool clusterSortPtrAccesses(ArrayRef<Value *> VL, // Map from bases to a vector of (Ptr, Offset, OrigIdx), which we insert each // Ptr into, sort and return the sorted indices with values next to one // another. - SmallMapVector<std::pair<BasicBlock *, Value *>, - SmallVector<SmallVector<std::tuple<Value *, int, unsigned>>>, 8> + SmallMapVector< + std::pair<BasicBlock *, Value *>, + SmallVector<SmallVector<std::tuple<Value *, int64_t, unsigned>>>, 8> Bases; Bases .try_emplace(std::make_pair( @@ -6441,10 +6448,10 @@ static bool clusterSortPtrAccesses(ArrayRef<Value *> VL, getUnderlyingObject(Ptr, RecursionMaxDepth)); bool Found = any_of(Bases.try_emplace(Key).first->second, [&, &Cnt = Cnt, &Ptr = Ptr](auto &Base) { - std::optional<int> Diff = getPointersDiff( - ElemTy, std::get<0>(Base.front()), ElemTy, - Ptr, DL, SE, - /*StrictCheck=*/true); + std::optional<int64_t> Diff = + getPointersDiff(ElemTy, std::get<0>(Base.front()), + ElemTy, Ptr, DL, SE, + /*StrictCheck=*/true); if (!Diff) return false; @@ -6494,10 +6501,11 @@ static bool clusterSortPtrAccesses(ArrayRef<Value *> VL, for (auto &Vec : Base.second) { if (Vec.size() > 1) { stable_sort(Vec, llvm::less_second()); - int InitialOffset = std::get<1>(Vec[0]); + int64_t InitialOffset = std::get<1>(Vec[0]); bool AnyConsecutive = all_of(enumerate(Vec), [InitialOffset](const auto &P) { - return std::get<1>(P.value()) == int(P.index()) + InitialOffset; + return std::get<1>(P.value()) == + int64_t(P.index()) + InitialOffset; }); // Fill SortedIndices array only if it looks worth-while to sort the // ptrs. @@ -7007,7 +7015,7 @@ static void combineOrders(MutableArrayRef<unsigned> Order, ArrayRef<unsigned> SecondaryOrder) { assert((SecondaryOrder.empty() || Order.size() == SecondaryOrder.size()) && "Expected same size of orders"); - unsigned Sz = Order.size(); + size_t Sz = Order.size(); SmallBitVector UsedIndices(Sz); for (unsigned Idx : seq<unsigned>(0, Sz)) { if (Order[Idx] != Sz) @@ -7999,7 +8007,7 @@ BoUpSLP::collectUserStores(const BoUpSLP::TreeEntry *TE) const { if (StoresVec.size() > Lane) continue; if (!StoresVec.empty()) { - std::optional<int> Diff = getPointersDiff( + std::optional<int64_t> Diff = getPointersDiff( SI->getValueOperand()->getType(), SI->getPointerOperand(), SI->getValueOperand()->getType(), StoresVec.front()->getPointerOperand(), *DL, *SE, @@ -8027,14 +8035,14 @@ bool BoUpSLP::canFormVector(ArrayRef<StoreInst *> StoresVec, // To avoid calling getPointersDiff() while sorting we create a vector of // pairs {store, offset from first} and sort this instead. - SmallVector<std::pair<int, unsigned>> StoreOffsetVec; + SmallVector<std::pair<int64_t, unsigned>> StoreOffsetVec; StoreInst *S0 = StoresVec[0]; StoreOffsetVec.emplace_back(0, 0); Type *S0Ty = S0->getValueOperand()->getType(); Value *S0Ptr = S0->getPointerOperand(); for (unsigned Idx : seq<unsigned>(1, StoresVec.size())) { StoreInst *SI = StoresVec[Idx]; - std::optional<int> Diff = + std::optional<int64_t> Diff = getPointersDiff(S0Ty, S0Ptr, SI->getValueOperand()->getType(), SI->getPointerOperand(), *DL, *SE, /*StrictCheck=*/true); @@ -8046,7 +8054,7 @@ bool BoUpSLP::canFormVector(ArrayRef<StoreInst *> StoresVec, return false; sort(StoreOffsetVec, llvm::less_first()); unsigned Idx = 0; - int PrevDist = 0; + int64_t PrevDist = 0; for (const auto &P : StoreOffsetVec) { if (Idx > 0 && P.first != PrevDist + 1) return false; @@ -8130,15 +8138,15 @@ void BoUpSLP::buildTree(ArrayRef<Value *> Roots) { static void gatherPossiblyVectorizableLoads( const BoUpSLP &R, ArrayRef<Value *> VL, const DataLayout &DL, ScalarEvolution &SE, const TargetTransformInfo &TTI, - SmallVectorImpl<SmallVector<std::pair<LoadInst *, int>>> &GatheredLoads, + SmallVectorImpl<SmallVector<std::pair<LoadInst *, int64_t>>> &GatheredLoads, bool AddNew = true) { if (VL.empty()) return; Type *ScalarTy = getValueType(VL.front()); if (!isValidElementType(ScalarTy)) return; - SmallVector<SmallVector<std::pair<LoadInst *, int>>> ClusteredLoads; - SmallVector<DenseMap<int, LoadInst *>> ClusteredDistToLoad; + SmallVector<SmallVector<std::pair<LoadInst *, int64_t>>> ClusteredLoads; + SmallVector<DenseMap<int64_t, LoadInst *>> ClusteredDistToLoad; for (Value *V : VL) { auto *LI = dyn_cast<LoadInst>(V); if (!LI) @@ -8154,7 +8162,7 @@ static void gatherPossiblyVectorizableLoads( RecursionMaxDepth) && "Expected loads with the same type, same parent and same " "underlying pointer."); - std::optional<int> Dist = getPointersDiff( + std::optional<int64_t> Dist = getPointersDiff( LI->getType(), LI->getPointerOperand(), Data.front().first->getType(), Data.front().first->getPointerOperand(), DL, SE, /*StrictCheck=*/true); @@ -8176,11 +8184,11 @@ static void gatherPossiblyVectorizableLoads( } } auto FindMatchingLoads = - [&](ArrayRef<std::pair<LoadInst *, int>> Loads, - SmallVectorImpl<SmallVector<std::pair<LoadInst *, int>>> + [&](ArrayRef<std::pair<LoadInst *, int64_t>> Loads, + SmallVectorImpl<SmallVector<std::pair<LoadInst *, int64_t>>> &GatheredLoads, SetVector<unsigned> &ToAdd, SetVector<unsigned> &Repeated, - int &Offset, unsigned &Start) { + int64_t &Offset, unsigned &Start) { if (Loads.empty()) return GatheredLoads.end(); LoadInst *LI = Loads.front().first; @@ -8191,16 +8199,16 @@ static void gatherPossiblyVectorizableLoads( if (LI->getParent() != Data.front().first->getParent() || LI->getType() != Data.front().first->getType()) continue; - std::optional<int> Dist = + std::optional<int64_t> Dist = getPointersDiff(LI->getType(), LI->getPointerOperand(), Data.front().first->getType(), Data.front().first->getPointerOperand(), DL, SE, /*StrictCheck=*/true); if (!Dist) continue; - SmallSet<int, 4> DataDists; + SmallSet<int64_t, 4> DataDists; SmallPtrSet<LoadInst *, 4> DataLoads; - for (std::pair<LoadInst *, int> P : Data) { + for (std::pair<LoadInst *, int64_t> P : Data) { DataDists.insert(P.second); DataLoads.insert(P.first); } @@ -8231,10 +8239,10 @@ static void gatherPossiblyVectorizableLoads( ToAdd.clear(); return GatheredLoads.end(); }; - for (ArrayRef<std::pair<LoadInst *, int>> Data : ClusteredLoads) { + for (ArrayRef<std::pair<LoadInst *, int64_t>> Data : ClusteredLoads) { unsigned Start = 0; SetVector<unsigned> ToAdd, LocalToAdd, Repeated; - int Offset = 0; + int64_t Offset = 0; auto *It = FindMatchingLoads(Data, GatheredLoads, LocalToAdd, Repeated, Offset, Start); while (It != GatheredLoads.end()) { @@ -8249,7 +8257,7 @@ static void gatherPossiblyVectorizableLoads( return !ToAdd.contains(Idx) && !Repeated.contains(Idx); })) { auto AddNewLoads = - [&](SmallVectorImpl<std::pair<LoadInst *, int>> &Loads) { + [&](SmallVectorImpl<std::pair<LoadInst *, int64_t>> &Loads) { for (unsigned Idx : seq<unsigned>(Data.size())) { if (ToAdd.contains(Idx) || Repeated.contains(Idx)) continue; @@ -8259,7 +8267,7 @@ static void gatherPossiblyVectorizableLoads( if (!AddNew) { LoadInst *LI = Data.front().first; It = find_if( - GatheredLoads, [&](ArrayRef<std::pair<LoadInst *, int>> PD) { + GatheredLoads, [&](ArrayRef<std::pair<LoadInst *, int64_t>> PD) { return PD.front().first->getParent() == LI->getParent() && PD.front().first->getType() == LI->getType(); }); @@ -8267,7 +8275,7 @@ static void gatherPossiblyVectorizableLoads( AddNewLoads(*It); It = std::find_if( std::next(It), GatheredLoads.end(), - [&](ArrayRef<std::pair<LoadInst *, int>> PD) { + [&](ArrayRef<std::pair<LoadInst *, int64_t>> PD) { return PD.front().first->getParent() == LI->getParent() && PD.front().first->getType() == LI->getType(); }); @@ -8280,9 +8288,10 @@ static void gatherPossiblyVectorizableLoads( } void BoUpSLP::tryToVectorizeGatheredLoads( - const SmallMapVector<std::tuple<BasicBlock *, Value *, Type *>, - SmallVector<SmallVector<std::pair<LoadInst *, int>>>, - 8> &GatheredLoads) { + const SmallMapVector< + std::tuple<BasicBlock *, Value *, Type *>, + SmallVector<SmallVector<std::pair<LoadInst *, int64_t>>>, 8> + &GatheredLoads) { GatheredLoadsEntriesFirst = VectorizableTree.size(); SmallVector<SmallPtrSet<const Value *, 4>> LoadSetsToVectorize( @@ -8291,8 +8300,8 @@ void BoUpSLP::tryToVectorizeGatheredLoads( Set.insert_range(VectorizableTree[Idx]->Scalars); // Sort loads by distance. - auto LoadSorter = [](const std::pair<LoadInst *, int> &L1, - const std::pair<LoadInst *, int> &L2) { + auto LoadSorter = [](const std::pair<LoadInst *, int64_t> &L1, + const std::pair<LoadInst *, int64_t> &L2) { return L1.second > L2.second; }; @@ -8454,28 +8463,30 @@ void BoUpSLP::tryToVectorizeGatheredLoads( }; auto ProcessGatheredLoads = [&, &TTI = *TTI]( - ArrayRef<SmallVector<std::pair<LoadInst *, int>>> GatheredLoads, + ArrayRef<SmallVector<std::pair<LoadInst *, int64_t>>> GatheredLoads, bool Final = false) { SmallVector<LoadInst *> NonVectorized; - for (ArrayRef<std::pair<LoadInst *, int>> LoadsDists : GatheredLoads) { + for (ArrayRef<std::pair<LoadInst *, int64_t>> LoadsDists : + GatheredLoads) { if (LoadsDists.size() <= 1) { NonVectorized.push_back(LoadsDists.back().first); continue; } - SmallVector<std::pair<LoadInst *, int>> LocalLoadsDists(LoadsDists); + SmallVector<std::pair<LoadInst *, int64_t>> LocalLoadsDists( + LoadsDists); SmallVector<LoadInst *> OriginalLoads(make_first_range(LoadsDists)); stable_sort(LocalLoadsDists, LoadSorter); SmallVector<LoadInst *> Loads; unsigned MaxConsecutiveDistance = 0; unsigned CurrentConsecutiveDist = 1; - int LastDist = LocalLoadsDists.front().second; + int64_t LastDist = LocalLoadsDists.front().second; bool AllowMaskedGather = IsMaskedGatherSupported(OriginalLoads); - for (const std::pair<LoadInst *, int> &L : LocalLoadsDists) { + for (const std::pair<LoadInst *, int64_t> &L : LocalLoadsDists) { if (isVectorized(L.first)) continue; assert(LastDist >= L.second && "Expected first distance always not less than second"); - if (static_cast<unsigned>(LastDist - L.second) == + if (static_cast<uint64_t>(LastDist - L.second) == CurrentConsecutiveDist) { ++CurrentConsecutiveDist; MaxConsecutiveDistance = @@ -8698,12 +8709,12 @@ void BoUpSLP::tryToVectorizeGatheredLoads( if (!Ref.empty() && !NonVectorized.empty() && std::accumulate( Ref.begin(), Ref.end(), 0u, - [](unsigned S, - ArrayRef<std::pair<LoadInst *, int>> LoadsDists) -> unsigned { - return S + LoadsDists.size(); - }) != NonVectorized.size() && + [](unsigned S, ArrayRef<std::pair<LoadInst *, int64_t>> LoadsDists) + -> unsigned { return S + LoadsDists.size(); }) != + NonVectorized.size() && IsMaskedGatherSupported(NonVectorized)) { - SmallVector<SmallVector<std::pair<LoadInst *, int>>> FinalGatheredLoads; + SmallVector<SmallVector<std::pair<LoadInst *, int64_t>>> + FinalGatheredLoads; for (LoadInst *LI : NonVectorized) { // Reinsert non-vectorized loads to other list of loads with the same // base pointers. @@ -9299,10 +9310,10 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState( Ptr0 = PointerOps[CurrentOrder.front()]; PtrN = PointerOps[CurrentOrder.back()]; } - std::optional<int> Dist = + std::optional<int64_t> Dist = getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, *DL, *SE); // Check that the sorted pointer operands are consecutive. - if (static_cast<unsigned>(*Dist) == VL.size() - 1) + if (static_cast<uint64_t>(*Dist) == VL.size() - 1) return TreeEntry::Vectorize; } @@ -10751,7 +10762,7 @@ unsigned BoUpSLP::canMapToVector(Type *T) const { if (!isValidElementType(EltTy)) return 0; - uint64_t VTSize = DL->getTypeStoreSizeInBits(getWidenedType(EltTy, N)); + size_t VTSize = DL->getTypeStoreSizeInBits(getWidenedType(EltTy, N)); if (VTSize < MinVecRegSize || VTSize > MaxVecRegSize || VTSize != DL->getTypeStoreSizeInBits(T)) return 0; @@ -11950,7 +11961,7 @@ void BoUpSLP::transformNodes() { // A list of loads to be gathered during the vectorization process. We can // try to vectorize them at the end, if profitable. SmallMapVector<std::tuple<BasicBlock *, Value *, Type *>, - SmallVector<SmallVector<std::pair<LoadInst *, int>>>, 8> + SmallVector<SmallVector<std::pair<LoadInst *, int64_t>>>, 8> GatheredLoads; for (std::unique_ptr<TreeEntry> &TE : VectorizableTree) { @@ -18270,12 +18281,13 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { Value *Ptr0 = cast<LoadInst>(E->Scalars.front())->getPointerOperand(); Value *PtrN = cast<LoadInst>(E->Scalars.back())->getPointerOperand(); PO = IsReverseOrder ? PtrN : Ptr0; - std::optional<int> Diff = getPointersDiff( + std::optional<int64_t> Diff = getPointersDiff( VL0->getType(), Ptr0, VL0->getType(), PtrN, *DL, *SE); Type *StrideTy = DL->getIndexType(PO->getType()); Value *StrideVal; if (Diff) { - int Stride = *Diff / (static_cast<int>(E->Scalars.size()) - 1); + int64_t Stride = + *Diff / (static_cast<int64_t>(E->Scalars.size()) - 1); StrideVal = ConstantInt::get(StrideTy, (IsReverseOrder ? -1 : 1) * Stride * DL->getTypeAllocSize(ScalarTy)); @@ -21133,18 +21145,18 @@ public: /// \p PtrDist. /// Does nothing if there is already a store with that \p PtrDist. /// \returns The previously associated Instruction index, or std::nullopt - std::optional<unsigned> insertOrLookup(unsigned InstrIdx, int PtrDist) { + std::optional<unsigned> insertOrLookup(unsigned InstrIdx, int64_t PtrDist) { auto [It, Inserted] = Instrs.emplace(PtrDist, InstrIdx); - return Inserted ? std::nullopt : std::optional<unsigned>(It->second); + return Inserted ? std::nullopt : std::make_optional(It->second); } - using DistToInstMap = std::map<int, unsigned>; + using DistToInstMap = std::map<int64_t, unsigned>; const DistToInstMap &getStores() const { return Instrs; } /// If \p SI is related to this group of stores, return the distance of its /// pointer operand to the one the group's BaseInstr. - std::optional<int> getPointerDiff(StoreInst &SI, const DataLayout &DL, - ScalarEvolution &SE) const { + std::optional<int64_t> getPointerDiff(StoreInst &SI, const DataLayout &DL, + ScalarEvolution &SE) const { StoreInst &BaseStore = *AllStores[BaseInstrIdx]; return getPointersDiff( BaseStore.getValueOperand()->getType(), BaseStore.getPointerOperand(), @@ -21155,7 +21167,7 @@ public: /// Recompute the pointer distances to be based on \p NewBaseInstIdx. /// Stores whose index is less than \p MinSafeIdx will be dropped. void rebase(unsigned MinSafeIdx, unsigned NewBaseInstIdx, - int DistFromCurBase) { + int64_t DistFromCurBase) { DistToInstMap PrevSet = std::move(Instrs); reset(NewBaseInstIdx); @@ -21171,7 +21183,7 @@ public: /// Remove all stores that have been vectorized from this group. void clearVectorizedStores(const BoUpSLP::ValueSet &VectorizedStores) { DistToInstMap::reverse_iterator LastVectorizedStore = find_if( - reverse(Instrs), [&](const std::pair<int, unsigned> &DistAndIdx) { + reverse(Instrs), [&](const std::pair<int64_t, unsigned> &DistAndIdx) { return VectorizedStores.contains(AllStores[DistAndIdx.second]); }); @@ -21204,7 +21216,7 @@ bool SLPVectorizerPass::vectorizeStores( bool Changed = false; auto TryToVectorize = [&](const RelatedStoreInsts::DistToInstMap &StoreSeq) { - int PrevDist = -1; + int64_t PrevDist = -1; BoUpSLP::ValueList Operands; // Collect the chain into a list. for (auto [Idx, Data] : enumerate(StoreSeq)) { @@ -21505,7 +21517,7 @@ bool SLPVectorizerPass::vectorizeStores( // dependencies and no need to waste compile time to try to vectorize them. // - Try to vectorize the sequence {1, {1, 0}, {3, 2}}. auto FillStoresSet = [&](unsigned Idx, StoreInst *SI) { - std::optional<int> PtrDist; + std::optional<int64_t> PtrDist; auto *RelatedStores = find_if( SortedStores, [&PtrDist, SI, this](const RelatedStoreInsts &StoreSeq) { PtrDist = StoreSeq.getPointerDiff(*SI, *DL, *SE);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/long-pointer-distance.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-grtev4-linux-gnu < %s -mattr=+avx" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %this) {\nentry:\n store i64 1, ptr %this, align 8\n %b = getelementptr i8, ptr %this, i64 8\n store i64 2, ptr %b, align 8\n %c = getelementptr i8, ptr %this, i64 4294967312\n store i64 3, ptr %c, align 8\n %d = getelementptr i8, ptr %this, i64 4294967320\n store i64 4, ptr %d, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPV] Pointer offsets truncated to 32-bits, resulting in wrong code", "body": "Consider:\n\n```\n$ cat t.ll\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\"\ntarget triple = \"x86_64-grtev4-linux-gnu\"\n\ndefine void @_ZN12_GLOBAL__N_111LargeObjectILm4294967296EEC2Em(ptr %this) #0 {\nentry:\n store i64 1, ptr %this, align 8\n %b = getelementptr i8, ptr %this, i64 8\n store i64 2, ptr %b, align 8\n %c = getelementptr i8, ptr %this, i64 u0x100000010\n store i64 3, ptr %c, align 8\n %d = getelementptr i8, ptr %this, i64 u0x100000018\n store i64 4, ptr %d, align 8\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+aes,+avx,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+prfchw,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave\" }\n\n$ opt -passes=slp-vectorizer t.ll -S -o -\n; ModuleID = 't.ll'\nsource_filename = \"t.ll\"\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\"\ntarget triple = \"x86_64-grtev4-linux-gnu\"\n\ndefine void @_ZN12_GLOBAL__N_111LargeObjectILm4294967296EEC2Em(ptr %this) #0 {\nentry:\n store <4 x i64> <i64 1, i64 2, i64 3, i64 4>, ptr %this, align 8\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+aes,+avx,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+prfchw,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave\" }\n```\n\nClearly, somewhere inside SLPV, the GEP offsets here are truncated from 64-bits to 32. To quickly check SLPV with static analysis, I did this:\n\n```\n$ ninja opt # build everything once\n$ touch ../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp\n$ CCC_OVERRIDE_OPTIONS='+-Wshorten-64-to-32' ninja opt | tee slpv-truncations.txt\n...\n```\n\nUnfortunately, there are 733 hits:\n```\n$ grep warning: slpv-truncations.txt | wc -l\n 733\n```\n\nThis is not a recent regression, it goes back to LLVM 14 and earlier: https://godbolt.org/z/9baE551T7 LLVM 14 is just as far back as the IR is parseable out of the box.\n\nI think the next move here would be to do a global search & replace of getZExtValue with some variant that asserts when the result is wider than 32-bits, or to focus only on the warnings that include getZExtValue in the warning text snippet.", "author": "rnk", "labels": [ "miscompilation", "llvm:SLPVectorizer", "llvm:analysis" ], "comments": [ { "author": "alexey-bataev", "body": "LoopAccessAnalysis.cpp, getPointersDiff() returns distance -16 for pointers %b and %d, there is an implicit cast from int64_t to int, which looses the info\nhttps://github.com/llvm/llvm-project/blob/9eeae5a5de41b22d31d9037be2acc45dd7af4192/llvm/lib/Analysis/LoopAccessAnalysis.cpp#L1598\nhttps://github.com/llvm/llvm-project/blob/9eeae5a5de41b22d31d9037be2acc45dd7af4192/llvm/lib/Analysis/LoopAccessAnalysis.cpp#L1589\n" } ] }
true
null
80836
https://github.com/llvm/llvm-project/issues/80836
crash
ea2d9383a23ca17b9240ad64c2adc5f2b5a73dc0
2024-02-06T14:26:26
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "1c10821022f1799452065fb57474e894e2562b7f", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 2010, 2025 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "getCost" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1c10821022f1799452065fb57474e894e2562b7f Author: David Sherwood <[email protected]> Date: Wed Feb 14 16:07:51 2024 +0000 [LoopVectorize] Fix divide-by-zero bug (#80836) (#81721) When attempting to use the estimated trip count to refine the costs of the runtime memory checks we should also check for sane trip counts to prevent divide-by-zero faults on some platforms. Fixes #80836 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b39bf21cacdb..98b177cf5d2d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2010,16 +2010,18 @@ public: BestTripCount = *EstimatedTC; } + BestTripCount = std::max(BestTripCount, 1U); InstructionCost NewMemCheckCost = MemCheckCost / BestTripCount; // Let's ensure the cost is always at least 1. NewMemCheckCost = std::max(*NewMemCheckCost.getValue(), (InstructionCost::CostType)1); - LLVM_DEBUG(dbgs() - << "We expect runtime memory checks to be hoisted " - << "out of the outer loop. Cost reduced from " - << MemCheckCost << " to " << NewMemCheckCost << '\n'); + if (BestTripCount > 1) + LLVM_DEBUG(dbgs() + << "We expect runtime memory checks to be hoisted " + << "out of the outer loop. Cost reduced from " + << MemCheckCost << " to " << NewMemCheckCost << '\n'); MemCheckCost = NewMemCheckCost; }
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/low_trip_memcheck_cost.ll", "commands": [ "opt -p loop-vectorize -debug-only=loop-vectorize -S -disable-output < %s 2>&1" ], "tests": [ { "test_name": "outer_known_tc3_full_range_checks", "test_body": "target triple = \"aarch64-unknown-linux-gnu\"\n\ndefine void @outer_known_tc3_full_range_checks(ptr nocapture noundef %dst, ptr nocapture noundef readonly %src, i64 noundef %n) {\nentry:\n br label %outer.loop\n\nouter.loop: ; preds = %inner.exit, %entry\n %outer.iv = phi i64 [ 0, %entry ], [ %outer.iv.next, %inner.exit ]\n %0 = mul nsw i64 %outer.iv, %n\n br label %inner.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %iv.inner = phi i64 [ 0, %outer.loop ], [ %iv.inner.next, %inner.loop ]\n %1 = add nuw nsw i64 %iv.inner, %0\n %arrayidx.us = getelementptr inbounds i32, ptr %src, i64 %1\n %2 = load i32, ptr %arrayidx.us, align 4\n %arrayidx8.us = getelementptr inbounds i32, ptr %dst, i64 %1\n %3 = load i32, ptr %arrayidx8.us, align 4\n %add9.us = add nsw i32 %3, %2\n store i32 %add9.us, ptr %arrayidx8.us, align 4\n %iv.inner.next = add nuw nsw i64 %iv.inner, 1\n %inner.exit.cond = icmp eq i64 %iv.inner.next, %n\n br i1 %inner.exit.cond, label %inner.exit, label %inner.loop\n\ninner.exit: ; preds = %inner.loop\n %outer.iv.next = add nuw nsw i64 %outer.iv, 1\n %outer.exit.cond = icmp eq i64 %outer.iv.next, 3\n br i1 %outer.exit.cond, label %outer.exit, label %outer.loop\n\nouter.exit: ; preds = %inner.exit\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "outer_pgo_minus1", "test_body": "target triple = \"aarch64-unknown-linux-gnu\"\n\ndefine void @outer_pgo_minus1(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %m, i64 noundef %n) {\nentry:\n br label %outer.loop\n\nouter.loop: ; preds = %inner.exit, %entry\n %outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]\n %mul.us = mul nsw i64 %outer.iv, %n\n br label %inner.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]\n %add.us = add nuw nsw i64 %inner.iv, %mul.us\n %arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us\n %0 = load i8, ptr %arrayidx.us, align 1\n %arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us\n %1 = load i8, ptr %arrayidx7.us, align 1\n %add9.us = add i8 %1, %0\n store i8 %add9.us, ptr %arrayidx7.us, align 1\n %inner.iv.next = add nuw nsw i64 %inner.iv, 1\n %exitcond.not = icmp eq i64 %inner.iv.next, %n\n br i1 %exitcond.not, label %inner.exit, label %inner.loop\n\ninner.exit: ; preds = %inner.loop\n %outer.iv.next = add nuw nsw i64 %outer.iv, 1\n %exitcond26.not = icmp eq i64 %outer.iv.next, %m\n br i1 %exitcond26.not, label %outer.exit, label %outer.loop, !prof !0\n\nouter.exit: ; preds = %inner.exit\n ret void\n}\n\n!0 = !{!\"branch_weights\", i32 1, i32 -1}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Unhandled Floating point exception with loop-vectorize ", "body": "Run opt with -passes=loop-vectorize \r\n\r\nhttps://godbolt.org/z/s3PWY3vhE\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine ptr addrspace(1) @wombat(i64 %arg, ptr addrspace(1) %arg1) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb4, %bb\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb3, %bb2\r\n %phi = phi i64 [ 0, %bb2 ], [ %add, %bb3 ]\r\n %add = add i64 %phi, 1\r\n %load = load i8, ptr addrspace(1) %arg1, align 1\r\n %shl = shl i64 0, 0\r\n store i16 0, ptr addrspace(1) null, align 2\r\n %icmp = icmp ult i64 %phi, %arg\r\n br i1 %icmp, label %bb3, label %bb4\r\n\r\nbb4: ; preds = %bb3\r\n br i1 false, label %bb5, label %bb2, !prof !0\r\n\r\nbb5: ; preds = %bb4\r\n ret ptr addrspace(1) null\r\n}\r\n\r\n!0 = !{!\"branch_weights\", i32 1, i32 -1}\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "DaniilSuchkov", "body": "It started failing after 962fbafecf4730ba84a3b9fd7a662a5c30bb2c7c\r\n```\r\nAuthor: David Sherwood <[email protected]>\r\nDate: Fri Jan 26 14:43:48 2024 +0000\r\n\r\n [LoopVectorize] Refine runtime memory check costs when there is an outer loop (#76034)\r\n\r\n When we generate runtime memory checks for an inner loop it's\r\n possible that these checks are invariant in the outer loop and\r\n so will get hoisted out. In such cases, the effective cost of\r\n the checks should reduce to reflect the outer loop trip count.\r\n\r\n This fixes a 25% performance regression introduced by commit\r\n\r\n 49b0e6dcc296792b577ae8f0f674e61a0929b99d\r\n\r\n when building the SPEC2017 x264 benchmark with PGO, where we\r\n decided the inner loop trip count wasn't high enough to warrant\r\n the (incorrect) high cost of the runtime checks. Also, when\r\n runtime memory checks consist entirely of diff checks these are\r\n likely to be outer loop invariant.\r\n```\r\nWe have a division by 0 here https://github.com/llvm/llvm-project/commit/962fbafecf4730ba84a3b9fd7a662a5c30bb2c7c#diff-da321d454a7246f8ae276bf1db2782bf26b5210b8133cb59e4d7fd45d0905decR2114 because `getLoopEstimatedTripCount(OuterLoop)` just above that line returns 0." }, { "author": "david-arm", "body": "OK thanks for raising this issue - I'll take a look this morning!" }, { "author": "david-arm", "body": "I have a fix in review - https://github.com/llvm/llvm-project/pull/81721" } ] }
true
null
84025
https://github.com/llvm/llvm-project/issues/84025
miscompilation
f51ade25b9205efee09a4915031848cebe772805
2024-03-05T15:07:55
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "e96c0c1d5e0a9916098b1a31acb006ea6c1108fb", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": [ [ 2167, 2180 ] ], "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": [ "collectInsertionElements" ], "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit e96c0c1d5e0a9916098b1a31acb006ea6c1108fb Author: Quentin Dian <[email protected]> Date: Wed Mar 6 06:16:28 2024 +0800 [InstCombine] Fix shift calculation in InstCombineCasts (#84027) Fixes #84025. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 33ed1d557537..45afa6363ae0 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2167,14 +2167,14 @@ static bool collectInsertionElements(Value *V, unsigned Shift, Type *ElementIntTy = IntegerType::get(C->getContext(), ElementSize); for (unsigned i = 0; i != NumElts; ++i) { - unsigned ShiftI = Shift + i * ElementSize; + unsigned ShiftI = i * ElementSize; Constant *Piece = ConstantFoldBinaryInstruction( Instruction::LShr, C, ConstantInt::get(C->getType(), ShiftI)); if (!Piece) return false; Piece = ConstantExpr::getTrunc(Piece, ElementIntTy); - if (!collectInsertionElements(Piece, ShiftI, Elements, VecEltTy, + if (!collectInsertionElements(Piece, ShiftI + Shift, Elements, VecEltTy, isBigEndian)) return false; }
[ { "file": "llvm/test/Transforms/InstCombine/bitcast.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "bitcast_from_single_element_pointer_vector_to_pointer", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\ntarget triple = \"x86_64-apple-darwin10.0.0\"\n\ndefine ptr @bitcast_from_single_element_pointer_vector_to_pointer(<1 x ptr> %ptrvec) {\n %ptr = bitcast <1 x ptr> %ptrvec to ptr\n ret ptr %ptr\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "bitcast_shl", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\ntarget triple = \"x86_64-apple-darwin10.0.0\"\n\ndefine <4 x i32> @bitcast_shl(i32 %arg) {\n %i = zext i32 %arg to i64\n %i1 = shl i64 %i, 32\n %i2 = or i64 %i1, 65\n %i3 = zext i64 %i2 to i128\n %i4 = shl i128 %i3, 64\n %i5 = bitcast i128 %i4 to <4 x i32>\n ret <4 x i32> %i5\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "select_bitcast_unsized_pointer", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\ntarget triple = \"x86_64-apple-darwin10.0.0\"\n\ndeclare void @f1()\n\ndeclare void @f2()\n\ndefine ptr @select_bitcast_unsized_pointer(i1 %c) {\n %s = select i1 %c, ptr @f1, ptr @f2\n ret ptr %s\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "InstCombine calculated a wrong `insertelement` instruction", "body": "I tried this IR:\r\n\r\n```llvm\r\ndefine <4 x i32> @src(i32 %arg) {\r\n %i = zext i32 %arg to i64\r\n %i1 = shl i64 %i, 32\r\n %i2 = or i64 %i1, 65\r\n %i3 = zext i64 %i2 to i128\r\n %i4 = shl i128 %i3, 64\r\n %i5 = bitcast i128 %i4 to <4 x i32>\r\n ret <4 x i32> %i5\r\n}\r\n\r\ndefine <4 x i32> @tgt(i32 %arg) {\r\n %i5 = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 %arg, i64 3\r\n ret <4 x i32> %i5\r\n}\r\n```\r\n\r\nI expect `src` to be:\r\n\r\n```llvm\r\ndefine <4 x i32> @src(i32 %arg) {\r\n %i5 = insertelement <4 x i32> <i32 0, i32 0, i32 65, i32 poison>, i32 %arg, i64 3\r\n ret <4 x i32> %i5\r\n}\r\n```\r\n\r\nBut I'm getting the same instructions as `tgt`.\r\n\r\nGodbolt: https://llvm.godbolt.org/z/KnMEY4rTq\r\nAlive2: https://alive2.llvm.org/ce/z/7FIJNi\r\nFrom: https://github.com/rust-lang/rust/issues/121996", "author": "DianQK", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "cbeuw", "body": "Looks like this bug is almost 11 years old: https://github.com/llvm/llvm-project/commit/feb34713d531d1f48c37116e8cab84814202d057! Thanks for fixing" }, { "author": "DianQK", "body": "> Looks like this bug is almost 11 years old: [feb3471](https://github.com/llvm/llvm-project/commit/feb34713d531d1f48c37116e8cab84814202d057)! Thanks for fixing\r\n\r\nBased on my experience, we likely have many more latent bugs. :)" } ] }
true
null
122558
https://github.com/llvm/llvm-project/issues/122558
crash
25f28ddd69ed2453726c0934ba6feea8ae6f10f8
2025-01-11T00:36:48
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "1de3dc7d23dd6b856efad3a3a04f2396328726d7", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 4052, 4058 ], [ 4064, 4069 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::computeMaxVF" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1de3dc7d23dd6b856efad3a3a04f2396328726d7 Author: Florian Hahn <[email protected]> Date: Tue Jan 14 22:07:38 2025 +0000 [LV] Bail out early if BTC+1 wraps. Currently we fail to detect the case where BTC + 1 wraps, i.e. the vector trip count is 0, In those cases, the minimum iteration count check will fail, and the vector code will never be executed. Explicitly check for this condition in computeMaxVF and avoid trying to vectorize alltogether. Note that a number of tests needed to be updated, because the vector loop would never be executed given the input IR. Fixes https://github.com/llvm/llvm-project/issues/122558. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 744faef19243..fe2fb5e9faae 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4052,7 +4052,8 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { return FixedScalableVFPair::getNone(); } - unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop); + ScalarEvolution *SE = PSE.getSE(); + unsigned TC = SE->getSmallConstantTripCount(TheLoop); unsigned MaxTC = PSE.getSmallConstantMaxTripCount(); LLVM_DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n'); if (TC != MaxTC) @@ -4064,6 +4065,22 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { return FixedScalableVFPair::getNone(); } + // If BTC matches the widest induction type and is -1 then the trip count + // computation will wrap to 0 and the vector trip count will be 0. Do not try + // to vectorize. + const SCEV *BTC = SE->getBackedgeTakenCount(TheLoop); + if (!isa<SCEVCouldNotCompute>(BTC) && + BTC->getType()->getScalarSizeInBits() >= + Legal->getWidestInductionType()->getScalarSizeInBits() && + SE->isKnownPredicate(CmpInst::ICMP_EQ, BTC, + SE->getMinusOne(BTC->getType()))) { + reportVectorizationFailure( + "Trip count computation wrapped", + "backedge-taken count is -1, loop trip count wrapped to 0", + "TripCountWrapped", ORE, TheLoop); + return FixedScalableVFPair::getNone(); + } + switch (ScalarEpilogueStatus) { case CM_ScalarEpilogueAllowed: return computeFeasibleMaxVF(MaxTC, UserVF, false);
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll", "commands": [ "opt -mattr=+dotprod -passes=loop-vectorize -force-vector-interleave=1 -S < %s" ], "tests": [ { "test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-mixed.ll", "commands": [ "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+i8mm,+dotprod -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+dotprod -S < %s" ], "tests": [ { "test_name": "dotp_z_s", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_z_s(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dotp_s_z", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_s_z(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-neon.ll", "commands": [ "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -vectorizer-maximize-bandwidth -S < %s" ], "tests": [ { "test_name": "dotp_unrolled", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_predicated_pragma", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_not_loop_carried", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_different_types", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_not_phi", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_extend_user", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_predicated", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-interleave=1 -enable-epilogue-vectorization=false -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -S < %s", "opt -passes=loop-vectorize -force-vector-interleave=1 -vectorizer-maximize-bandwidth -enable-epilogue-vectorization=false -S < %s" ], "tests": [ { "test_name": "not_dotp_not_phi2", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @not_dotp_not_phi2(ptr %matrix, i32 %n) #0 {\nentry:\n %cmp = icmp sgt i32 %n, 0\n br i1 %cmp, label %for.preheader, label %exit\n\nfor.preheader: ; preds = %entry\n %load.a = load i8, ptr null, align 1\n %load.a1 = load i8, ptr inttoptr (i64 1 to ptr), align 1\n %a.ext = sext i8 %load.a to i32\n %a.ext1 = sext i8 %load.a1 to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.preheader\n %iv = phi i32 [ %iv.next, %for.body ], [ 0, %for.preheader ]\n %ptr = phi ptr [ %scevgep, %for.body ], [ %matrix, %for.preheader ]\n %accum = phi i32 [ %add.1, %for.body ], [ 0, %for.preheader ]\n %gep.b = getelementptr i8, ptr %ptr, i64 1\n %gep.b1 = getelementptr i8, ptr %ptr, i64 2\n %load.b = load i8, ptr %gep.b, align 1\n %b.ext = sext i8 %load.b to i32\n %mul = mul nsw i32 %a.ext, %b.ext\n %add = add i32 %mul, %accum\n %load.b1 = load i8, ptr %gep.b1, align 1\n %b.ext1 = sext i8 %load.b1 to i32\n %mul.1 = mul nsw i32 %a.ext1, %b.ext1\n %add.1 = add i32 %mul.1, %add\n %scevgep = getelementptr i8, ptr %ptr, i64 16\n %iv.next = add nuw nsw i32 %iv, 1\n %exitcond.not = icmp eq i32 %iv.next, %n\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %add.1.lcssa = phi i32 [ %add.1, %for.body ]\n %add.float = sitofp i32 %add.1.lcssa to float\n br label %exit\n\nexit: ; preds = %for.exit, %entry\n %result = phi float [ 0.000000e+00, %entry ], [ %add.float, %for.exit ]\n store float %result, ptr %matrix, align 4\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_ext_outside_plan2", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan2(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.b, %ext.a\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dotp_unrolled", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_predicated_pragma", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "dotp_cost_disagreement", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @dotp_cost_disagreement(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i.iv = phi i64 [ 0, %entry ], [ %i.iv.next, %for.body ]\n %sum = phi i64 [ 0, %entry ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds nuw i8, ptr %a, i64 %i.iv\n %0 = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %0 to i64\n %i.iv.next = add nuw nsw i64 %i.iv, 1\n %arrayidx2 = getelementptr inbounds nuw i8, ptr %b, i64 %i.iv.next\n %1 = load i8, ptr %arrayidx2, align 1\n %conv3 = zext i8 %1 to i64\n %mul = mul nuw nsw i64 %conv3, %conv\n %add = add i64 %sum, %mul\n %exitcond.not = icmp eq i64 %i.iv.next, 16\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i64 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_not_loop_carried", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_different_types", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_not_phi", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_extend_user", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_ext_outside_plan", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.a, %ext.b\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_dotp_predicated", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll", "commands": [ "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon -S < %s" ], "tests": [ { "test_name": "not_dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/store-costs-sve.ll", "commands": [ "opt -p loop-vectorize -S %s", "opt -p loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S %s" ], "tests": [ { "test_name": "trunc_store", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @trunc_store(ptr %dst, ptr %src, i16 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %x.ext = zext i16 %x to i64\n %l = load i64, ptr %src, align 8\n %and = and i64 %l, %x.ext\n %trunc = trunc i64 %and to i8\n %gep = getelementptr i8, ptr %dst, i64 %iv\n store i8 %trunc, ptr %gep, align 1\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll", "commands": [ "opt -mattr=+neon,+dotprod -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -disable-output %s 2>&1" ], "tests": [ { "test_name": "print_partial_reduction", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @print_partial_reduction(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/Hexagon/maximum-vf-crash.ll", "commands": [ "opt -mtriple=hexagon -hexagon-autohvx -passes=loop-vectorize -S < %s 2>&1" ], "tests": [ { "test_name": "f", "test_body": "target datalayout = \"e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048\"\n\n; Function Attrs: optsize\ndefine i32 @f(ptr %src) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %g.016 = phi i32 [ 0, %entry ], [ %g.1.lcssa, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = load i8, ptr %src, align 1\n %g.1.lcssa = add i32 %g.016, 1\n %iv.next = add nsw i32 %iv, 1\n %exitcond = icmp eq i32 %iv.next, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %g.1.lcssa\n}\n\nattributes #0 = { optsize \"target-features\"=\"+hvx-length128b\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "second_lshr_operand_zero_via_scev", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @second_lshr_operand_zero_via_scev() {\nentry:\n %ext.0 = sext i8 0 to i32\n br label %loops\n\nloops: ; preds = %loops, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loops ]\n %red = phi i64 [ 0, %entry ], [ %red.next, %loops ]\n %c = icmp eq i64 %iv, 0\n %and = and i64 %iv, 0\n %0 = trunc i64 %iv to i32\n %shr = lshr i32 %0, %ext.0\n %conv.1 = zext i32 %shr to i64\n %red.next.v = select i1 %c, i64 %and, i64 %conv.1\n %red.next = or i64 %red.next.v, %red\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loops\n\nexit: ; preds = %loops\n %res = phi i64 [ %red.next, %loops ]\n ret i64 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": [ "opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S" ], "tests": [ { "test_name": "narrowed_reduction", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {\nentry:\n %conv = zext i1 %cmp to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]\n %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]\n %and = and i32 %or13, 1\n %or = or i32 %and, %conv\n %inc = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 16\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %or\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll", "commands": [ "opt %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S" ], "tests": [ { "test_name": "drop_zext_nneg", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc-linux-gnu\"\n\n; Function Attrs: noinline nounwind uwtable\ndefine void @drop_zext_nneg(ptr noalias %p, ptr noalias %p1) #0 {\nentry:\n br label %body\n\nbody: ; preds = %else, %entry\n %iv = phi i64 [ %next, %else ], [ 0, %entry ]\n %0 = trunc i64 %iv to i32\n %c = icmp eq i32 %0, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %body\n %zext = zext nneg i32 %0 to i64\n %idx1 = getelementptr double, ptr %p, i64 %zext\n %idx2 = getelementptr double, ptr %p, i64 %zext\n %1 = load double, ptr %idx2, align 8\n br label %else\n\nelse: ; preds = %then, %body\n %phi = phi double [ %1, %then ], [ 0.000000e+00, %body ]\n store double %phi, ptr %p1, align 8\n %next = add i64 %iv, 1\n %cmp = icmp eq i64 %next, 1024\n br i1 %cmp, label %exit, label %body\n\nexit: ; preds = %else\n ret void\n}\n\nattributes #0 = { noinline nounwind uwtable \"target-features\"=\"+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl\" }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/interleave-cost.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "test_free_instructions_feeding_geps_for_interleave_groups", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @test_free_instructions_feeding_geps_for_interleave_groups(ptr noalias %p.invar, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.0 = load float, ptr %p.invar, align 4\n %iv.mul = shl i64 %iv, 2\n %gep.dst.19 = getelementptr float, ptr %dst.1, i64 %iv.mul\n store float %l.0, ptr %gep.dst.19, align 4\n %l.1 = load float, ptr %p.invar, align 4\n %add.1 = or disjoint i64 %iv.mul, 1\n %gep.dst.119 = getelementptr float, ptr %dst.1, i64 %add.1\n store float %l.1, ptr %gep.dst.119, align 4\n %add.2 = or disjoint i64 %iv.mul, 2\n %gep.dst.129 = getelementptr float, ptr %dst.1, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.129, align 4\n %add.3 = or disjoint i64 %iv.mul, 3\n %gep.dst.140 = getelementptr float, ptr %dst.1, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.140, align 4\n %l.2 = load float, ptr %p.invar, align 4\n %gep.dst.247 = getelementptr float, ptr %dst.2, i64 %iv.mul\n store float %l.2, ptr %gep.dst.247, align 4\n %gep.dst.255 = getelementptr float, ptr %dst.2, i64 %add.1\n store float 0.000000e+00, ptr %gep.dst.255, align 4\n %gep.dst.265 = getelementptr float, ptr %dst.2, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.265, align 4\n %gep.dst.276 = getelementptr float, ptr %dst.2, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.276, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/replicate-uniform-call.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "smax_call_uniform", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @smax_call_uniform(ptr %dst, i64 %x) {\nentry:\n %c = icmp ult i8 -68, -69\n %mul = mul nuw nsw i64 %x, 0\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %rem = urem i64 %mul, %x\n %smax = tail call i64 @llvm.smax.i64(i64 %rem, i64 0)\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %p = phi i64 [ 1, %loop.header ], [ %smax, %else ]\n %add = add i64 %p, 1\n %gep = getelementptr i64, ptr %dst, i64 %add\n store i64 0, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.smax.i64(i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/epilog-vectorization-vector-trip-count-zero.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=2 -epilogue-vectorization-force-VF=2 -S %s" ], "tests": [ { "test_name": "vector_trip_count_0_as_btc_is_all_1", "test_body": "target datalayout = \"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64\"\n\ndefine void @vector_trip_count_0_as_btc_is_all_1(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i32 %iv, -1\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test_resinking_required", "test_body": "define double @test_resinking_required(ptr %p, ptr noalias %a, ptr noalias %b) {\nEntry:\n br label %Loop\n\nLoop: ; preds = %Loop, %Entry\n %for.1 = phi double [ %l1, %Loop ], [ 0.000000e+00, %Entry ]\n %for.2 = phi double [ %l2, %Loop ], [ 0.000000e+00, %Entry ]\n %for.3 = phi double [ %for.2, %Loop ], [ 0.000000e+00, %Entry ]\n %iv = phi i64 [ %iv.next, %Loop ], [ 0, %Entry ]\n %USE_2_FORS = fdiv double %for.3, %for.1\n %div = fdiv double 0.000000e+00, %for.1\n %l1 = load double, ptr %a, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %l2 = load double, ptr %b, align 8\n store double %div, ptr %p, align 8\n %cond = icmp eq i64 %iv.next, 1000\n br i1 %cond, label %End, label %Loop\n\nEnd: ; preds = %Loop\n %res.1 = fadd double %for.1, %for.2\n %res.2 = fadd double %res.1, %for.3\n ret double %res.2\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/if-pred-stores.ll", "commands": [ "opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s", "opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize -verify-loop-info < %s", "opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s" ], "tests": [ { "test_name": "minimal_bit_widths_with_aliasing_store", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @minimal_bit_widths_with_aliasing_store(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1000, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/induction.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -enable-interleaved-mem-accesses -S" ], "tests": [ { "test_name": "max_i32_backedgetaken", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine i32 @max_i32_backedgetaken() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]\n %b.0 = phi i32 [ 0, %entry ], [ %b.next, %loop ]\n %a.0.and = and i32 %a.0, 4\n %b.next = add i32 %b.0, -1\n %ec = icmp eq i32 %b.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %a.0.and\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -debug -disable-output %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s" ], "tests": [ { "test_name": "scalarize_ptrtoint", "test_body": "define void @scalarize_ptrtoint(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr ptr, ptr %src, i64 %iv\n %l = load ptr, ptr %gep, align 8\n %cast = ptrtoint ptr %l to i64\n %add = add i64 %cast, 10\n %cast.2 = inttoptr i64 %add to ptr\n store ptr %cast.2, ptr %dst, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/is_fpclass.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-width=2 -S" ], "tests": [ { "test_name": "d", "test_body": "define void @d() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %i = phi i64 [ 0, %entry ], [ %i7, %loop ]\n %i3 = load float, ptr null, align 4\n %i4 = getelementptr float, ptr @d, i64 %i\n %i5 = tail call i1 @llvm.is.fpclass.f32(float %i3, i32 0)\n %i6 = select i1 %i5, float 0.000000e+00, float 0.000000e+00\n store float %i6, ptr %i4, align 4\n %i7 = add i64 %i, 1\n %i8 = icmp eq i64 %i7, 128\n br i1 %i8, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i1 @llvm.is.fpclass.f32(float, i32 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll", "commands": [ "opt -passes='loop-vectorize' -force-vector-width=4 -enable-epilogue-vectorization -epilogue-vectorization-force-VF=4 -S %s", "opt -passes='loop-vectorize' -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 -S %s" ], "tests": [ { "test_name": "multiple_ivs_wide", "test_body": "target datalayout = \"e-m:e-i64:64-n32:64-v128:128:128\"\n\ndefine void @multiple_ivs_wide(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ -64, %entry ], [ %iv.2.next, %loop ]\n %iv.next = add i32 %iv, 2\n %iv.2.next = add i32 %iv.2, 2\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.2.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 128\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll", "commands": [ "opt < %s -passes='loop-vectorize' -force-vector-interleave=1 -S -force-vector-width=4 -debug-only=loop-accesses,loop-vectorize,loop-utils" ], "tests": [ { "test_name": "stride_check_known_via_loop_guard", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @stride_check_known_via_loop_guard(ptr %C, ptr %A, i32 %Acols) {\nentry:\n %pre.c = icmp ugt i32 %Acols, 0\n br i1 %pre.c, label %exit, label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]\n %mul.us = mul i32 %outer.iv, %Acols\n %arrayidx.us = getelementptr double, ptr %A, i32 %mul.us\n br label %inner\n\ninner: ; preds = %inner, %outer.header\n %inner.iv = phi i32 [ 0, %outer.header ], [ %inner.iv.next, %inner ]\n %gep.C = getelementptr inbounds double, ptr %C, i32 %inner.iv\n %l = load double, ptr %arrayidx.us, align 8\n store double %l, ptr %gep.C, align 8\n %inner.iv.next = add i32 %inner.iv, 1\n %inner.c = icmp eq i32 %inner.iv.next, 1000\n br i1 %inner.c, label %outer.latch, label %inner\n\nouter.latch: ; preds = %inner\n %outer.iv.next = add i32 %outer.iv, 1\n %outer.c = icmp ult i32 %outer.iv, 128\n br i1 %outer.c, label %exit, label %outer.header\n\nexit: ; preds = %outer.latch, %entry\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -lv-strided-pointer-ivs=true -S %s" ], "tests": [ { "test_name": "step_direction_unknown", "test_body": "define void @step_direction_unknown(i32 %arg, ptr %dst) {\nentry:\n %add = add i32 %arg, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 0, %entry ], [ %add2, %loop ]\n %trunc = trunc i64 %phi to i32\n %mul = mul i32 %add, %trunc\n %zext = zext i32 %mul to i64\n %getelementptr = getelementptr double, ptr %dst, i64 %zext\n store double 0.000000e+00, ptr %getelementptr, align 8\n %add2 = add i64 %phi, 1\n %icmp = icmp eq i64 %add2, 1024\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "integer_induction_wraps_scev_predicate_known", "test_body": "define void @integer_induction_wraps_scev_predicate_known(i32 %x, ptr %call, ptr %start) {\nentry:\n %mul = shl i32 %x, 1\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %entry\n %iv = phi i32 [ 30, %entry ], [ %inc, %for.cond ]\n %p.0 = phi ptr [ %start, %entry ], [ %add.ptr, %for.cond ]\n %add.ptr = getelementptr i8, ptr %p.0, i32 %mul\n %arrayidx = getelementptr ptr, ptr %call, i32 %iv\n store ptr %p.0, ptr %arrayidx, align 4\n %inc = add i32 %iv, 1\n %tobool.not = icmp eq i32 %iv, 1024\n br i1 %tobool.not, label %for.end, label %for.cond\n\nfor.end: ; preds = %for.cond\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -debug -disable-output %s 2>&1" ], "tests": [ { "test_name": "sink_with_sideeffects", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @sink_with_sideeffects(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1024, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorizer] Assertion `EPResumeVal && \"must have a resume value for the canonical IV\"' failed.", "body": "clang -Wno-incompatible-pointer-types -O3 -march=z13 -S -c crash19.i -o a.out -w -mllvm -disable-licm-promotion -mllvm -epilogue-vectorization-force-VF=2 \n\n[crash19.tar.gz](https://github.com/user-attachments/files/18383534/crash19.tar.gz)\n\n#9 0x000002aa3ff5e440 preparePlanForEpilogueVectorLoop\n#12 0x000002aa3ffa098a llvm::LoopVectorizePass::run\n\n@bmahjour \n@fhahn ", "author": "JonPsson1", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "@JonPsson1 Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count." }, { "author": "JonPsson1", "body": "> [@JonPsson1](https://github.com/JonPsson1) Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count.\n\nNo, it was a CSmith test case." }, { "author": "fhahn", "body": "@JonPsson1 Could you check if it fixes the full reproducer? If not, it would be great if you could share the full reproducer?" } ] }
true
null
130250
https://github.com/llvm/llvm-project/issues/130250
crash
3ed4daf9a749fe8590ad291f63fabce48fb4135f
2025-03-07T05:51:40
[ "llvm/test/Transforms/PhaseOrdering", "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "0ee8f699780569d7a6b94d61cd833285bb67eca1", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 2037, 2043 ], [ 2051, 2074 ] ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::foldShuffleOfSelects" ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 0ee8f699780569d7a6b94d61cd833285bb67eca1 Author: hanbeom <[email protected]> Date: Sat Mar 8 01:40:26 2025 +0900 [VectorCombine] Fix invalid shuffle cost argument of foldShuffleOfSelects (#130281) In the previous code (#128032), it specified the destination vector as the getShuffleCost argument. Because the shuffle mask specifies the indices of the two vectors specified as elements, the maximum value is twice the size of the source vector. This causes a problem if the destination vector is smaller than the source vector and specify an index in the mask that exceeds the size of the destination vector. Fix the problem by correcting the previous code, which was using wrong argument in the Cost calculation. Fixes #130250 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 4d4a1a6e04d3..019d79567b4a 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -2037,7 +2037,6 @@ bool VectorCombine::foldShuffleOfSelects(Instruction &I) { m_Mask(Mask)))) return false; - auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType()); auto *C1VecTy = dyn_cast<FixedVectorType>(C1->getType()); auto *C2VecTy = dyn_cast<FixedVectorType>(C2->getType()); if (!C1VecTy || !C2VecTy || C1VecTy != C2VecTy) @@ -2051,24 +2050,26 @@ bool VectorCombine::foldShuffleOfSelects(Instruction &I) { (SI0FOp->getFastMathFlags() != SI1FOp->getFastMathFlags()))) return false; + auto *SrcVecTy = dyn_cast<FixedVectorType>(T1->getType()); + auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType()); auto SK = TargetTransformInfo::SK_PermuteTwoSrc; auto SelOp = Instruction::Select; InstructionCost OldCost = TTI.getCmpSelInstrCost( - SelOp, T1->getType(), C1VecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); - OldCost += TTI.getCmpSelInstrCost(SelOp, T2->getType(), C2VecTy, + SelOp, SrcVecTy, C1VecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); + OldCost += TTI.getCmpSelInstrCost(SelOp, SrcVecTy, C2VecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); - OldCost += TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr, + OldCost += TTI.getShuffleCost(SK, SrcVecTy, Mask, CostKind, 0, nullptr, {I.getOperand(0), I.getOperand(1)}, &I); - auto *C1C2VecTy = cast<FixedVectorType>( - toVectorTy(Type::getInt1Ty(I.getContext()), DstVecTy->getNumElements())); InstructionCost NewCost = - TTI.getShuffleCost(SK, C1C2VecTy, Mask, CostKind, 0, nullptr, {C1, C2}); + TTI.getShuffleCost(SK, C1VecTy, Mask, CostKind, 0, nullptr, {C1, C2}); NewCost += - TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr, {T1, T2}); + TTI.getShuffleCost(SK, SrcVecTy, Mask, CostKind, 0, nullptr, {T1, T2}); NewCost += - TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr, {F1, F2}); - NewCost += TTI.getCmpSelInstrCost(SelOp, DstVecTy, DstVecTy, + TTI.getShuffleCost(SK, SrcVecTy, Mask, CostKind, 0, nullptr, {F1, F2}); + auto *C1C2ShuffledVecTy = cast<FixedVectorType>( + toVectorTy(Type::getInt1Ty(I.getContext()), DstVecTy->getNumElements())); + NewCost += TTI.getCmpSelInstrCost(SelOp, DstVecTy, C1C2ShuffledVecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); LLVM_DEBUG(dbgs() << "Found a shuffle feeding two selects: " << I
[ { "file": "llvm/test/Transforms/PhaseOrdering/X86/blendv-select.ll", "commands": [ "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v4" ], "tests": [ { "test_name": "x86_pblendvb_v8f32_v4f32", "test_body": "define <8 x float> @x86_pblendvb_v8f32_v4f32(<8 x float> %a, <8 x float> %b, <8 x float> %c, <8 x float> %d) {\n %a.bc = bitcast <8 x float> %a to <32 x i8>\n %b.bc = bitcast <8 x float> %b to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = fcmp olt <8 x float> %c, %d\n %sext = sext <8 x i1> %cmp to <8 x i32>\n %sext.bc = bitcast <8 x i32> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <8 x float>\n ret <8 x float> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v32i16_v16i16", "test_body": "define <8 x i64> @x86_pblendvb_v32i16_v16i16(<8 x i64> %a, <8 x i64> %b, <8 x i64> %c, <8 x i64> %d) {\n %a.bc = bitcast <8 x i64> %a to <64 x i8>\n %b.bc = bitcast <8 x i64> %b to <64 x i8>\n %c.bc = bitcast <8 x i64> %c to <32 x i16>\n %d.bc = bitcast <8 x i64> %d to <32 x i16>\n %a.lo = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.lo = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %a.hi = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %b.hi = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %cmp = icmp slt <32 x i16> %c.bc, %d.bc\n %sext = sext <32 x i1> %cmp to <32 x i16>\n %sext.bc = bitcast <32 x i16> %sext to <64 x i8>\n %sext.lo = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sext.hi = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %sel.lo = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.lo, <32 x i8> %b.lo, <32 x i8> %sext.lo)\n %sel.hi = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.hi, <32 x i8> %b.hi, <32 x i8> %sext.hi)\n %concat = shufflevector <32 x i8> %sel.lo, <32 x i8> %sel.hi, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %res = bitcast <64 x i8> %concat to <8 x i64>\n ret <8 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8>, <32 x i8>, <32 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v64i8_v32i8", "test_body": "define <8 x i64> @x86_pblendvb_v64i8_v32i8(<8 x i64> %a, <8 x i64> %b, <8 x i64> %c, <8 x i64> %d) {\n %a.bc = bitcast <8 x i64> %a to <64 x i8>\n %b.bc = bitcast <8 x i64> %b to <64 x i8>\n %c.bc = bitcast <8 x i64> %c to <64 x i8>\n %d.bc = bitcast <8 x i64> %d to <64 x i8>\n %a.lo = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.lo = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %a.hi = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %b.hi = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %cmp = icmp slt <64 x i8> %c.bc, %d.bc\n %sext = sext <64 x i1> %cmp to <64 x i8>\n %sext.lo = shufflevector <64 x i8> %sext, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sext.hi = shufflevector <64 x i8> %sext, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %sel.lo = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.lo, <32 x i8> %b.lo, <32 x i8> %sext.lo)\n %sel.hi = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.hi, <32 x i8> %b.hi, <32 x i8> %sext.hi)\n %concat = shufflevector <32 x i8> %sel.lo, <32 x i8> %sel.hi, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %res = bitcast <64 x i8> %concat to <8 x i64>\n ret <8 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8>, <32 x i8>, <32 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v4f64_v2f64", "test_body": "define <4 x double> @x86_pblendvb_v4f64_v2f64(<4 x double> %a, <4 x double> %b, <4 x double> %c, <4 x double> %d) {\n %a.bc = bitcast <4 x double> %a to <32 x i8>\n %b.bc = bitcast <4 x double> %b to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = fcmp olt <4 x double> %c, %d\n %sext = sext <4 x i1> %cmp to <4 x i64>\n %sext.bc = bitcast <4 x i64> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x double>\n ret <4 x double> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v16i16_v8i16", "test_body": "define <4 x i64> @x86_pblendvb_v16i16_v8i16(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %c.bc = bitcast <4 x i64> %c to <16 x i16>\n %d.bc = bitcast <4 x i64> %d to <16 x i16>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <16 x i16> %c.bc, %d.bc\n %sext = sext <16 x i1> %cmp to <16 x i16>\n %sext.bc = bitcast <16 x i16> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v8i32_v4i32", "test_body": "define <4 x i64> @x86_pblendvb_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %c.bc = bitcast <4 x i64> %c to <8 x i32>\n %d.bc = bitcast <4 x i64> %d to <8 x i32>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <8 x i32> %c.bc, %d.bc\n %sext = sext <8 x i1> %cmp to <8 x i32>\n %sext.bc = bitcast <8 x i32> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v4i64_v2i64", "test_body": "define <4 x i64> @x86_pblendvb_v4i64_v2i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <4 x i64> %c, %d\n %sext = sext <4 x i1> %cmp to <4 x i64>\n %sext.bc = bitcast <4 x i64> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v32i8_v16i8", "test_body": "define <4 x i64> @x86_pblendvb_v32i8_v16i8(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %c.bc = bitcast <4 x i64> %c to <32 x i8>\n %d.bc = bitcast <4 x i64> %d to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <32 x i8> %c.bc, %d.bc\n %sext = sext <32 x i1> %cmp to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "x86_pblendvb_v16i32_v8i32", "test_body": "define <8 x i64> @x86_pblendvb_v16i32_v8i32(<8 x i64> %a, <8 x i64> %b, <8 x i64> %c, <8 x i64> %d) {\n %a.bc = bitcast <8 x i64> %a to <64 x i8>\n %b.bc = bitcast <8 x i64> %b to <64 x i8>\n %c.bc = bitcast <8 x i64> %c to <16 x i32>\n %d.bc = bitcast <8 x i64> %d to <16 x i32>\n %a.lo = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.lo = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %a.hi = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %b.hi = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %cmp = icmp slt <16 x i32> %c.bc, %d.bc\n %sext = sext <16 x i1> %cmp to <16 x i32>\n %sext.bc = bitcast <16 x i32> %sext to <64 x i8>\n %sext.lo = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sext.hi = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %sel.lo = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.lo, <32 x i8> %b.lo, <32 x i8> %sext.lo)\n %sel.hi = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.hi, <32 x i8> %b.hi, <32 x i8> %sext.hi)\n %concat = shufflevector <32 x i8> %sel.lo, <32 x i8> %sel.hi, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %res = bitcast <64 x i8> %concat to <8 x i64>\n ret <8 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8>, <32 x i8>, <32 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "bitcast_smax_v8i32_v4i32", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @bitcast_smax_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b) {\n %a.bc0 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc0 = bitcast <4 x i64> %b to <8 x i32>\n %cmp = icmp slt <8 x i32> %a.bc0, %b.bc0\n %cmp.lo = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %cmp.hi = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %a.bc1 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc1 = bitcast <4 x i64> %b to <8 x i32>\n %a.lo = shufflevector <8 x i32> %a.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %b.lo = shufflevector <8 x i32> %b.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %lo = select <4 x i1> %cmp.lo, <4 x i32> %b.lo, <4 x i32> %a.lo\n %a.bc2 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc2 = bitcast <4 x i64> %b to <8 x i32>\n %a.hi = shufflevector <8 x i32> %a.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %b.hi = shufflevector <8 x i32> %b.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %hi = select <4 x i1> %cmp.hi, <4 x i32> %b.hi, <4 x i32> %a.hi\n %concat = shufflevector <4 x i32> %lo, <4 x i32> %hi, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %res = bitcast <8 x i32> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/VectorCombine/X86/shuffle-of-selects.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mcpu=x86-64-v4" ], "tests": [ { "test_name": "src_v8tov16_i16", "test_body": "define <16 x i16> @src_v8tov16_i16(<8 x i1> %a, <8 x i1> %b, <8 x i16> %x, <8 x i16> %y, <8 x i16> %z) {\n %select.xz = select <8 x i1> %a, <8 x i16> %x, <8 x i16> %z\n %select.yx = select <8 x i1> %b, <8 x i16> %y, <8 x i16> %x\n %res = shufflevector <8 x i16> %select.xz, <8 x i16> %select.yx, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n ret <16 x i16> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v4tov8_float", "test_body": "define <8 x float> @src_v4tov8_float(<4 x i1> %a, <4 x i1> %b, <4 x float> %x, <4 x float> %y, <4 x float> %z) {\n %select.xz = select <4 x i1> %a, <4 x float> %x, <4 x float> %z\n %select.yx = select <4 x i1> %b, <4 x float> %y, <4 x float> %x\n %res = shufflevector <4 x float> %select.xz, <4 x float> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x float> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v4tov8_i16", "test_body": "define <8 x i16> @src_v4tov8_i16(<4 x i1> %a, <4 x i1> %b, <4 x i16> %x, <4 x i16> %y, <4 x i16> %z) {\n %select.xz = select <4 x i1> %a, <4 x i16> %x, <4 x i16> %z\n %select.yx = select <4 x i1> %b, <4 x i16> %y, <4 x i16> %x\n %res = shufflevector <4 x i16> %select.xz, <4 x i16> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x i16> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov4_i64", "test_body": "define <4 x i64> @src_v2tov4_i64(<2 x i1> %a, <2 x i1> %b, <2 x i64> %x, <2 x i64> %y, <2 x i64> %z) {\n %select.xz = select <2 x i1> %a, <2 x i64> %x, <2 x i64> %z\n %select.yx = select <2 x i1> %b, <2 x i64> %y, <2 x i64> %x\n %res = shufflevector <2 x i64> %select.xz, <2 x i64> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x i64> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov2_i64", "test_body": "define <2 x i64> @src_v2tov2_i64(<2 x i1> %a, <2 x i1> %b, <2 x i64> %x, <2 x i64> %y, <2 x i64> %z) {\n %select.xz = select <2 x i1> %a, <2 x i64> %x, <2 x i64> %z\n %select.yx = select <2 x i1> %b, <2 x i64> %y, <2 x i64> %x\n %res = shufflevector <2 x i64> %select.xz, <2 x i64> %select.yx, <2 x i32> <i32 0, i32 3>\n ret <2 x i64> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov4_i32", "test_body": "define <4 x i32> @src_v2tov4_i32(<2 x i1> %a, <2 x i1> %b, <2 x i32> %x, <2 x i32> %y, <2 x i32> %z) {\n %select.xz = select <2 x i1> %a, <2 x i32> %x, <2 x i32> %z\n %select.yx = select <2 x i1> %b, <2 x i32> %y, <2 x i32> %x\n %res = shufflevector <2 x i32> %select.xz, <2 x i32> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x i32> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov2_double", "test_body": "define <2 x double> @src_v2tov2_double(<2 x i1> %a, <2 x i1> %b, <2 x double> %x, <2 x double> %y, <2 x double> %z) {\n %select.xz = select <2 x i1> %a, <2 x double> %x, <2 x double> %z\n %select.yx = select <2 x i1> %b, <2 x double> %y, <2 x double> %x\n %res = shufflevector <2 x double> %select.xz, <2 x double> %select.yx, <2 x i32> <i32 0, i32 3>\n ret <2 x double> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_mask0", "test_body": "define <2 x float> @test_mask0(<4 x i1> %c, <4 x float> %x, <4 x float> %y, <4 x float> %z) {\n %select.xy = select <4 x i1> %c, <4 x float> %x, <4 x float> %y\n %select.yz = select <4 x i1> %c, <4 x float> %y, <4 x float> %z\n %res = shufflevector <4 x float> %select.xy, <4 x float> %select.yz, <2 x i32> <i32 4, i32 7>\n ret <2 x float> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov4_i16", "test_body": "define <4 x i16> @src_v2tov4_i16(<2 x i1> %a, <2 x i1> %b, <2 x i16> %x, <2 x i16> %y, <2 x i16> %z) {\n %select.xz = select <2 x i1> %a, <2 x i16> %x, <2 x i16> %z\n %select.yx = select <2 x i1> %b, <2 x i16> %y, <2 x i16> %x\n %res = shufflevector <2 x i16> %select.xz, <2 x i16> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x i16> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v4tov8_i32", "test_body": "define <8 x i32> @src_v4tov8_i32(<4 x i1> %a, <4 x i1> %b, <4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {\n %select.xz = select <4 x i1> %a, <4 x i32> %x, <4 x i32> %z\n %select.yx = select <4 x i1> %b, <4 x i32> %y, <4 x i32> %x\n %res = shufflevector <4 x i32> %select.xz, <4 x i32> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x i32> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v8tov8_i16", "test_body": "define <8 x i16> @src_v8tov8_i16(<8 x i1> %a, <8 x i1> %b, <8 x i16> %x, <8 x i16> %y, <8 x i16> %z) {\n %select.xz = select <8 x i1> %a, <8 x i16> %x, <8 x i16> %z\n %select.yx = select <8 x i1> %b, <8 x i16> %y, <8 x i16> %x\n %res = shufflevector <8 x i16> %select.xz, <8 x i16> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x i16> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov4_float", "test_body": "define <4 x float> @src_v2tov4_float(<2 x i1> %a, <2 x i1> %b, <2 x float> %x, <2 x float> %y, <2 x float> %z) {\n %select.xz = select <2 x i1> %a, <2 x float> %x, <2 x float> %z\n %select.yx = select <2 x i1> %b, <2 x float> %y, <2 x float> %x\n %res = shufflevector <2 x float> %select.xz, <2 x float> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x float> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_mask1", "test_body": "define <2 x float> @test_mask1(<4 x i1> %c, <4 x float> %x, <4 x float> %y, <4 x float> %z) {\n %select.xy = select <4 x i1> %c, <4 x float> %x, <4 x float> %y\n %select.yz = select <4 x i1> %c, <4 x float> %y, <4 x float> %z\n %res = shufflevector <4 x float> %select.xy, <4 x float> %select.yz, <2 x i32> <i32 7, i32 4>\n ret <2 x float> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov4_double", "test_body": "define <4 x double> @src_v2tov4_double(<2 x i1> %a, <2 x i1> %b, <2 x double> %x, <2 x double> %y, <2 x double> %z) {\n %select.xz = select <2 x i1> %a, <2 x double> %x, <2 x double> %z\n %select.yx = select <2 x i1> %b, <2 x double> %y, <2 x double> %x\n %res = shufflevector <2 x double> %select.xz, <2 x double> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x double> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "src_v2tov4_float_nnan", "test_body": "define <4 x float> @src_v2tov4_float_nnan(<2 x i1> %a, <2 x i1> %b, <2 x float> %x, <2 x float> %y, <2 x float> %z) {\n %select.xz = select nnan <2 x i1> %a, <2 x float> %x, <2 x float> %z\n %select.yx = select nnan <2 x i1> %b, <2 x float> %y, <2 x float> %x\n %res = shufflevector <2 x float> %select.xz, <2 x float> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x float> %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "A/F: `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\" after upstream commit 5d1029b", "body": "One of our internal tests recently started hitting an assertion failure when building which I bisected back to 5d1029b4a87f36a394c169b89b26a74d17f7ff01. I was able to reduce the test case to the following code:\n```c++\ntypedef float e __attribute__((__vector_size__(16)));\ne g(e h, e j) { return __builtin_ia32_cmpltps(j, h); }\ne k(float, float l, float n, float) { return {n, l}; }\ne o, p;\ntypedef union q {\n e r;\n} t;\ntypedef union u {\n e r;\n} w;\nunion aa {\n t ab;\n w ac;\n float f[];\n aa(t v) : ab(v) {}\n e ad;\n aa(e v) : ad(v) {}\n};\n#define ae(v) aa(v).ab\n#define af(v) aa(v).ac\n#define ag(a, b, c, d) ae(k(d, c, b, a))\n#define ah(v, ai) aa(v).f[ai]\n#define aj(a, b) af(g(a.r, b.r))\n#define ak(a, b, m) ae(al(a.r, b.r, m.r))\nt am(t an, t abcd) {\n e ao = __builtin_shufflevector(an.r, abcd.r, 0, 4, 1, 5);\n t ap = ae(ao);\n return ap;\n}\ne al(e, e, e aq) {\n e ar = __builtin_ia32_blendvps(o, p, aq);\n return ar;\n}\nfloat as(t v, int s) { return ah(v, s); }\nw at(t a, t b) { return aj(a, b); }\nt au(w aq) {\n t b, a;\n return ak(a, b, aq);\n}\nt av(t an, t abcd) { return am(an, abcd); }\nt aw_x, bl, bq_ay;\nt bf();\nstruct bc {\n t bd;\n bc(t bg) { bd = bg; }\n t be() { return bd; }\n};\nstruct bh {\n t bi;\n int i;\n bh(t bg, int bj) : bi(bg), i(bj) {}\n operator float() {\n float bk = as(bi, i);\n return bk;\n }\n};\nfloat bm_x;\nstruct bm {\n bm(float y, float z) { bl = ag(bm_x, y, z, 0.0f); }\n bm(bc y, bc z) {\n q bn = z.be(), bo(bn), bp = y.be();\n bl = av(bo, bp);\n }\n bh operator[](int bj) { return bh(bl, bj); }\n};\nbc bq() {\n t __trans_tmp_3 = bf();\n u bb = at(bq_ay, aw_x);\n __trans_tmp_3 = au(bb);\n return __trans_tmp_3;\n}\nbm bs() { return bm(bq(), bq()); }\nvoid bx() {\n unsigned char by, bz;\n bm ca = bs();\n bz = ca[1];\n by = ca[2];\n bm(bz, by);\n}\n```\nIf compiled with a compiler that includes 5d1029b4a87f36a394c169b89b26a74d17f7ff01 and with optimizations and AVX enabled, the compiler hits an assertion failure:\n```\n$ ~/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang -c -O2 -mavx repro.cpp\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/IR/Instructions.cpp:1906: bool isSingleSourceMaskImpl(llvm::ArrayRef<int>, int): Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0. Program arguments: /home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang -c -O2 repro.cpp -mavx\n1. <eof> parser at end of file\n2. Optimizer\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"repro.cpp\"\n4. Running pass \"vector-combine\" on function \"_Z2bxv\"\n #0 0x0000561cf26380ef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x224f0ef)\n #1 0x0000561cf2635c04 llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x224cc04)\n #2 0x0000561cf2586258 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007f5f727e6420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #4 0x00007f5f722b300b raise /build/glibc-FcRMwW/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #5 0x00007f5f72292859 abort /build/glibc-FcRMwW/glibc-2.31/stdlib/abort.c:81:7\n #6 0x00007f5f72292729 get_sysdep_segment_value /build/glibc-FcRMwW/glibc-2.31/intl/loadmsgcat.c:509:8\n #7 0x00007f5f72292729 _nl_load_domain /build/glibc-FcRMwW/glibc-2.31/intl/loadmsgcat.c:970:34\n #8 0x00007f5f722a3fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #9 0x0000561cf203aa46 isSingleSourceMaskImpl(llvm::ArrayRef<int>, int) Instructions.cpp:0:0\n#10 0x0000561cf20436e4 llvm::ShuffleVectorInst::isSelectMask(llvm::ArrayRef<int>, int) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1c5a6e4)\n#11 0x0000561cf116c2b0 llvm::X86TTIImpl::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd832b0)\n#12 0x0000561cf17404ed llvm::TargetTransformInfo::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) const (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x13574ed)\n#13 0x0000561cf42a667a (anonymous namespace)::VectorCombine::foldShuffleOfSelects(llvm::Instruction&) VectorCombine.cpp:0:0\n#14 0x0000561cf42c0e55 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\n#15 0x0000561cf42c1d85 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x3ed8d85)\n#16 0x0000561cf3b8f1a6 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x37a61a6)\n#17 0x0000561cf20deb09 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1cf5b09)\n#18 0x0000561cf11a9906 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xdc0906)\n#19 0x0000561cf20dd372 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1cf4372)\n#20 0x0000561cf11aa2c6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xdc12c6)\n#21 0x0000561cf20dcd91 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1cf3d91)\n#22 0x0000561cf28d99aa (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#23 0x0000561cf28dd9db clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x24f49db)\n#24 0x0000561cf3021121 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c38121)\n#25 0x0000561cf4a4170c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x465870c)\n#26 0x0000561cf3021548 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c38548)\n#27 0x0000561cf32f80f9 clang::FrontendAction::Execute() (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2f0f0f9)\n#28 0x0000561cf3278f4e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2e8ff4e)\n#29 0x0000561cf33ed2b6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x30042b6)\n#30 0x0000561cf1125ccd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd3cccd)\n#31 0x0000561cf111d5ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#32 0x0000561cf306b3cd void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#33 0x0000561cf2586760 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x219d760)\n#34 0x0000561cf306b9ef clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#35 0x0000561cf302c9c4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c439c4)\n#36 0x0000561cf302da5e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c44a5e)\n#37 0x0000561cf3035ef5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c4cef5)\n#38 0x0000561cf1122aab clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd39aab)\n#39 0x0000561cf10546bb main (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xc6b6bb)\n#40 0x00007f5f72294083 __libc_start_main /build/glibc-FcRMwW/glibc-2.31/csu/../csu/libc-start.c:342:3\n#41 0x0000561cf111d05e _start (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd3405e)\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\nclang version 21.0.0 (https://github.com/llvm/llvm-project.git 5d1029b4a87f36a394c169b89b26a74d17f7ff01)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin\nBuild config: +assertions\n```", "author": "dyung", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "ParkHanbum", "body": "Can you help me compile the sample?\nnever mind. I get the crash." }, { "author": "ParkHanbum", "body": "```\ndefine void @test(<4 x i1> %z, <4 x float> %1, <4 x float> %2) {\n%a = select <4 x i1> %z, <4 x float> %1, <4 x float> %2\n%b = select <4 x i1> %z, <4 x float> %1, <4 x float> %2\n%c = shufflevector <4 x float> %a, <4 x float> %b, <2 x i32> <i32 0, i32 5>\nret void\n}\n```\nThe problematic IR is shown above.\n\n```\n * frame #4: 0x00000001043d7fe8 clang++`isIdentityMaskImpl(llvm::ArrayRef<int>, int) (.cold.3) + 36\n frame #5: 0x0000000100fd5334 clang++`llvm::ShuffleVectorInst::isSelectMask(llvm::ArrayRef<int>, int) + 256\n frame #6: 0x0000000100095ff8 clang++`llvm::BasicTTIImplBase<llvm::X86TTIImpl>::improveShuffleKindFromMask(llvm::TargetTransformInfo::ShuffleKind, llvm::ArrayRef<int>, llvm::VectorType*, int&, llvm::VectorType*&) const + 184\n frame #7: 0x000000010033e104 clang++`llvm::X86TTIImpl::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) + 128\n```\n\nThis is where the crash happens.\n\n\n```\n OldCost += TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr,\n {I.getOperand(0), I.getOperand(1)}, &I);\n```\n\nThe problematic IR is shown above.\n\nTo calculate the OldCost, call getShuffleCost.\nThe DstVecTy passed as an argument is `<2 x float>` and the Mask is <i32 0, i32 5>.\n\nThe second Mask specifier is 5, which is greater than NumOpElts * 2 of DstVecTy, so this assertion seems to be thrown.\n(If we increase the Mask to <3 x i32> <i32 0, i32 5, i32 5> or decrease the Mask size to <2 x i32> <i32 0, i32 3>, the error will not occur.)\n\nI will add a fix after further analysis.\n\n\n" }, { "author": "RKSimon", "body": "@ParkHanbum You must use the source type not destination type for getShuffleCost" }, { "author": "ParkHanbum", "body": "@RKSimon I'm sorry, I made a mistake. I'll push up the patch quickly.\n" }, { "author": "RKSimon", "body": "You just need the fix + test coverage - no need to revert the existing patch if you are prompt" } ] }
true
null
141237
https://github.com/llvm/llvm-project/issues/141237
crash
af2a957ce30e3d91e17e2194e4be0a6b6481e4ba
2025-05-23T15:00:13
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "a9b2998e315af64b7a68606af9064db425699c39", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 7082, 7087 ], [ 7315, 7321 ], [ 7352, 7357 ], [ 7477, 7485 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": [ [ 364, 369 ] ], "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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationPlanner::computeBestVF", "VPCostContext::getLegacyCost", "VPCostContext::skipCostComputation", "planContainsAdditionalSimplifications" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a9b2998e315af64b7a68606af9064db425699c39 Author: Florian Hahn <[email protected]> Date: Sat May 24 11:09:27 2025 +0100 [VPlan] Skip cost assert if VPlan converted to single-scalar recipes. Check if a VPlan transform converted recipes to single-scalar VPReplicateRecipes (after 07c085af3efcd67503232f99a1652efc6e54c1a9). If that's the case, the legacy cost model incorrectly overestimates the cost. Fixes https://github.com/llvm/llvm-project/issues/141237. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 275b3d567856..8a35afbb73f3 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7082,6 +7082,11 @@ InstructionCost VPCostContext::getLegacyCost(Instruction *UI, return CM.getInstructionCost(UI, VF); } +bool VPCostContext::isLegacyUniformAfterVectorization(Instruction *I, + ElementCount VF) const { + return CM.isUniformAfterVectorization(I, VF); +} + bool VPCostContext::skipCostComputation(Instruction *UI, bool IsVector) const { return CM.ValuesToIgnore.contains(UI) || (IsVector && CM.VecValuesToIgnore.contains(UI)) || @@ -7315,7 +7320,8 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, /// cost-model did not account for. static bool planContainsAdditionalSimplifications(VPlan &Plan, VPCostContext &CostCtx, - Loop *TheLoop) { + Loop *TheLoop, + ElementCount VF) { // First collect all instructions for the recipes in Plan. auto GetInstructionForCost = [](const VPRecipeBase *R) -> Instruction * { if (auto *S = dyn_cast<VPSingleDefRecipe>(R)) @@ -7352,6 +7358,16 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan, // comparing against the legacy cost isn't desirable. if (isa<VPPartialReductionRecipe>(&R)) return true; + + /// If a VPlan transform folded a recipe to one producing a single-scalar, + /// but the original instruction wasn't uniform-after-vectorization in the + /// legacy cost model, the legacy cost overestimates the actual cost. + if (auto *RepR = dyn_cast<VPReplicateRecipe>(&R)) { + if (RepR->isSingleScalar() && + !CostCtx.isLegacyUniformAfterVectorization( + RepR->getUnderlyingInstr(), VF)) + return true; + } if (Instruction *UI = GetInstructionForCost(&R)) { // If we adjusted the predicate of the recipe, the cost in the legacy // cost model may be different. @@ -7477,9 +7493,10 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() { // legacy cost model doesn't properly model costs for such loops. assert((BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit() || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), - CostCtx, OrigLoop) || - planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width), - CostCtx, OrigLoop)) && + CostCtx, OrigLoop, + BestFactor.Width) || + planContainsAdditionalSimplifications( + getPlanFor(LegacyVF.Width), CostCtx, OrigLoop, LegacyVF.Width)) && " VPlan cost model and legacy cost model disagreed"); assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) && "when vectorizing, the scalar cost must be computed."); diff --git a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h index 1d42c8f5f373..0446991ebfff 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanHelpers.h +++ b/llvm/lib/Transforms/Vectorize/VPlanHelpers.h @@ -364,6 +364,11 @@ struct VPCostContext { /// Returns the OperandInfo for \p V, if it is a live-in. TargetTransformInfo::OperandValueInfo getOperandInfo(VPValue *V) const; + + /// Return true if \p I is considered uniform-after-vectorization in the + /// legacy cost model for \p VF. Only used to check for additional VPlan + /// simplifications. + bool isLegacyUniformAfterVectorization(Instruction *I, ElementCount VF) const; }; /// This class can be used to assign names to VPValues. For VPValues without
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/uniform_load.ll", "commands": [ "opt -passes=loop-vectorize -S %s" ], "tests": [ { "test_name": "foo", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@inc = external global float, align 4\n\ndefine void @foo(ptr noalias captures(none) %A, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.inc = load float, ptr @inc, align 4\n %gep.A = getelementptr inbounds float, ptr %A, i64 %iv\n %l.A = load float, ptr %gep.A, align 4\n %add = fadd float %l.inc, %l.A\n store float %add, ptr %gep.A, align 4\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 32\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"core-avx2\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "uniform_load_can_fold_users", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @uniform_load_can_fold_users(ptr noalias %src, ptr %dst, i64 %start, double %d) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi i64 [ 0, %entry ], [ %iv.1.next, %loop ]\n %iv.2 = phi i64 [ %start, %entry ], [ %iv.2.next, %loop ]\n %l = load double, ptr %src, align 8\n %m = fmul double %l, 9.000000e+00\n %div = fdiv double %m, %d\n %sub = sub i64 %iv.1, 1\n %gep.1 = getelementptr double, ptr %dst, i64 %iv.1\n %gep.2 = getelementptr double, ptr %gep.1, i64 %sub\n store double %div, ptr %gep.2, align 8\n %iv.1.next = add i64 %iv.1, 1\n %iv.2.next = add i64 %iv.2, -1\n %ec = icmp sgt i64 %iv.2, 0\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Crash in LoopVectorizationPlanner::computeBestVF()", "body": "Reduced reproducer:\n```\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\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @reduced_test_(ptr %0, i64 %1, ptr %.sroa.067.0.copyload) {\n._crit_edge103:\n br label %2\n\n2: ; preds = %2, %._crit_edge103\n %indvars.iv = phi i64 [ 0, %._crit_edge103 ], [ %indvars.iv.next, %2 ]\n %3 = phi i64 [ %1, %._crit_edge103 ], [ %10, %2 ]\n %4 = load double, ptr %0, align 8\n %5 = fmul double %4, 0.000000e+00\n %6 = fdiv double %5, 0.000000e+00\n %7 = sub i64 %indvars.iv, %1\n %8 = getelementptr double, ptr %.sroa.067.0.copyload, i64 %indvars.iv\n %9 = getelementptr double, ptr %8, i64 %7\n store double %6, ptr %9, align 8\n %indvars.iv.next = add i64 %indvars.iv, 1\n %10 = add i64 %3, -1\n %11 = icmp sgt i64 %3, 0\n br i1 %11, label %2, label %._crit_edge106\n\n._crit_edge106: ; preds = %2\n ret void\n}\n```\nCrash:\n```\n$ opt -O2 reduced.ll \nWARNING: You're attempting to print out a bitcode file.\nThis is inadvisable as it may cause display problems. If\nyou REALLY want to taste LLVM bitcode first-hand, you\ncan force output with the `-f' option.\n\nopt: .../llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7478: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || BestPlan.hasEarlyExit() || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop) || planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: opt -O2 reduced.ll\n1. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"reduced.ll\"\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"reduced_test_\"\n #0 0x0000000001b16948 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (.../llvm-5162/bin/opt+0x1b16948)\n #1 0x0000000001b13bd4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007ce1f6c45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #3 0x00007ce1f6c9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #4 0x00007ce1f6c9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #5 0x00007ce1f6c9eb2c pthread_kill ./nptl/pthread_kill.c:89:10\n #6 0x00007ce1f6c4527e raise ./signal/../sysdeps/posix/raise.c:27:6\n #7 0x00007ce1f6c288ff abort ./stdlib/abort.c:81:7\n #8 0x00007ce1f6c2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n #9 0x00007ce1f6c3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)\n#10 0x0000000003b73b36 llvm::LoopVectorizationPlanner::computeBestVF() (.../llvm-5162/bin/opt+0x3b73b36)\n#11 0x0000000003b7556a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (.../llvm-5162/bin/opt+0x3b7556a)\n#12 0x0000000003b78140 llvm::LoopVectorizePass::runImpl(llvm::Function&) (.../llvm-5162/bin/opt+0x3b78140)\n#13 0x0000000003b78793 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (opt+0x3b78793)\n#14 0x00000000036215ae llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0\n#15 0x0000000001de4030 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (opt+0x1de4030)\n#16 0x0000000002e4da6e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) NVPTXTargetMachine.cpp:0:0\n#17 0x0000000001de4543 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (opt+0x1de4543)\n#18 0x0000000002e4da2e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) NVPTXTargetMachine.cpp:0:0\n#19 0x0000000001de2160 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (opt+0x1de2160)\n#20 0x00000000034ad61a 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+0x34ad61a)\n...\nAborted\n```", "author": "eugeneepshteyn", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
96012
https://github.com/llvm/llvm-project/issues/96012
hang
aad27bf534b59645f47a92f072af798687b1dd0d
2024-06-19T02:31:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "48ae61470104e9d7a8be5beb8739c24f52cc33c0", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [ [ 780, 790 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ [ 90, 102 ], [ 309, 314 ], [ 537, 543 ] ], "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ "Negator::Negate", "Negator::Negator", "Negator::visitImpl", "Negator::~Negator" ], "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 48ae61470104e9d7a8be5beb8739c24f52cc33c0 Author: Yingwei Zheng <[email protected]> Date: Sat Aug 17 16:48:29 2024 +0800 [InstCombine] Avoid infinite loop when negating phi nodes (#104581) Closes https://github.com/llvm/llvm-project/issues/96012 --------- Co-authored-by: Nikita Popov <[email protected]> diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 16f1c3ba15eb..a0f2399972b5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -780,11 +780,14 @@ class Negator final { using BuilderTy = IRBuilder<TargetFolder, IRBuilderCallbackInserter>; BuilderTy Builder; + const DominatorTree &DT; + const bool IsTrulyNegation; SmallDenseMap<Value *, Value *> NegationsCache; - Negator(LLVMContext &C, const DataLayout &DL, bool IsTrulyNegation); + Negator(LLVMContext &C, const DataLayout &DL, const DominatorTree &DT, + bool IsTrulyNegation); #if LLVM_ENABLE_STATS unsigned NumValuesVisitedInThisNegator = 0; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index 2dd1db6a4a75..92293ef40146 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -90,13 +90,14 @@ static cl::opt<unsigned> cl::desc("What is the maximal lookup depth when trying to " "check for viability of negation sinking.")); -Negator::Negator(LLVMContext &C, const DataLayout &DL, bool IsTrulyNegation_) +Negator::Negator(LLVMContext &C, const DataLayout &DL, const DominatorTree &DT_, + bool IsTrulyNegation_) : Builder(C, TargetFolder(DL), IRBuilderCallbackInserter([&](Instruction *I) { ++NegatorNumInstructionsCreatedTotal; NewInstructions.push_back(I); })), - IsTrulyNegation(IsTrulyNegation_) {} + DT(DT_), IsTrulyNegation(IsTrulyNegation_) {} #if LLVM_ENABLE_STATS Negator::~Negator() { @@ -309,6 +310,9 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { auto *PHI = cast<PHINode>(I); SmallVector<Value *, 4> NegatedIncomingValues(PHI->getNumOperands()); for (auto I : zip(PHI->incoming_values(), NegatedIncomingValues)) { + // Don't negate indvars to avoid infinite loops. + if (DT.dominates(PHI->getParent(), std::get<0>(I))) + return nullptr; if (!(std::get<1>(I) = negate(std::get<0>(I), IsNSW, Depth + 1))) // Early return. return nullptr; @@ -537,7 +541,8 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { if (!NegatorEnabled || !DebugCounter::shouldExecute(NegatorCounter)) return nullptr; - Negator N(Root->getContext(), IC.getDataLayout(), LHSIsZero); + Negator N(Root->getContext(), IC.getDataLayout(), IC.getDominatorTree(), + LHSIsZero); std::optional<Result> Res = N.run(Root, IsNSW); if (!Res) { // Negation failed. LLVM_DEBUG(dbgs() << "Negator: failed to sink negation into " << *Root
[ { "file": "llvm/test/Transforms/InstCombine/pr96012.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Make sure we don't hang here.\ndefine i32 @pr96012() {\n;\nentry:\n br label %for.cond\n\nfor.cond:\n %indvar = phi i32 [ 1, %entry ], [ %shl, %for.cond ]\n %conv1 = trunc i32 %indvar to i8\n %neg = sub i8 0, %conv1\n %conv2 = zext i8 %neg to i32\n %shl = shl nuw i32 %conv2, 24\n br label %for.cond\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "InstCombine gets stuck when sinking negation", "body": "Minimal reproducer (It looks over-reduced): https://godbolt.org/z/9zj5K8seP\r\n```\r\n; opt -passes=instcombine test.ll -S -debug\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @func_112() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond, %entry\r\n %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\n %conv5 = trunc i32 %l_139.0 to i8\r\n %call6 = sub i8 0, %conv5\r\n %conv7 = zext i8 %call6 to i32\r\n %0 = shl nuw i32 %conv7, 24\r\n br label %for.cond\r\n}\r\n```\r\n\r\n```\r\nINSTCOMBINE ITERATION #1 on func_112\r\nADD: br label %for.cond\r\nADD: %0 = shl nuw i32 %conv7, 24\r\nADD: %conv7 = zext i8 %call6 to i32\r\nADD: %call6 = sub i8 0, %conv5\r\nADD: %conv5 = trunc i32 %l_139.0 to i8\r\nADD: %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nADD: br label %for.cond\r\nIC: Visiting: br label %for.cond\r\nIC: Visiting: %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nIC: Visiting: %conv5 = trunc i32 %l_139.0 to i8\r\nIC: Visiting: %call6 = sub i8 0, %conv5\r\nNegator: attempting to sink negation into %conv5 = trunc i32 %l_139.0 to i8\r\nNegator: successfully sunk negation into %conv5 = trunc i32 %l_139.0 to i8\r\n NEW: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nNegator: Propagating 3 instrs to InstCombine\r\nADD DEFERRED: %.neg = mul i32 %conv7, -16777216\r\nADD DEFERRED: %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nADD DEFERRED: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nIC: Old = %call6 = sub i8 0, %conv5\r\n New = <badref> = add i8 %conv5.neg, 0\r\nADD: %call6 = add i8 %conv5.neg, 0\r\nIC: ERASE %0 = sub i8 0, %conv5\r\nADD DEFERRED: %conv5 = trunc i32 %l_139.0 to i8\r\nIC: ERASE %conv5 = trunc i32 %l_139.0 to i8\r\nADD DEFERRED: %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nIC: ERASE %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nADD DEFERRED: %0 = shl nuw i32 %conv7, 24\r\nIC: ERASE %0 = shl nuw i32 %conv7, 24\r\nADD DEFERRED: %conv7 = zext i8 %call6 to i32\r\nADD: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nADD: %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nADD: %.neg = mul i32 %conv7, -16777216\r\nIC: Visiting: %.neg = mul i32 %conv7, -16777216\r\nNegator: attempting to sink negation into %conv7 = zext i8 %call6 to i32\r\nNegator: failed to sink negation into %conv7 = zext i8 %call6 to i32\r\nADD DEFERRED: %call6.neg = sub i8 0, %call6\r\nADD DEFERRED: %call6.neg.z = zext i8 %call6.neg to i32\r\nIC: Old = %.neg = mul i32 %conv7, -16777216\r\n New = <badref> = shl i32 %call6.neg.z, 24\r\nADD: %.neg = shl i32 %call6.neg.z, 24\r\nIC: ERASE %0 = mul i32 %conv7, -16777216\r\nADD DEFERRED: %conv7 = zext i8 %call6 to i32\r\nIC: ERASE %conv7 = zext i8 %call6 to i32\r\nADD DEFERRED: %call6 = add i8 %conv5.neg, 0\r\nADD: %call6.neg.z = zext i8 %call6.neg to i32\r\nADD: %call6.neg = sub i8 0, %call6\r\nIC: Visiting: %call6.neg = sub i8 0, %call6\r\nIC: Old = %call6.neg = sub i8 0, %call6\r\n New = <badref> = sub i8 0, %conv5.neg\r\nADD: %call6.neg = sub i8 0, %conv5.neg\r\nIC: ERASE %0 = sub i8 0, %call6\r\nADD DEFERRED: %call6 = add i8 %conv5.neg, 0\r\nIC: ERASE %call6 = add i8 %conv5.neg, 0\r\nADD DEFERRED: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nADD DEFERRED: %call6.neg = sub i8 0, %conv5.neg\r\nIC: Visiting: %call6.neg = sub i8 0, %conv5.neg\r\nNegator: attempting to sink negation into %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nNegator: successfully sunk negation into %conv5.neg = trunc i32 %l_139.0.neg to i8\r\n NEW: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nNegator: Propagating 3 instrs to InstCombine\r\nADD DEFERRED: %.neg.neg = mul i32 %call6.neg.z, -16777216\r\nADD DEFERRED: %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nADD DEFERRED: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nIC: Old = %call6.neg = sub i8 0, %conv5.neg\r\n New = <badref> = add i8 %conv5.neg.neg, 0\r\nADD: %call6.neg = add i8 %conv5.neg.neg, 0\r\nIC: ERASE %0 = sub i8 0, %conv5.neg\r\nADD DEFERRED: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nIC: ERASE %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nADD DEFERRED: %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nIC: ERASE %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nADD DEFERRED: %.neg = shl i32 %call6.neg.z, 24\r\nIC: ERASE %.neg = shl i32 %call6.neg.z, 24\r\nADD DEFERRED: %call6.neg.z = zext i8 %call6.neg to i32\r\nADD: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nADD: %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nADD: %.neg.neg = mul i32 %call6.neg.z, -16777216\r\nIC: Visiting: %.neg.neg = mul i32 %call6.neg.z, -16777216\r\nNegator: attempting to sink negation into %call6.neg.z = zext i8 %call6.neg to i32\r\nNegator: failed to sink negation into %call6.neg.z = zext i8 %call6.neg to i32\r\nADD DEFERRED: %call6.neg.neg = sub i8 0, %call6.neg\r\nADD DEFERRED: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nIC: Old = %.neg.neg = mul i32 %call6.neg.z, -16777216\r\n New = <badref> = shl i32 %call6.neg.neg.z, 24\r\nADD: %.neg.neg = shl i32 %call6.neg.neg.z, 24\r\nIC: ERASE %0 = mul i32 %call6.neg.z, -16777216\r\nADD DEFERRED: %call6.neg.z = zext i8 %call6.neg to i32\r\nIC: ERASE %call6.neg.z = zext i8 %call6.neg to i32\r\nADD DEFERRED: %call6.neg = add i8 %conv5.neg.neg, 0\r\nADD: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD: %call6.neg.neg = sub i8 0, %call6.neg\r\nIC: Visiting: %call6.neg.neg = sub i8 0, %call6.neg\r\nIC: Old = %call6.neg.neg = sub i8 0, %call6.neg\r\n New = <badref> = sub i8 0, %conv5.neg.neg\r\nADD: %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\nIC: ERASE %0 = sub i8 0, %call6.neg\r\nADD DEFERRED: %call6.neg = add i8 %conv5.neg.neg, 0\r\nIC: ERASE %call6.neg = add i8 %conv5.neg.neg, 0\r\nADD DEFERRED: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nADD DEFERRED: %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\nIC: Visiting: %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\nNegator: attempting to sink negation into %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nNegator: successfully sunk negation into %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\n NEW: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nNegator: Propagating 3 instrs to InstCombine\r\nADD DEFERRED: %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\nADD DEFERRED: %l_139.0.neg.neg.neg = phi i32 [ -1, %entry ], [ %.neg.neg.neg, %for.cond ]\r\nADD DEFERRED: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nIC: Old = %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\n New = <badref> = add i8 %conv5.neg.neg.neg, 0\r\nADD: %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nIC: ERASE %0 = sub i8 0, %conv5.neg.neg\r\nADD DEFERRED: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nIC: ERASE %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nADD DEFERRED: %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nIC: ERASE %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nADD DEFERRED: %.neg.neg = shl i32 %call6.neg.neg.z, 24\r\nIC: ERASE %.neg.neg = shl i32 %call6.neg.neg.z, 24\r\nADD DEFERRED: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nADD: %l_139.0.neg.neg.neg = phi i32 [ -1, %entry ], [ %.neg.neg.neg, %for.cond ]\r\nADD: %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\nIC: Visiting: %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\nNegator: attempting to sink negation into %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nNegator: failed to sink negation into %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD DEFERRED: %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\nADD DEFERRED: %call6.neg.neg.neg.z = zext i8 %call6.neg.neg.neg to i32\r\nIC: Old = %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\n New = <badref> = shl i32 %call6.neg.neg.neg.z, 24\r\nADD: %.neg.neg.neg = shl i32 %call6.neg.neg.neg.z, 24\r\nIC: ERASE %0 = mul i32 %call6.neg.neg.z, -16777216\r\nADD DEFERRED: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nIC: ERASE %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD DEFERRED: %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nADD: %call6.neg.neg.neg.z = zext i8 %call6.neg.neg.neg to i32\r\nADD: %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\nIC: Visiting: %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\nIC: Old = %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\n New = <badref> = sub i8 0, %conv5.neg.neg.neg\r\nADD: %call6.neg.neg.neg = sub i8 0, %conv5.neg.neg.neg\r\nIC: ERASE %0 = sub i8 0, %call6.neg.neg\r\nADD DEFERRED: %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nIC: ERASE %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nADD DEFERRED: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nADD DEFERRED: %call6.neg.neg.neg = sub i8 0, %conv5.neg.neg.neg\r\nIC: Visiting: %call6.neg.neg.neg = sub i8 0, %conv5.neg.neg.neg\r\nNegator: attempting to sink negation into %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nNegator: successfully sunk negation into %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\n NEW: %conv5.neg.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg.neg to i8\r\n...\r\n```", "author": "dtcxzyw", "labels": [ "llvm:instcombine", "llvm:hang" ], "comments": [] }
true
null
133288
https://github.com/llvm/llvm-project/issues/133288
crash
77ba6918a14ddef4ee639bf6221cc2eb95adf320
2025-03-27T17:54:31
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "1bfc61064ab46e44865453d2c2176f5e7f96987c", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13347, 13353 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::getSpillCost" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 1bfc61064ab46e44865453d2c2176f5e7f96987c Author: Alexey Bataev <[email protected]> Date: Fri Mar 28 11:37:42 2025 -0700 [SLP]Fix spill cost analysis for split vectorized nodes If the entry is SplitVectorize, it can be skipped in favor of its operands, operands allow correctly detect spill costs. Fixes #133288 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index f29fb6780253..850895895d44 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13347,7 +13347,8 @@ InstructionCost BoUpSLP::getSpillCost() { for (const TreeEntry *Op : Operands) { if (!Op->isGather()) LiveEntries.push_back(Op); - if ((Entry->getOpcode() != Instruction::PHI && Op->isGather()) || + if (Entry->State == TreeEntry::SplitVectorize || + (Entry->getOpcode() != Instruction::PHI && Op->isGather()) || (Op->isGather() && allConstant(Op->Scalars))) continue; Budget = 0;
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/split-node-parent-operands-in-spill.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 -mattr=+sse4.1 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(i32 %arg) {\n;\nbb:\n %load = load i32, ptr addrspace(3) null, align 4\n %load1 = load i32, ptr addrspace(3) null, align 4\n %load2 = load i32, ptr addrspace(3) null, align 4\n %load3 = load i32, ptr addrspace(3) null, align 4\n br label %bb4\n\nbb4:\n switch i32 0, label %bb8 [\n i32 0, label %bb7\n i32 1, label %bb21\n ]\n\nbb5:\n %srem = srem i32 0, 0\n br label %bb21\n\nbb6:\n br label %bb12\n\nbb7:\n ret void\n\nbb8:\n %phi = phi i32 [ 0, %bb4 ]\n %phi9 = phi i32 [ 0, %bb4 ]\n %phi10 = phi i32 [ 0, %bb4 ]\n %phi11 = phi i32 [ 0, %bb4 ]\n br label %bb12\n\nbb12:\n %phi13 = phi i32 [ %load, %bb8 ], [ 0, %bb6 ]\n %phi14 = phi i32 [ %load1, %bb8 ], [ 0, %bb6 ]\n %phi15 = phi i32 [ %load2, %bb8 ], [ %arg, %bb6 ]\n %phi16 = phi i32 [ %load3, %bb8 ], [ 0, %bb6 ]\n %phi17 = phi i32 [ %phi, %bb8 ], [ %srem, %bb6 ]\n %phi18 = phi i32 [ %phi11, %bb8 ], [ 0, %bb6 ]\n %phi19 = phi i32 [ %phi9, %bb8 ], [ 0, %bb6 ]\n %phi20 = phi i32 [ %phi10, %bb8 ], [ 0, %bb6 ]\n ret void\n\nbb21:\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "slpvectorizer crash", "body": "To reproduce run opt with the test below with -passes=slp-vectorizer -slp-threshold=-99999\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @wombat(i32 %arg) #0 gc \"statepoint-example\" {\nbb:\n %load = load i32, ptr addrspace(3) null, align 4\n %load1 = load i32, ptr addrspace(3) null, align 4\n %load2 = load i32, ptr addrspace(3) null, align 4\n %load3 = load i32, ptr addrspace(3) null, align 4\n br label %bb4\n\nbb4: ; preds = %bb\n switch i32 0, label %bb8 [\n i32 0, label %bb7\n i32 1, label %bb21\n ]\n\nbb5: ; No predecessors!\n %srem = srem i32 0, 0\n br label %bb21\n\nbb6: ; No predecessors!\n br label %bb12\n\nbb7: ; preds = %bb4\n ret void\n\nbb8: ; preds = %bb4\n %phi = phi i32 [ 0, %bb4 ]\n %phi9 = phi i32 [ 0, %bb4 ]\n %phi10 = phi i32 [ 0, %bb4 ]\n %phi11 = phi i32 [ 0, %bb4 ]\n br label %bb12\n\nbb12: ; preds = %bb8, %bb6\n %phi13 = phi i32 [ %load, %bb8 ], [ 0, %bb6 ]\n %phi14 = phi i32 [ %load1, %bb8 ], [ 0, %bb6 ]\n %phi15 = phi i32 [ %load2, %bb8 ], [ %arg, %bb6 ]\n %phi16 = phi i32 [ %load3, %bb8 ], [ 0, %bb6 ]\n %phi17 = phi i32 [ %phi, %bb8 ], [ %srem, %bb6 ]\n %phi18 = phi i32 [ %phi11, %bb8 ], [ 0, %bb6 ]\n %phi19 = phi i32 [ %phi9, %bb8 ], [ 0, %bb6 ]\n %phi20 = phi i32 [ %phi10, %bb8 ], [ 0, %bb6 ]\n ret void\n\nbb21: ; preds = %bb5, %bb4\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-amx-fp8,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,-movrs,-invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,-avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,-sha512,-avxvnni,-rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-vpclmulqdq,-avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,-avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,-avx512bw,+sse3,-pku,-nf,-amx-tf32,-amx-avx512,+fsgsbase,+clzero,-mwaitx,-lwp,+lzcnt,+sha,-movdir64b,-ppx,+wbnoinvd,-enqcmd,-amx-transpose,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-amx-movrs,+rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,-avx512dq,+sse4a\" }\n```\nReproducer: https://godbolt.org/z/1E6shqxdd\n\nStack dump:\n```\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer -slp-threshold=-99999 <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\n #0 0x000000000549f758 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x549f758)\n #1 0x000000000549d0e4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007d8bfda42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00000000017c9e90 llvm::BasicBlock::getTerminator() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x17c9e90)\n #4 0x0000000004492866 llvm::slpvectorizer::BoUpSLP::getSpillCost() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4492866)\n #5 0x00000000044fbea8 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>, llvm::InstructionCost) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44fbea8)\n #6 0x0000000004504152 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4504152)\n #7 0x000000000450937d bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n #8 0x000000000450ad55 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x450ad55)\n #9 0x0000000004512cbe 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\n#10 0x000000000451387b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x451387b)\n#11 0x00000000031ad81e 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+0x31ad81e)\n#12 0x000000000529b7a0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x529b7a0)\n#13 0x0000000000e7a28e 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+0xe7a28e)\n#14 0x000000000529a073 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x529a073)\n#15 0x0000000000e792ae 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+0xe792ae)\n#16 0x0000000005299a80 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5299a80)\n#17 0x000000000093f60a 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+0x93f60a)\n#18 0x0000000000932cfc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x932cfc)\n#19 0x00007d8bfda29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#20 0x00007d8bfda29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#21 0x000000000092a935 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92a935)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
137185
https://github.com/llvm/llvm-project/issues/137185
crash
6479e9bad371f19a36ed15c236defc301efc180f
2025-04-24T14:36:28
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "a750893fea29f32e9bab2cd5176eec34e63b0898", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 2127, 2133 ] ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPScalarIVStepsRecipe::execute" ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a750893fea29f32e9bab2cd5176eec34e63b0898 Author: Maryam Moghadas <[email protected]> Date: Tue May 6 12:48:21 2025 -0400 [VPlan][LV] Fix invalid truncation in VPScalarIVStepsRecipe (#137832) Replace CreateTrunc with CreateSExtOrTrunc in VPScalarIVStepsRecipe to safely handle type conversion. This prevents assertion failures from invalid truncation when StartIdx0 has a smaller integer type than IntStepTy. The assertion was introduced by commit 783a846. Fixes https://github.com/llvm/llvm-project/issues/137185 diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 6027572f1e84..c45c62e13d76 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2127,7 +2127,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) { Builder.CreateMul(StartIdx0, ConstantInt::get(StartIdx0->getType(), getUnrollPart(*this))); } - StartIdx0 = Builder.CreateTrunc(StartIdx0, IntStepTy); + StartIdx0 = Builder.CreateSExtOrTrunc(StartIdx0, IntStepTy); } if (!FirstLaneOnly && State.VF.isScalable()) {
[ { "file": "llvm/test/Transforms/LoopVectorize/PowerPC/vplan-scalarivsext-crash.ll", "commands": [ "opt -passes=loop-vectorize -S %s 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"E-m:a-p:32:32-Fi32-i64:64-n32\"\ntarget triple = \"powerpc-ibm-aix7.2.0.0\"\n\ndefine void @test_iv_trunc_crash(ptr %a, ptr %b, i32 %n) {\n;\nentry:\n %sum.0 = fadd reassoc double 0.0, 0.0\n %x = load double, ptr %a, align 8\n br label %loop_header\n\nloop_header: ; preds = %loop_body, %entry\n %sum.1 = phi double [ %sum.0, %entry ], [ %sum.next, %loop_body ]\n %i = phi i32 [ 0, %entry ], [ %i.next, %loop_body ]\n %cond = icmp sgt i32 %i, %n\n br i1 %cond, label %exit, label %loop_body\n\nloop_body: ; preds = %loop_header\n store double %sum.1, ptr %b, align 8\n %sum.next = fadd reassoc double %sum.1, %x\n %i.next = add i32 %i, 1\n br label %loop_header\n\nexit:\n ret void\n}\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[Loop Vectorize] Crash: Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"'", "body": "Here is the godbolt link to the reproducer: https://godbolt.org/z/354qYx43T\nFor the record here is the IR:\n```\nsource_filename = \"reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @widget() {\nbb:\n %sitofp = sitofp i32 0 to double\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ %add, %bb1 ], [ 0, %bb ]\n %phi2 = phi double [ %fsub, %bb1 ], [ 0.000000e+00, %bb ]\n %fsub = fsub double %phi2, %sitofp\n %add = add i32 %phi, 1\n %icmp = icmp ult i32 %phi, 252\n br i1 %icmp, label %bb1, label %bb3\n\nbb3: ; preds = %bb1\n %phi4 = phi double [ %phi2, %bb1 ]\n %phi5 = phi double [ %fsub, %bb1 ]\n ret void\n}\n```\nwhich fails when running: `opt -passes=loop-vectorize -slp-threshold=-99999 -force-vector-width=4` with the backtrace:\n```\nopt: /root/llvm-project/llvm/lib/IR/Constants.cpp:2231: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize -slp-threshold=-99999 -force-vector-width=4 <source>\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"widget\"\n #0 0x00000000054eff68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54eff68)\n #1 0x00000000054ed8f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007ccdb7442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007ccdb74969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007ccdb7442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007ccdb74287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007ccdb742871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007ccdb7439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x0000000005166c4b llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5166c4b)\n #9 0x0000000000d41160 llvm::IRBuilderBase::CreateTrunc(llvm::Value*, llvm::Type*, llvm::Twine const&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xd41160)\n#10 0x00000000045b9885 llvm::VPScalarIVStepsRecipe::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45b9885)\n#11 0x0000000004576263 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4576263)\n#12 0x000000000457e734 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x457e734)\n#13 0x000000000457f740 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x457f740)\n#14 0x000000000458abda llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x458abda)\n#15 0x000000000442b57c llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x442b57c)\n#16 0x0000000004443b38 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4443b38)\n#17 0x0000000004445ce0 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4445ce0)\n#18 0x0000000004446333 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4446333)\n#19 0x00000000031c103e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x31c103e)\n#20 0x00000000052e90a0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e90a0)\n#21 0x0000000000e7bace 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+0xe7bace)\n#22 0x00000000052e7973 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e7973)\n#23 0x0000000000e7a98e 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+0xe7a98e)\n#24 0x00000000052e7380 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e7380)\n#25 0x000000000094707a 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+0x94707a)\n#26 0x000000000093a84c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93a84c)\n#27 0x00007ccdb7429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#28 0x00007ccdb7429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#29 0x0000000000932485 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x932485)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "Nirhar", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "Nirhar", "body": "As far as I can see, we are trying to truncate an i32 value to i64 type, which is illegal, here:\nhttps://github.com/llvm/llvm-project/blob/72cc868c65b0641f23d1fb0518a8503c73ecdb5a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp#L2137\n\nMight be related to @fhahn 's commit here: 783a846507683c7b515473b833c9cf02cd2b1993" }, { "author": "maryammo", "body": "I have also noticed the assertion as a result of commit 783a846507683c7b515473b833c9cf02cd2b1993 for invalid truncation. \n\n@fhahn , Does the following fix make sense? \n\n```\n--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\n+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp\n@@ -2124,7 +2124,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) {\n Builder.CreateMul(StartIdx0, ConstantInt::get(StartIdx0->getType(),\n getUnrollPart(*this)));\n }\n- StartIdx0 = Builder.CreateTrunc(StartIdx0, IntStepTy);\n+ StartIdx0 = Builder.CreateSExtOrTrunc(StartIdx0, IntStepTy);\n }\n \n if (!FirstLaneOnly && State.VF.isScalable()) {\ndiff --git a/llvm/test/Transforms/LoopVectorize/PowerPC/regression-scalarivsext-crash.ll b/llvm/test/Transforms/LoopVectorize/PowerPC/regression-scalarivsext-crash.ll\nnew file mode 100644\nindex 000000000000..66b54a29b913\n--- /dev/null\n+++ b/llvm/test/Transforms/LoopVectorize/PowerPC/regression-scalarivsext-crash.ll\n@@ -0,0 +1,31 @@\n+; RUN: opt -passes=loop-vectorize -S < %s > /dev/null\n+; REQUIRES: asserts\n+\n+target datalayout = \"E-m:a-p:32:32-Fi32-i64:64-n32\"\n+target triple = \"powerpc-ibm-aix7.2.0.0\"\n+\n+define void @__power_mod_NMOD_power_init(ptr %a, ptr %b, i32 %n) {\n+entry:\n+ br label %loop_entry\n+\n+loop_exit: ; preds = %loop_header\n+ br label %loop_entry\n+\n+loop_entry: ; preds = %loop_exit, %entry\n+ %sum.0 = phi double [ 0.000000e+00, %entry ], [ %sum.1, %loop_exit ]\n+ %x = load double, ptr %a, align 8\n+ br label %loop_header\n+\n+loop_header: ; preds = %loop_body, %loop_entry\n+ %sum.1 = phi double [ %sum.0, %loop_entry ], [ %sum.next, %loop_body ]\n+ %i = phi i32 [ 0, %loop_entry ], [ %i.next, %loop_body ]\n+ %cond = icmp sgt i32 %i, %n\n+ br i1 %cond, label %loop_exit, label %loop_body\n+\n+loop_body: ; preds = %loop_header\n+ store double %sum.1, ptr %b, align 8\n+ %sum.next = fadd reassoc double %sum.1, %x\n+ %i.next = add i32 %i, 1\n+ br label %loop_header\n+}\n+\n```" }, { "author": "fhahn", "body": "@maryammo thanks, could you create a PR? For the test case, does it require a target-triple or can the one provided by @Nirhar be used without a target triple?\n" }, { "author": "maryammo", "body": "@fhahn , Sure I do. Both tests need target triple to fail. " }, { "author": "maryammo", "body": "https://github.com/llvm/llvm-project/pull/137832" } ] }
true
null
89500
https://github.com/llvm/llvm-project/issues/89500
miscompilation
a1b1c4a6d1d52916c5d885170a5f54632d579cdc
2024-04-20T12:43:21
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "7339f7ba3053db7595ece1ca5f49bd2e4c3c8305", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 1722, 1732 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/include/llvm/IR/PatternMatch.h": [ [ 350, 357 ], [ 374, 380 ], [ 389, 400 ], [ 484, 489 ], [ 2596, 2601 ] ], "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "foldSelectICmpEq" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": [ "isValue", "m_AllOnes", "m_Not", "m_c_SMin", "match" ], "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 7339f7ba3053db7595ece1ca5f49bd2e4c3c8305 Author: Nikita Popov <[email protected]> Date: Wed Apr 24 10:57:17 2024 +0900 [InstCombine] Fix poison propagation in select of bitwise fold (#89701) We're replacing the select with the false value here, but it may be more poisonous if m_Not contains poison elements. Fix this by introducing a m_NotForbidPoison matcher and using it here. Fixes https://github.com/llvm/llvm-project/issues/89500. diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 1fee1901fabb..0b13b4aad9c3 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -350,8 +350,9 @@ template <int64_t Val> inline constantint_match<Val> m_ConstantInt() { /// This helper class is used to match constant scalars, vector splats, /// and fixed width vectors that satisfy a specified predicate. -/// For fixed width vector constants, poison elements are ignored. -template <typename Predicate, typename ConstantVal> +/// For fixed width vector constants, poison elements are ignored if AllowPoison +/// is true. +template <typename Predicate, typename ConstantVal, bool AllowPoison> struct cstval_pred_ty : public Predicate { template <typename ITy> bool match(ITy *V) { if (const auto *CV = dyn_cast<ConstantVal>(V)) @@ -374,7 +375,7 @@ struct cstval_pred_ty : public Predicate { Constant *Elt = C->getAggregateElement(i); if (!Elt) return false; - if (isa<PoisonValue>(Elt)) + if (AllowPoison && isa<PoisonValue>(Elt)) continue; auto *CV = dyn_cast<ConstantVal>(Elt); if (!CV || !this->isValue(CV->getValue())) @@ -389,12 +390,13 @@ struct cstval_pred_ty : public Predicate { }; /// specialization of cstval_pred_ty for ConstantInt -template <typename Predicate> -using cst_pred_ty = cstval_pred_ty<Predicate, ConstantInt>; +template <typename Predicate, bool AllowPoison = true> +using cst_pred_ty = cstval_pred_ty<Predicate, ConstantInt, AllowPoison>; /// specialization of cstval_pred_ty for ConstantFP template <typename Predicate> -using cstfp_pred_ty = cstval_pred_ty<Predicate, ConstantFP>; +using cstfp_pred_ty = cstval_pred_ty<Predicate, ConstantFP, + /*AllowPoison=*/true>; /// This helper class is used to match scalar and vector constants that /// satisfy a specified predicate, and bind them to an APInt. @@ -484,6 +486,10 @@ inline cst_pred_ty<is_all_ones> m_AllOnes() { return cst_pred_ty<is_all_ones>(); } +inline cst_pred_ty<is_all_ones, false> m_AllOnesForbidPoison() { + return cst_pred_ty<is_all_ones, false>(); +} + struct is_maxsignedvalue { bool isValue(const APInt &C) { return C.isMaxSignedValue(); } }; @@ -2596,6 +2602,13 @@ m_Not(const ValTy &V) { return m_c_Xor(m_AllOnes(), V); } +template <typename ValTy> +inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor, + true> +m_NotForbidPoison(const ValTy &V) { + return m_c_Xor(m_AllOnesForbidPoison(), V); +} + /// Matches an SMin with LHS and RHS in either order. template <typename LHS, typename RHS> inline MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true> diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 73600206a55c..117eb7a1dcc9 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1722,11 +1722,11 @@ static Instruction *foldSelectICmpEq(SelectInst &SI, ICmpInst *ICI, return match(CmpRHS, m_Zero()) && match(FalseVal, matchInner); if (NotMask == NotInner) { - return match(FalseVal, - m_c_BinOp(OuterOpc, m_Not(matchInner), m_Specific(CmpRHS))); + return match(FalseVal, m_c_BinOp(OuterOpc, m_NotForbidPoison(matchInner), + m_Specific(CmpRHS))); } else if (NotMask == NotRHS) { - return match(FalseVal, - m_c_BinOp(OuterOpc, matchInner, m_Not(m_Specific(CmpRHS)))); + return match(FalseVal, m_c_BinOp(OuterOpc, matchInner, + m_NotForbidPoison(m_Specific(CmpRHS)))); } else { return match(FalseVal, m_c_BinOp(OuterOpc, matchInner, m_Specific(CmpRHS)));
[ { "file": "llvm/test/Transforms/InstCombine/select.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "src_and_eq_C_xor_OrAndNotC_vec_poison", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC_vec_poison(<2 x i32> %0, <2 x i32> %1, <2 x i32> %2) {\nentry:\n %and = and <2 x i32> %1, %0\n %cmp = icmp eq <2 x i32> %and, %2\n %xor = xor <2 x i32> %1, %0\n %or = or <2 x i32> %1, %0\n %not = xor <2 x i32> %2, <i32 -1, i32 poison>\n %and1 = and <2 x i32> %or, %not\n %cond = select <2 x i1> %cmp, <2 x i32> %xor, <2 x i32> %and1\n ret <2 x i32> %cond\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Miscompilation with poison vectors in `src_and_eq_C_xor_OrAndNotC` ", "body": "Alive2: https://alive2.llvm.org/ce/z/yB3oAx\r\n```ll\r\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC(<2 x i32> %0, <2 x i32> %1, <2 x i32> %2) {\r\nentry:\r\n %and = and <2 x i32> %1, %0\r\n %cmp = icmp eq <2 x i32> %and, %2\r\n %xor = xor <2 x i32> %1, %0\r\n %or = or <2 x i32> %1, %0\r\n %not = xor <2 x i32> %2, <i32 -1, i32 poison>\r\n %and1 = and <2 x i32> %or, %not\r\n %cond = select <2 x i1> %cmp, <2 x i32> %xor, <2 x i32> %and1\r\n ret <2 x i32> %cond\r\n}\r\n```\r\n```ll\r\n\r\n----------------------------------------\r\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC(<2 x i32> %#0, <2 x i32> %#1, <2 x i32> %#2) {\r\nentry:\r\n %and = and <2 x i32> %#1, %#0\r\n %cmp = icmp eq <2 x i32> %and, %#2\r\n %xor = xor <2 x i32> %#1, %#0\r\n %or = or <2 x i32> %#1, %#0\r\n %not = xor <2 x i32> %#2, { 4294967295, poison }\r\n %and1 = and <2 x i32> %or, %not\r\n %cond = select <2 x i1> %cmp, <2 x i32> %xor, <2 x i32> %and1\r\n ret <2 x i32> %cond\r\n}\r\n=>\r\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC(<2 x i32> %#0, <2 x i32> %#1, <2 x i32> %#2) nofree willreturn memory(none) {\r\nentry:\r\n %or = or <2 x i32> %#1, %#0\r\n %not = xor <2 x i32> %#2, { 4294967295, poison }\r\n %and1 = and <2 x i32> %or, %not\r\n ret <2 x i32> %and1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<2 x i32> %#0 = < poison, #x00000000 (0) >\r\n<2 x i32> %#1 = < poison, #x00000000 (0) >\r\n<2 x i32> %#2 = < poison, #x00000000 (0) >\r\n\r\nSource:\r\n<2 x i32> %and = < poison, #x00000000 (0) >\r\n<2 x i1> %cmp = < poison, #x1 (1) >\r\n<2 x i32> %xor = < poison, #x00000000 (0) >\r\n<2 x i32> %or = < poison, #x00000000 (0) >\r\n<2 x i32> %not = < poison, poison >\r\n<2 x i32> %and1 = < poison, poison >\r\n<2 x i32> %cond = < poison, #x00000000 (0) >\r\n\r\nTarget:\r\n<2 x i32> %or = < poison, #x00000000 (0) >\r\n<2 x i32> %not = < poison, poison >\r\n<2 x i32> %and1 = < poison, poison >\r\nSource value: < poison, #x00000000 (0) >\r\nTarget value: < poison, poison >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```\r\n\r\nFound with https://github.com/dtcxzyw/llvm-tools.\r\ncc @nikic", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "nikic", "body": "Looks like a recent issue introduced with https://github.com/llvm/llvm-project/pull/73362." }, { "author": "ParkHanbum", "body": "I'll not forget to create a testcase with poison.\r\n" } ] }
true
null
110382
https://github.com/llvm/llvm-project/issues/110382
crash
72a957ba4c8ef059f1572f6d4ee0cba8dc615268
2024-09-28T19:00:52
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "c136d3237a3c6230cfe1ab3f0f6790f903c54a27", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 1984, 2016 ], [ 2038, 2044 ] ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::foldShuffleToIdentity" ], "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit c136d3237a3c6230cfe1ab3f0f6790f903c54a27 Author: David Green <[email protected]> Date: Wed Oct 9 16:20:03 2024 +0100 [VectorCombine] Do not try to operate on OperandBundles. (#111635) This bails out if we see an intrinsic with an operand bundle on it, to make sure we don't process the bundles incorrectly. Fixes #110382. diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index a2ab5d966640..627edb680dfa 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1984,33 +1984,35 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) { // We need each element to be the same type of value, and check that each // element has a single use. - if (all_of(drop_begin(Item), [Item](InstLane IL) { - Value *FrontV = Item.front().first->get(); - if (!IL.first) - return true; - Value *V = IL.first->get(); - if (auto *I = dyn_cast<Instruction>(V); I && !I->hasOneUse()) - return false; - if (V->getValueID() != FrontV->getValueID()) - return false; - if (auto *CI = dyn_cast<CmpInst>(V)) - if (CI->getPredicate() != cast<CmpInst>(FrontV)->getPredicate()) - return false; - if (auto *CI = dyn_cast<CastInst>(V)) - if (CI->getSrcTy() != cast<CastInst>(FrontV)->getSrcTy()) - return false; - if (auto *SI = dyn_cast<SelectInst>(V)) - if (!isa<VectorType>(SI->getOperand(0)->getType()) || - SI->getOperand(0)->getType() != - cast<SelectInst>(FrontV)->getOperand(0)->getType()) - return false; - if (isa<CallInst>(V) && !isa<IntrinsicInst>(V)) - return false; - auto *II = dyn_cast<IntrinsicInst>(V); - return !II || (isa<IntrinsicInst>(FrontV) && - II->getIntrinsicID() == - cast<IntrinsicInst>(FrontV)->getIntrinsicID()); - })) { + auto CheckLaneIsEquivalentToFirst = [Item](InstLane IL) { + Value *FrontV = Item.front().first->get(); + if (!IL.first) + return true; + Value *V = IL.first->get(); + if (auto *I = dyn_cast<Instruction>(V); I && !I->hasOneUse()) + return false; + if (V->getValueID() != FrontV->getValueID()) + return false; + if (auto *CI = dyn_cast<CmpInst>(V)) + if (CI->getPredicate() != cast<CmpInst>(FrontV)->getPredicate()) + return false; + if (auto *CI = dyn_cast<CastInst>(V)) + if (CI->getSrcTy() != cast<CastInst>(FrontV)->getSrcTy()) + return false; + if (auto *SI = dyn_cast<SelectInst>(V)) + if (!isa<VectorType>(SI->getOperand(0)->getType()) || + SI->getOperand(0)->getType() != + cast<SelectInst>(FrontV)->getOperand(0)->getType()) + return false; + if (isa<CallInst>(V) && !isa<IntrinsicInst>(V)) + return false; + auto *II = dyn_cast<IntrinsicInst>(V); + return !II || (isa<IntrinsicInst>(FrontV) && + II->getIntrinsicID() == + cast<IntrinsicInst>(FrontV)->getIntrinsicID() && + !II->hasOperandBundles()); + }; + if (all_of(drop_begin(Item), CheckLaneIsEquivalentToFirst)) { // Check the operator is one that we support. if (isa<BinaryOperator, CmpInst>(FrontU)) { // We exclude div/rem in case they hit UB from poison lanes. @@ -2038,7 +2040,8 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) { Worklist.push_back(generateInstLaneVectorFromOperand(Item, 2)); continue; } else if (auto *II = dyn_cast<IntrinsicInst>(FrontU); - II && isTriviallyVectorizable(II->getIntrinsicID())) { + II && isTriviallyVectorizable(II->getIntrinsicID()) && + !II->hasOperandBundles()) { for (unsigned Op = 0, E = II->getNumOperands() - 1; Op < E; Op++) { if (isVectorIntrinsicWithScalarOpAtArg(II->getIntrinsicID(), Op)) { if (!all_of(drop_begin(Item), [Item, Op](InstLane &IL) {
[ { "file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "add_same_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @add_same_operands(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add = add <4 x i32> %shuf, %shuf\n %revshuf = shufflevector <4 x i32> %add, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i32> %revshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "extrause_add_same_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @extrause_add_same_operands(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add = add <4 x i32> %shuf, %shuf\n %revshuf = shufflevector <4 x i32> %add, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add2 = add <4 x i32> %shuf, %revshuf\n ret <4 x i32> %add2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "callinst2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst2(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @llvm.fabs.v4f16(<4 x half> %at)\n %abb = call <4 x half> @othercall(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "poison_intrinsic", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @poison_intrinsic(<2 x i16> %l256) {\n %l266 = call <2 x i16> @llvm.abs.v2i16(<2 x i16> %l256, i1 false)\n %l267 = zext <2 x i16> %l266 to <2 x i32>\n %l271 = shufflevector <2 x i32> %l267, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>\n ret <4 x i32> %l271\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i16> @llvm.abs.v2i16(<2 x i16>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "splattwice", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splattwice(<8 x half> %a, <8 x half> %b) {\n %as = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> zeroinitializer\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> zeroinitializer\n %ab1 = fadd <4 x half> %as, %bs\n %ab2 = fadd <4 x half> %as, %bs\n %r = shufflevector <4 x half> %ab1, <4 x half> %ab2, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fadd_mismatched_types", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x float> @fadd_mismatched_types(<4 x float> %x, <4 x float> %y) {\n %shuf.x = shufflevector <4 x float> %x, <4 x float> poison, <2 x i32> <i32 0, i32 2>\n %shuf.y = shufflevector <4 x float> %y, <4 x float> poison, <2 x i32> <i32 1, i32 3>\n %fadd = fadd fast <2 x float> %shuf.x, %shuf.y\n %extshuf = shufflevector <2 x float> %fadd, <2 x float> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>\n ret <4 x float> %extshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "intrinsics_minmax", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_minmax(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %abt1 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> %abt, <4 x i8> %bt)\n %abb1 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> %abb, <4 x i8> %bb)\n %abt2 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %abt1, <4 x i8> %bt)\n %abb2 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %abb1, <4 x i8> %bb)\n %abt3 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> %abt2, <4 x i8> %bt)\n %abb3 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> %abb2, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smax.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umax.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "constantdiff2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantdiff2(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, <i8 1, i8 2, i8 3, i8 4>\n %abb = add <4 x i8> %ab, <i8 1, i8 2, i8 3, i8 4>\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fcmpsel", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @fcmpsel(<8 x half> %a, <8 x half> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt1 = fcmp olt <4 x half> %at, %bt\n %abb1 = fcmp olt <4 x half> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "inner_shuffle", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @inner_shuffle(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %cs = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> zeroinitializer\n %abt = mul <4 x i8> %at, %bt\n %abb = mul <4 x i8> %ab, %bb\n %abt2 = shufflevector <4 x i8> %abt, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %abb2 = shufflevector <4 x i8> %abb, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %abt3 = add <4 x i8> %abt2, %cs\n %abb3 = add <4 x i8> %abb2, %cs\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "zext_types", "test_body": "target triple = \"aarch64\"\n\ndefine void @zext_types(<8 x i16> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = zext <4 x i16> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %r = shufflevector <4 x i64> %ab1, <4 x i64> %at1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i64> %r, ptr %p, align 64\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "add_different_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @add_different_operands(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "constantdiff", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantdiff(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, <i8 1, i8 2, i8 3, i8 4>\n %abb = add <4 x i8> %ab, <i8 5, i8 6, i8 7, i8 8>\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "extrause_add_different_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @extrause_add_different_operands(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n call void @use(<4 x i8> %abb)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\ndeclare void @use(<4 x i8>)\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmpsel_diffentcond", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @icmpsel_diffentcond(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt1 = icmp slt <4 x i8> %at, %bt\n %abb1 = icmp ult <4 x i8> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "exttrunc", "test_body": "target triple = \"aarch64\"\n\ndefine void @exttrunc(<8 x i32> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %bb = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %bt = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = zext <4 x i32> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %bb1 = sext <4 x i32> %bb to <4 x i64>\n %bt1 = sext <4 x i32> %bt to <4 x i64>\n %abb = add <4 x i64> %ab1, %bb1\n %abt = add <4 x i64> %at1, %bt1\n %abb1 = trunc <4 x i64> %abb to <4 x i32>\n %abt1 = trunc <4 x i64> %abt to <4 x i32>\n %r = shufflevector <4 x i32> %abb1, <4 x i32> %abt1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "lrint", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i32> @lrint(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half> %at)\n %abb = call <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x i32> %abt, <4 x i32> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i32> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fadd", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fadd(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = fadd <4 x half> %at, %bt\n %abb = fadd <4 x half> %ab, %bb\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "abs_different", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @abs_different(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 true)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "wrong_addsub", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @wrong_addsub(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = sub <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "single_zext", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @single_zext(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i32> %shuf to <4 x i64>\n %revshuf = shufflevector <4 x i64> %zext, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "v8f64interleave", "test_body": "target triple = \"aarch64\"\n\ndefine void @v8f64interleave(i64 %0, ptr %1, ptr %x, double %z) {\nentry:\n %broadcast.splatinsert = insertelement <2 x double> poison, double %z, i64 0\n %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer\n %wide.vec = load <16 x double>, ptr %1, align 8\n %strided.vec = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 0, i32 8>\n %strided.vec27 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 1, i32 9>\n %strided.vec28 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 2, i32 10>\n %strided.vec29 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 3, i32 11>\n %strided.vec30 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 4, i32 12>\n %strided.vec31 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 5, i32 13>\n %strided.vec32 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 6, i32 14>\n %strided.vec33 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 7, i32 15>\n %2 = fmul fast <2 x double> %strided.vec, %broadcast.splat\n %3 = getelementptr inbounds double, ptr %x, i64 %0\n %wide.vec34 = load <16 x double>, ptr %3, align 8\n %strided.vec35 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 0, i32 8>\n %strided.vec36 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 1, i32 9>\n %strided.vec37 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 2, i32 10>\n %strided.vec38 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 3, i32 11>\n %strided.vec39 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 4, i32 12>\n %strided.vec40 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 5, i32 13>\n %strided.vec41 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 6, i32 14>\n %strided.vec42 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 7, i32 15>\n %4 = fadd fast <2 x double> %strided.vec35, %2\n %5 = fmul fast <2 x double> %strided.vec27, %broadcast.splat\n %6 = fadd fast <2 x double> %strided.vec36, %5\n %7 = fmul fast <2 x double> %strided.vec28, %broadcast.splat\n %8 = fadd fast <2 x double> %strided.vec37, %7\n %9 = fmul fast <2 x double> %strided.vec29, %broadcast.splat\n %10 = fadd fast <2 x double> %strided.vec38, %9\n %11 = fmul fast <2 x double> %strided.vec30, %broadcast.splat\n %12 = fadd fast <2 x double> %strided.vec39, %11\n %13 = fmul fast <2 x double> %strided.vec31, %broadcast.splat\n %14 = fadd fast <2 x double> %strided.vec40, %13\n %15 = fmul fast <2 x double> %strided.vec32, %broadcast.splat\n %16 = fadd fast <2 x double> %strided.vec41, %15\n %17 = or disjoint i64 %0, 7\n %18 = fmul fast <2 x double> %strided.vec33, %broadcast.splat\n %19 = getelementptr inbounds double, ptr %x, i64 %17\n %20 = fadd fast <2 x double> %strided.vec42, %18\n %21 = getelementptr inbounds i8, ptr %19, i64 -56\n %22 = shufflevector <2 x double> %4, <2 x double> %6, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %23 = shufflevector <2 x double> %8, <2 x double> %10, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %24 = shufflevector <2 x double> %12, <2 x double> %14, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %25 = shufflevector <2 x double> %16, <2 x double> %20, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %26 = shufflevector <4 x double> %22, <4 x double> %23, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %27 = shufflevector <4 x double> %24, <4 x double> %25, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %interleaved.vec = shufflevector <8 x double> %26, <8 x double> %27, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>\n store <16 x double> %interleaved.vec, ptr %21, align 8\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "singleop", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i8> @singleop(<4 x i8> %a, <4 x i8> %b) {\n %a1 = shufflevector <4 x i8> %a, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %b1 = shufflevector <4 x i8> %b, <4 x i8> poison, <4 x i32> zeroinitializer\n %a2 = zext <4 x i8> %a1 to <4 x i16>\n %b2 = zext <4 x i8> %b1 to <4 x i16>\n %ab = add <4 x i16> %a2, %b2\n %t = trunc <4 x i16> %ab to <4 x i8>\n %r = shufflevector <4 x i8> %t, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_bitcast", "test_body": "target triple = \"aarch64\"\n\ndefine i32 @not_bitcast(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bitcast = bitcast <4 x i8> %shuf to i32\n ret i32 %bitcast\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "zext_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @zext_chain(<4 x i16> %x) {\n %shuf = shufflevector <4 x i16> %x, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i16> %shuf to <4 x i32>\n %sext = sext <4 x i32> %zext to <4 x i64>\n %revshuf = shufflevector <4 x i64> %sext, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "intrinsics_different", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_different(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "operandbundles_second", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @operandbundles_second(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "cast_mismatched_types", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @cast_mismatched_types(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <2 x i32> <i32 0, i32 2>\n %zext = zext <2 x i32> %shuf to <2 x i64>\n %extshuf = shufflevector <2 x i64> %zext, <2 x i64> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>\n ret <4 x i64> %extshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "operandbundles_first", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @operandbundles_first(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "wrong_lanes", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @wrong_lanes(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 6, i32 7, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "first_scalar_select", "test_body": "target triple = \"aarch64\"\n\ndefine <2 x float> @first_scalar_select(<2 x float> %0, <2 x float> %1, float %x) {\nentry:\n %cmp.i903 = fcmp ogt float %x, 0.000000e+00\n %sel1639 = select i1 %cmp.i903, <2 x float> %0, <2 x float> %1\n %2 = fcmp ogt <2 x float> %0, zeroinitializer\n %sel48.i913 = select <2 x i1> %2, <2 x float> %0, <2 x float> %1\n %3 = shufflevector <2 x float> %sel1639, <2 x float> %sel48.i913, <2 x i32> <i32 0, i32 3>\n ret <2 x float> %3\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "splat0", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splat0(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> zeroinitializer\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "splatandidentity", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splatandidentity(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bs = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> zeroinitializer\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "trivial", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @trivial(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %r = shufflevector <4 x i8> %at, <4 x i8> %ab, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "constantsplat", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantsplat(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, splat (i8 10)\n %abb = add <4 x i8> %ab, splat (i8 10)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "bitcast_srcty_mismatch", "test_body": "target triple = \"aarch64\"\n\ndefine void @bitcast_srcty_mismatch() {\nentry:\n %shuffle.i.i = shufflevector <2 x i64> zeroinitializer, <2 x i64> zeroinitializer, <2 x i32> <i32 1, i32 3>\n %0 = bitcast <4 x i32> zeroinitializer to <4 x float>\n %1 = bitcast <2 x i64> %shuffle.i.i to <4 x float>\n %shufp.i196 = shufflevector <4 x float> %0, <4 x float> %1, <4 x i32> <i32 2, i32 1, i32 4, i32 7>\n store <4 x float> %shufp.i196, ptr null, align 16\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "zext_add_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @zext_add_chain(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i32> %shuf to <4 x i64>\n %add = add <4 x i64> %zext, %zext\n %revshuf = shufflevector <4 x i64> %add, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "add_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @add_chain(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add = add <4 x i32> %shuf, %shuf\n %add2 = add <4 x i32> %add, %add\n %revshuf = shufflevector <4 x i32> %add2, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i32> %revshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "splat2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splat2(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 2, i32 2, i32 2, i32 2>\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "trunc", "test_body": "target triple = \"aarch64\"\n\ndefine void @trunc(<8 x i64> %a, <8 x i64> %b, ptr %p) {\n %ab = shufflevector <8 x i64> %a, <8 x i64> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i64> %a, <8 x i64> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %abb1 = trunc <4 x i64> %ab to <4 x i32>\n %abt1 = trunc <4 x i64> %at to <4 x i32>\n %r = shufflevector <4 x i32> %abb1, <4 x i32> %abt1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sext", "test_body": "target triple = \"aarch64\"\n\ndefine void @sext(<8 x i16> %a, <8 x i16> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %bb = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %bt = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = sext <4 x i16> %ab to <4 x i32>\n %at1 = sext <4 x i16> %at to <4 x i32>\n %bb1 = sext <4 x i16> %bb to <4 x i32>\n %bt1 = sext <4 x i16> %bt to <4 x i32>\n %abb = add <4 x i32> %ab1, %bb1\n %abt = add <4 x i32> %at1, %bt1\n %r = shufflevector <4 x i32> %abb, <4 x i32> %abt, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "powi", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @powi(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @llvm.powi.v4f16.i32(<4 x half> %at, i32 10)\n %abb = call <4 x half> @llvm.powi.v4f16.i32(<4 x half> %ab, i32 10)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.powi.v4f16.i32(<4 x half>, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "callinst", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @othercall(<4 x half> %at)\n %abb = call <4 x half> @llvm.fabs.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fma", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fma(<8 x half> %a, <8 x half> %b, <8 x half> %c) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x half> %c, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x half> %c, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abb = call <4 x half> @llvm.fma.v4f16(<4 x half> %ab, <4 x half> %bb, <4 x half> %cb)\n %abt = call <4 x half> @llvm.fma.v4f16(<4 x half> %at, <4 x half> %bt, <4 x half> %ct)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fma.v4f16(<4 x half>, <4 x half>, <4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "extrause_shuffle", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @extrause_shuffle(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n call void @use(<4 x i8> %bt)\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\ndeclare void @use(<4 x i8>)\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "intrinsics_addsat", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_addsat(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %abt1 = call <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8> %abt, <4 x i8> %bt)\n %abb1 = call <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8> %abb, <4 x i8> %bb)\n %abt2 = call <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8> %abt1, <4 x i8> %bt)\n %abb2 = call <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8> %abb1, <4 x i8> %bb)\n %abt3 = call <4 x i8> @llvm.usub.sat.v4i8(<4 x i8> %abt2, <4 x i8> %bt)\n %abb3 = call <4 x i8> @llvm.usub.sat.v4i8(<4 x i8> %abb2, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.usub.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "zext", "test_body": "target triple = \"aarch64\"\n\ndefine void @zext(<8 x i16> %a, <8 x i16> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %bb = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %bt = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = zext <4 x i16> %ab to <4 x i32>\n %at1 = zext <4 x i16> %at to <4 x i32>\n %bb1 = zext <4 x i16> %bb to <4 x i32>\n %bt1 = zext <4 x i16> %bt to <4 x i32>\n %abb = add <4 x i32> %ab1, %bb1\n %abt = add <4 x i32> %at1, %bt1\n %r = shufflevector <4 x i32> %abb, <4 x i32> %abt, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "div", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @div(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = udiv <4 x i8> %at, %bt\n %abb = udiv <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 poison, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "bitcast_smax_v8i32_v4i32", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @bitcast_smax_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b) {\n %a.bc0 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc0 = bitcast <4 x i64> %b to <8 x i32>\n %cmp = icmp slt <8 x i32> %a.bc0, %b.bc0\n %cmp.lo = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %cmp.hi = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %a.bc1 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc1 = bitcast <4 x i64> %b to <8 x i32>\n %a.lo = shufflevector <8 x i32> %a.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %b.lo = shufflevector <8 x i32> %b.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %lo = select <4 x i1> %cmp.lo, <4 x i32> %b.lo, <4 x i32> %a.lo\n %a.bc2 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc2 = bitcast <4 x i64> %b to <8 x i32>\n %a.hi = shufflevector <8 x i32> %a.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %b.hi = shufflevector <8 x i32> %b.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %hi = select <4 x i1> %cmp.hi, <4 x i32> %b.hi, <4 x i32> %a.hi\n %concat = shufflevector <4 x i32> %lo, <4 x i32> %hi, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %res = bitcast <8 x i32> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_bitcast2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i16> @not_bitcast2(<4 x i32> %x, <8 x i16> %y) {\n %cast = bitcast <4 x i32> %x to <8 x i16>\n %out = shufflevector <8 x i16> %y, <8 x i16> %cast, <8 x i32> <i32 8, i32 1, i32 10, i32 3, i32 12, i32 5, i32 14, i32 7>\n ret <8 x i16> %out\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "abs", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @abs(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "maximal_legal_fpmath", "test_body": "target triple = \"aarch64\"\n\ndefine void @maximal_legal_fpmath(ptr %addr1, ptr %addr2, ptr %result, float %val) {\n %splatinsert = insertelement <4 x float> poison, float %val, i64 0\n %incoming.vec = shufflevector <4 x float> %splatinsert, <4 x float> poison, <4 x i32> zeroinitializer\n %vec1 = load <16 x float>, ptr %addr1, align 4\n %strided.vec1 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>\n %strided.vec2 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 1, i32 5, i32 9, i32 13>\n %strided.vec3 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 2, i32 6, i32 10, i32 14>\n %strided.vec4 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 3, i32 7, i32 11, i32 15>\n %vec2 = load <16 x float>, ptr %addr2, align 4\n %strided.vec6 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>\n %strided.vec7 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 1, i32 5, i32 9, i32 13>\n %strided.vec8 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 2, i32 6, i32 10, i32 14>\n %strided.vec9 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 3, i32 7, i32 11, i32 15>\n %1 = fmul fast <4 x float> %incoming.vec, %strided.vec6\n %2 = fadd fast <4 x float> %strided.vec1, %1\n %3 = fmul contract <4 x float> %incoming.vec, %strided.vec7\n %4 = fadd fast <4 x float> %strided.vec2, %3\n %5 = fmul reassoc contract <4 x float> %incoming.vec, %strided.vec8\n %6 = fadd fast <4 x float> %strided.vec3, %5\n %7 = fmul reassoc contract <4 x float> %incoming.vec, %strided.vec9\n %8 = fadd reassoc contract <4 x float> %strided.vec4, %7\n %9 = shufflevector <4 x float> %2, <4 x float> %4, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %10 = shufflevector <4 x float> %6, <4 x float> %8, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %interleaved.vec = shufflevector <8 x float> %9, <8 x float> %10, <16 x i32> <i32 0, i32 4, i32 8, i32 12, i32 1, i32 5, i32 9, i32 13, i32 2, i32 6, i32 10, i32 14, i32 3, i32 7, i32 11, i32 15>\n store <16 x float> %interleaved.vec, ptr %result, align 4\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_zext", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @not_zext(<4 x i32> %x) {\n %zext = zext <4 x i32> %x to <4 x i64>\n %revshuf = shufflevector <4 x i64> %zext, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "undeflane", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @undeflane(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 poison, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "operandbundles", "test_body": "target triple = \"aarch64\"\n\ndefine <16 x i64> @operandbundles(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) {\n %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>\n %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n ret <16 x i64> %shufflevector1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fneg", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fneg(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = fneg <4 x half> %at\n %abb = fneg <4 x half> %ab\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmpsel", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @icmpsel(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt1 = icmp slt <4 x i8> %at, %bt\n %abb1 = icmp slt <4 x i8> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "szext", "test_body": "target triple = \"aarch64\"\n\ndefine void @szext(<8 x i32> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = sext <4 x i32> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %r = shufflevector <4 x i64> %ab1, <4 x i64> %at1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i64> %r, ptr %p, align 64\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "constantsplatf", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @constantsplatf(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = fadd <4 x half> %at, splat (half 0xH4900)\n %abb = fadd <4 x half> %ab, splat (half 0xH4900)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_zext2", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @not_zext2(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i32> %shuf to <4 x i64>\n ret <4 x i64> %zext\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion Failure in Vector Combine", "body": "Runnning vector-combine pass on \r\n```llvm\r\nsource_filename = \"text\"\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-ni:10:11:12:13\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine nonnull ptr addrspace(10) @wombat() {\r\n %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> zeroinitializer, <4 x i64> zeroinitializer, <4 x i64> <i64 45, i64 45, i64 45, i64 45>) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\r\n %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>\r\n %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\r\n ret ptr addrspace(10) null\r\n}\r\n\r\ndeclare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)\r\n```\r\nproduces\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::Type]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' 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=vector-combine <source>\r\n1.\tRunning pass \"function(vector-combine)\" on module \"<source>\"\r\n2.\tRunning pass \"vector-combine\" on function \"wombat\"\r\n #0 0x0000000005079b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5079b38)\r\n #1 0x00000000050774ec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074d0dce42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074d0dce969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074d0dce42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074d0dce287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000074d0dce2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000074d0dce39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004186458 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\r\n #9 0x0000000004190f01 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\r\n#10 0x0000000004191c25 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4191c25)\r\n#11 0x0000000002f2defe llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f2defe)\r\n#12 0x0000000004e7c978 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7c978)\r\n#13 0x0000000000e157ce 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+0xe157ce)\r\n#14 0x0000000004e7b39e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7b39e)\r\n#15 0x0000000000e14f7e 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+0xe14f7e)\r\n#16 0x0000000004e7add0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7add0)\r\n#17 0x0000000000904cc2 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+0x904cc2)\r\n#18 0x00000000008f7b4c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f7b4c)\r\n#19 0x000074d0dce29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x000074d0dce29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008ef61e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ef61e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nGodbolt: https://godbolt.org/z/MGefYs3M5", "author": "Zentrik", "labels": [ "release:backport", "vectorizers", "crash" ], "comments": [ { "author": "Heresh83", "body": "> Runnning vector-combine pass on \n> ```llvm\n> source_filename = \"text\"\n> target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:10:11:12:13\"\n> target triple = \"x86_64-unknown-linux-gnu\"\n> \n> define nonnull ptr addrspace(10) @wombat() {\n> %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> zeroinitializer, <4 x i64> zeroinitializer, <4 x i64> <i64 45, i64 45, i64 45, i64 45>) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n> %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>\n> %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n> ret ptr addrspace(10) null\n> }\n> \n> declare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)\n> ```\n> produces\n> ```\n> opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::Type]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\n> PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\n> Stack dump:\n> 0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=vector-combine <source>\n> 1.\tRunning pass \"function(vector-combine)\" on module \"<source>\"\n> 2.\tRunning pass \"vector-combine\" on function \"wombat\"\n> #0 0x0000000005079b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5079b38)\n> #1 0x00000000050774ec SignalHandler(int) Signals.cpp:0:0\n> #2 0x000074d0dce42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n> #3 0x000074d0dce969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n> #4 0x000074d0dce42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n> #5 0x000074d0dce287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n> #6 0x000074d0dce2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n> #7 0x000074d0dce39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n> #8 0x0000000004186458 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\n> #9 0x0000000004190f01 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\n> #10 0x0000000004191c25 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4191c25)\n> #11 0x0000000002f2defe llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f2defe)\n> #12 0x0000000004e7c978 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7c978)\n> #13 0x0000000000e157ce 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+0xe157ce)\n> #14 0x0000000004e7b39e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7b39e)\n> #15 0x0000000000e14f7e 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+0xe14f7e)\n> #16 0x0000000004e7add0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7add0)\n> #17 0x0000000000904cc2 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+0x904cc2)\n> #18 0x00000000008f7b4c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f7b4c)\n> #19 0x000074d0dce29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n> #20 0x000074d0dce29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n> #21 0x00000000008ef61e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ef61e)\n> Program terminated with signal: SIGSEGV\n> Compiler returned: 139\n> ```\n> Godbolt: https://godbolt.org/z/MGefYs3M5\n\n" }, { "author": "RKSimon", "body": "Looks like foldShuffleToIdentity is attempting to fold the operand bundle on the fshl call" } ] }
true
null
124518
https://github.com/llvm/llvm-project/issues/124518
crash
2ec88374e07f8ec395b7bf414bf1bdda88cebfc6
2025-01-27T07:58:41
[ "llvm/test/Transforms/LoopUnrollAndJam" ]
{ "fix_commit": "3ef33066bb32a9d9b76d72c6de6a7ae9ff72ddcc", "components": [ "LoopUnrollAndJamPass" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": [ [ 425, 431 ], [ 441, 448 ], [ 457, 467 ] ], "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": [ "LoopUnrollAndJamPass::run", "tryToUnrollAndJamLoop" ], "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 3ef33066bb32a9d9b76d72c6de6a7ae9ff72ddcc Author: David Green <[email protected]> Date: Sat Mar 29 19:21:34 2025 +0000 [UnrollAndJam] Do not preserve loop nests if a loop was fully unrolled. (#133510) If UnJ completely unrolls a loop and removes it entirely, the loop remains in the current loop nest. If the loop nest gets reused the loops will no longer be valid. As there is no way to remove a loop from a LoopNest, this patch removes the preserve of the LoopNestAnalysis so that it will be regenerated. Fixes #124518 diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp index f1d1f3bc1e30..4fe74c7c3bbc 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp @@ -425,7 +425,7 @@ static bool tryToUnrollAndJamLoop(LoopNest &LN, DominatorTree &DT, LoopInfo &LI, const TargetTransformInfo &TTI, AssumptionCache &AC, DependenceInfo &DI, OptimizationRemarkEmitter &ORE, int OptLevel, - LPMUpdater &U) { + LPMUpdater &U, bool &AnyLoopRemoved) { bool DidSomething = false; ArrayRef<Loop *> Loops = LN.getLoops(); Loop *OutmostLoop = &LN.getOutermostLoop(); @@ -441,8 +441,11 @@ static bool tryToUnrollAndJamLoop(LoopNest &LN, DominatorTree &DT, LoopInfo &LI, tryToUnrollAndJamLoop(L, DT, &LI, SE, TTI, AC, DI, ORE, OptLevel); if (Result != LoopUnrollResult::Unmodified) DidSomething = true; - if (L == OutmostLoop && Result == LoopUnrollResult::FullyUnrolled) - U.markLoopAsDeleted(*L, LoopName); + if (Result == LoopUnrollResult::FullyUnrolled) { + if (L == OutmostLoop) + U.markLoopAsDeleted(*L, LoopName); + AnyLoopRemoved = true; + } } return DidSomething; @@ -457,11 +460,13 @@ PreservedAnalyses LoopUnrollAndJamPass::run(LoopNest &LN, DependenceInfo DI(&F, &AR.AA, &AR.SE, &AR.LI); OptimizationRemarkEmitter ORE(&F); + bool AnyLoopRemoved = false; if (!tryToUnrollAndJamLoop(LN, AR.DT, AR.LI, AR.SE, AR.TTI, AR.AC, DI, ORE, - OptLevel, U)) + OptLevel, U, AnyLoopRemoved)) return PreservedAnalyses::all(); auto PA = getLoopPassPreservedAnalyses(); - PA.preserve<LoopNestAnalysis>(); + if (!AnyLoopRemoved) + PA.preserve<LoopNestAnalysis>(); return PA; }
[ { "file": "llvm/test/Transforms/LoopUnrollAndJam/delete_middle_loop.ll", "commands": [ "opt -passes=\"loop(invalidate<all>,loop-unroll-and-jam,loop-unroll-and-jam)\" -allow-unroll-and-jam -unroll-and-jam-count=4 < %s -S" ], "tests": [ { "test_name": "<module>", "test_body": "\n; This test completely unrolls the middle loop out of a 3-deep loop nest.\n\ndefine i16 @test_it() {\n;\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %do.cond, %entry\n br label %do.body2\n\ndo.body2: ; preds = %do.cond, %for.cond\n br label %while.cond3\n\nwhile.cond3: ; preds = %while.cond3, %do.body2\n br i1 true, label %do.cond, label %while.cond3\n\ndo.cond: ; preds = %while.cond3\n br i1 true, label %for.cond, label %do.body2\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "LoopUnrollAndJamPass crash: GenericLoopInfo.h:146: [...] Assertion `!isInvalid() && \"Loop not in a valid state!\"' failed.", "body": "llvm commit: 6805d7e8aa5f\n\nReproduce with:\n```opt -passes=\"loop(invalidate<all>,loop-unroll-and-jam,loop-unroll-and-jam)\" bbi-103085.ll -o /dev/null -S -unroll-and-jam-count=4 -mcpu=cortex-a55 -mtriple=aarch64```\n\nResult:\n```\nopt: ../include/llvm/Support/GenericLoopInfo.h:146: const std::vector<LoopT *> &llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::getSubLoops() const [BlockT = llvm::BasicBlock, LoopT = llvm::Loop]: Assertion `!isInvalid() && \"Loop not in a valid state!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: build-all/bin/opt -passes=loop(invalidate<all>,loop-unroll-and-jam,loop-unroll-and-jam) bbi-103085.ll -o /dev/null -S -unroll-and-jam-count=4 -mcpu=cortex-a55 -mtriple=aarch64\n1.\tRunning pass \"function(loop(invalidate<all>,loop-unroll-and-jam,loop-unroll-and-jam))\" on module \"bbi-103085.ll\"\n2.\tRunning pass \"loop(invalidate<all>,loop-unroll-and-jam,loop-unroll-and-jam)\" on function \"test_it\"\n #0 0x0000564cc1e14ac6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/opt+0x45ceac6)\n #1 0x0000564cc1e1250e llvm::sys::RunSignalHandlers() (build-all/bin/opt+0x45cc50e)\n #2 0x0000564cc1e15379 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007fafbeb0bd10 __restore_rt (/lib64/libpthread.so.0+0x12d10)\n #4 0x00007fafbc4ab52f raise (/lib64/libc.so.6+0x4e52f)\n #5 0x00007fafbc47ee65 abort (/lib64/libc.so.6+0x21e65)\n #6 0x00007fafbc47ed39 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d39)\n #7 0x00007fafbc4a3e86 (/lib64/libc.so.6+0x46e86)\n #8 0x0000564cc274b6cb void llvm::appendReversedLoopsToWorklist<llvm::iterator_range<std::reverse_iterator<llvm::Loop* const*>>>(llvm::iterator_range<std::reverse_iterator<llvm::Loop* const*>>&&, llvm::SmallPriorityWorklist<llvm::Loop*, 4u>&) (build-all/bin/opt+0x4f056cb)\n #9 0x0000564cc274b42e void llvm::appendLoopsToWorklist<llvm::ArrayRef<llvm::Loop*>&>(llvm::ArrayRef<llvm::Loop*>&, llvm::SmallPriorityWorklist<llvm::Loop*, 4u>&) (build-all/bin/opt+0x4f0542e)\n#10 0x0000564cc381dfce llvm::LoopUnrollAndJamPass::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (build-all/bin/opt+0x5fd7fce)\n#11 0x0000564cc328d01d llvm::detail::PassModel<llvm::LoopNest, llvm::LoopUnrollAndJamPass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) PassBuilderPipelines.cpp:0:0\n#12 0x0000564cc34ff5ed std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::LoopNest, std::unique_ptr<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::LoopNest&, std::unique_ptr<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) (build-all/bin/opt+0x5cb95ed)\n#13 0x0000564cc34fe8e5 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (build-all/bin/opt+0x5cb88e5)\n#14 0x0000564cc34fe480 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (build-all/bin/opt+0x5cb8480)\n#15 0x0000564cc327a8bd llvm::detail::PassModel<llvm::Loop, llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) PassBuilderPipelines.cpp:0:0\n#16 0x0000564cc35001a1 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x5cba1a1)\n#17 0x0000564cc327eedd llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\n#18 0x0000564cc2035a27 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x47efa27)\n#19 0x0000564cc32846cd llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\n#20 0x0000564cc203a5fe llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x47f45fe)\n#21 0x0000564cc327c19d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilderPipelines.cpp:0:0\n#22 0x0000564cc2034717 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x47ee717)\n#23 0x0000564cc320468c 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) (build-all/bin/opt+0x59be68c)\n#24 0x0000564cc1dd7712 optMain (build-all/bin/opt+0x4591712)\n#25 0x00007fafbc4977e5 __libc_start_main (/lib64/libc.so.6+0x3a7e5)\n#26 0x0000564cc1dd532e _start (build-all/bin/opt+0x458f32e)\nAbort\n```\n\n[bbi-103085.ll.gz](https://github.com/user-attachments/files/18556221/bbi-103085.ll.gz)", "author": "mikaelholmen", "labels": [ "crash", "llvm:transforms", "generated by fuzzer" ], "comments": [ { "author": "mikaelholmen", "body": "The opt pipeline used to triggered this is non-standard and generated by a fuzzer, so I'm labelling this with \"generated by fuzzer\". I don't know if that the intended use. If not, please let me know." }, { "author": "davemgreen", "body": "Do you have the IR reproducer too? Thanks" }, { "author": "mikaelholmen", "body": "> Do you have the IR reproducer too? Thanks\n\nBah, sorry. Attached it to the original post now.\nThanks!" }, { "author": "mikaelholmen", "body": "I noticed that if we build opt with ASAN and run the bbi-103085.ll testcase we get\n```\n==3349467==ERROR: AddressSanitizer: use-after-poison on address 0x521000007a40 at pc 0x55713d205877 bp 0x7ffdd1999e50 sp 0x7ffdd1999e48\nREAD of size 1 at 0x521000007a40 thread T0\n #0 0x55713d205876 in isInvalid /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/GenericLoopInfo.h:219:12\n #1 0x55713d205876 in getSubLoops /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/GenericLoopInfo.h:146:5\n #2 0x55713d205876 in begin /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/GenericLoopInfo.h:156:35\n #3 0x55713d205876 in void llvm::appendReversedLoopsToWorklist<llvm::iterator_range<std::__1::reverse_iterator<llvm::Loop* const*>>>(llvm::iterator_range<std::__1::reverse_iterator<llvm::Loop* const*>>&&, llvm::SmallPriorityWorklist<llvm::Loop*, 4u>&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Utils/LoopUtils.cpp:1808:34\n #4 0x55713d204ad9 in void llvm::appendLoopsToWorklist<llvm::ArrayRef<llvm::Loop*>&>(llvm::ArrayRef<llvm::Loop*>&, llvm::SmallPriorityWorklist<llvm::Loop*, 4u>&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Utils/LoopUtils.cpp:1820:3\n #5 0x55714083fe1b in tryToUnrollAndJamLoop /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp:436:3\n #6 0x55714083fe1b in llvm::LoopUnrollAndJamPass::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp:460:8\n #7 0x55713f72db11 in llvm::detail::PassModel<llvm::LoopNest, llvm::LoopUnrollAndJamPass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #8 0x55713fec0dd7 in std::__1::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::LoopNest, std::__1::unique_ptr<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::__1::default_delete<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::LoopNest&, std::__1::unique_ptr<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::__1::default_delete<llvm::detail::PassConcept<llvm::LoopNest, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/Transforms/Scalar/LoopPassManager.h:375:32\n #9 0x55713febe67c in llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Scalar/LoopPassManager.cpp:112:16\n #10 0x55713febdd61 in llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Scalar/LoopPassManager.cpp:30:32\n #11 0x55713f719901 in llvm::detail::PassModel<llvm::Loop, llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #12 0x55713fec3348 in llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Scalar/LoopPassManager.cpp:302:38\n #13 0x55713f722991 in llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #14 0x55713ba254c9 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerImpl.h:81:38\n #15 0x55713f728871 in llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #16 0x55713ba34d25 in llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /repo/llvm/build-all-bbisdk-asan/../lib/IR/PassManager.cpp:124:38\n #17 0x55713f71d491 in llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #18 0x55713ba218f9 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerImpl.h:81:38\n #19 0x55713f5eda5d in 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::__1::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /repo/llvm/build-all-bbisdk-asan/../tools/opt/NewPMDriver.cpp:552:7\n #20 0x55713b2721b3 in optMain /repo/llvm/build-all-bbisdk-asan/../tools/opt/optdriver.cpp:725:12\n #21 0x7f6c3bae47e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) (BuildId: 37e4ac6a7fb96950b0e6bf72d73d94f3296c77eb)\n #22 0x55713b1823ad in _start (/repo/llvm/build-all-bbisdk-asan/bin/opt+0x8cfe3ad)\n\n0x521000007a40 is located 320 bytes inside of 4096-byte region [0x521000007900,0x521000008900)\nallocated by thread T0 here:\n #0 0x55713b25a992 in operator new(unsigned long, std::align_val_t, std::nothrow_t const&) asan_new_delete.cpp:113:3\n #1 0x55713b346d4f in llvm::allocate_buffer(unsigned long, unsigned long) /repo/llvm/build-all-bbisdk-asan/../lib/Support/MemAlloc.cpp:16:18\n #2 0x55713b34a30a in Allocate /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/AllocatorBase.h:92:12\n #3 0x55713b34a30a in StartNewSlab /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/Allocator.h:346:42\n #4 0x55713b34a30a in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>::AllocateSlow(unsigned long, unsigned long, llvm::Align) /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/Allocator.h:202:5\n #5 0x55713cb12443 in Allocate /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/Allocator.h:178:12\n #6 0x55713cb12443 in Allocate /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/Allocator.h:216:12\n #7 0x55713cb12443 in Allocate /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/AllocatorBase.h:53:43\n #8 0x55713cb12443 in Allocate<llvm::Loop> /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/AllocatorBase.h:76:29\n #9 0x55713cb12443 in llvm::Loop* llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::AllocateLoop<llvm::BasicBlock*&>(llvm::BasicBlock*&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/GenericLoopInfo.h:571:36\n #10 0x55713cb0ff50 in llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::analyze(llvm::DominatorTreeBase<llvm::BasicBlock, false> const&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/GenericLoopInfoImpl.h:594:18\n #11 0x55713cb23dbc in llvm::LoopAnalysis::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../lib/Analysis/LoopInfo.cpp:977:6\n #12 0x55714109e4e7 in llvm::detail::AnalysisPassModel<llvm::Function, llvm::LoopAnalysis, llvm::AnalysisManager<llvm::Function>::Invalidator>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:321:14\n #13 0x55713ba300ab in llvm::AnalysisManager<llvm::Function>::getResultImpl(llvm::AnalysisKey*, llvm::Function&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerImpl.h:156:35\n #14 0x55713d1e67b4 in getResult<llvm::LoopAnalysis> /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManager.h:414:9\n #15 0x55713d1e67b4 in llvm::LoopSimplifyPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Utils/LoopSimplify.cpp:825:22\n #16 0x55713f719f11 in llvm::detail::PassModel<llvm::Function, llvm::LoopSimplifyPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #17 0x55713ba254c9 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerImpl.h:81:38\n #18 0x55713fec1dce in llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../lib/Transforms/Scalar/LoopPassManager.cpp:209:34\n #19 0x55713f722991 in llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #20 0x55713ba254c9 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerImpl.h:81:38\n #21 0x55713f728871 in llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #22 0x55713ba34d25 in llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /repo/llvm/build-all-bbisdk-asan/../lib/IR/PassManager.cpp:124:38\n #23 0x55713f71d491 in llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerInternal.h:91:17\n #24 0x55713ba218f9 in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /repo/llvm/build-all-bbisdk-asan/../include/llvm/IR/PassManagerImpl.h:81:38\n #25 0x55713f5eda5d in 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::__1::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /repo/llvm/build-all-bbisdk-asan/../tools/opt/NewPMDriver.cpp:552:7\n #26 0x55713b2721b3 in optMain /repo/llvm/build-all-bbisdk-asan/../tools/opt/optdriver.cpp:725:12\n #27 0x7f6c3bae47e4 in __libc_start_main (/lib64/libc.so.6+0x3a7e4) (BuildId: 37e4ac6a7fb96950b0e6bf72d73d94f3296c77eb)\n\nSUMMARY: AddressSanitizer: use-after-poison /repo/llvm/build-all-bbisdk-asan/../include/llvm/Support/GenericLoopInfo.h:219:12 in isInvalid\nShadow bytes around the buggy address:\n 0x521000007780: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n 0x521000007800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n 0x521000007880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n 0x521000007900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n 0x521000007980: 00 00 00 00 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7\n=>0x521000007a00: f7 f7 f7 f7 f7 f7 f7 f7[f7]f7 00 00 00 00 00 00\n 0x521000007a80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f7 f7\n 0x521000007b00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7\n 0x521000007b80: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7\n 0x521000007c00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7\n 0x521000007c80: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7\nShadow byte legend (one shadow byte represents 8 application bytes):\n Addressable: 00\n Partially addressable: 01 02 03 04 05 06 07 \n Heap left redzone: fa\n Freed heap region: fd\n Stack left redzone: f1\n Stack mid redzone: f2\n Stack right redzone: f3\n Stack after return: f5\n Stack use after scope: f8\n Global redzone: f9\n Global init order: f6\n Poisoned by user: f7\n Container overflow: fc\n Array cookie: ac\n Intra object redzone: bb\n ASan internal: fe\n Left alloca redzone: ca\n Right alloca redzone: cb\n==3349467==ABORTING\n```\n" } ] }
true
null
91417
https://github.com/llvm/llvm-project/issues/91417
miscompilation
d9507a3e10d1750d88dd518c14b9a9a62b9eefcd
2024-05-08T01:40:37
[ "llvm/test/Transforms/Reassociate" ]
{ "fix_commit": "645fb04a3389e69801d401e669eae9ee42d70217", "components": [ "Reassociate" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": [ [ 302, 399 ], [ 475, 481 ], [ 490, 497 ], [ 509, 515 ], [ 518, 525 ], [ 528, 534 ], [ 562, 568 ], [ 625, 634 ], [ 642, 648 ], [ 1188, 1195 ], [ 2368, 2374 ] ], "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": [ "CarmichaelShift", "IncorporateWeight", "LinearizeExprTree", "LowerNegateToMultiply", "ReassociatePass::ReassociateExpression", "ReassociatePass::RemoveFactorFromExpression" ], "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 645fb04a3389e69801d401e669eae9ee42d70217 Author: Yingwei Zheng <[email protected]> Date: Sat Jun 8 22:28:56 2024 +0800 [Reassociate] Use uint64_t for repeat count (#94232) This patch relands #91469 and uses `uint64_t` for repeat count to avoid a miscompilation caused by overflow https://github.com/llvm/llvm-project/pull/91469#discussion_r1623925158. diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index c73d7c8d83be..f36e21b296bd 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -302,98 +302,7 @@ static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) { return Res; } -/// Returns k such that lambda(2^Bitwidth) = 2^k, where lambda is the Carmichael -/// function. This means that x^(2^k) === 1 mod 2^Bitwidth for -/// every odd x, i.e. x^(2^k) = 1 for every odd x in Bitwidth-bit arithmetic. -/// Note that 0 <= k < Bitwidth, and if Bitwidth > 3 then x^(2^k) = 0 for every -/// even x in Bitwidth-bit arithmetic. -static unsigned CarmichaelShift(unsigned Bitwidth) { - if (Bitwidth < 3) - return Bitwidth - 1; - return Bitwidth - 2; -} - -/// Add the extra weight 'RHS' to the existing weight 'LHS', -/// reducing the combined weight using any special properties of the operation. -/// The existing weight LHS represents the computation X op X op ... op X where -/// X occurs LHS times. The combined weight represents X op X op ... op X with -/// X occurring LHS + RHS times. If op is "Xor" for example then the combined -/// operation is equivalent to X if LHS + RHS is odd, or 0 if LHS + RHS is even; -/// the routine returns 1 in LHS in the first case, and 0 in LHS in the second. -static void IncorporateWeight(APInt &LHS, const APInt &RHS, unsigned Opcode) { - // If we were working with infinite precision arithmetic then the combined - // weight would be LHS + RHS. But we are using finite precision arithmetic, - // and the APInt sum LHS + RHS may not be correct if it wraps (it is correct - // for nilpotent operations and addition, but not for idempotent operations - // and multiplication), so it is important to correctly reduce the combined - // weight back into range if wrapping would be wrong. - - // If RHS is zero then the weight didn't change. - if (RHS.isMinValue()) - return; - // If LHS is zero then the combined weight is RHS. - if (LHS.isMinValue()) { - LHS = RHS; - return; - } - // From this point on we know that neither LHS nor RHS is zero. - - if (Instruction::isIdempotent(Opcode)) { - // Idempotent means X op X === X, so any non-zero weight is equivalent to a - // weight of 1. Keeping weights at zero or one also means that wrapping is - // not a problem. - assert(LHS == 1 && RHS == 1 && "Weights not reduced!"); - return; // Return a weight of 1. - } - if (Instruction::isNilpotent(Opcode)) { - // Nilpotent means X op X === 0, so reduce weights modulo 2. - assert(LHS == 1 && RHS == 1 && "Weights not reduced!"); - LHS = 0; // 1 + 1 === 0 modulo 2. - return; - } - if (Opcode == Instruction::Add || Opcode == Instruction::FAdd) { - // TODO: Reduce the weight by exploiting nsw/nuw? - LHS += RHS; - return; - } - - assert((Opcode == Instruction::Mul || Opcode == Instruction::FMul) && - "Unknown associative operation!"); - unsigned Bitwidth = LHS.getBitWidth(); - // If CM is the Carmichael number then a weight W satisfying W >= CM+Bitwidth - // can be replaced with W-CM. That's because x^W=x^(W-CM) for every Bitwidth - // bit number x, since either x is odd in which case x^CM = 1, or x is even in - // which case both x^W and x^(W - CM) are zero. By subtracting off multiples - // of CM like this weights can always be reduced to the range [0, CM+Bitwidth) - // which by a happy accident means that they can always be represented using - // Bitwidth bits. - // TODO: Reduce the weight by exploiting nsw/nuw? (Could do much better than - // the Carmichael number). - if (Bitwidth > 3) { - /// CM - The value of Carmichael's lambda function. - APInt CM = APInt::getOneBitSet(Bitwidth, CarmichaelShift(Bitwidth)); - // Any weight W >= Threshold can be replaced with W - CM. - APInt Threshold = CM + Bitwidth; - assert(LHS.ult(Threshold) && RHS.ult(Threshold) && "Weights not reduced!"); - // For Bitwidth 4 or more the following sum does not overflow. - LHS += RHS; - while (LHS.uge(Threshold)) - LHS -= CM; - } else { - // To avoid problems with overflow do everything the same as above but using - // a larger type. - unsigned CM = 1U << CarmichaelShift(Bitwidth); - unsigned Threshold = CM + Bitwidth; - assert(LHS.getZExtValue() < Threshold && RHS.getZExtValue() < Threshold && - "Weights not reduced!"); - unsigned Total = LHS.getZExtValue() + RHS.getZExtValue(); - while (Total >= Threshold) - Total -= CM; - LHS = Total; - } -} - -using RepeatedValue = std::pair<Value*, APInt>; +using RepeatedValue = std::pair<Value *, uint64_t>; /// Given an associative binary expression, return the leaf /// nodes in Ops along with their weights (how many times the leaf occurs). The @@ -475,7 +384,6 @@ static bool LinearizeExprTree(Instruction *I, assert((isa<UnaryOperator>(I) || isa<BinaryOperator>(I)) && "Expected a UnaryOperator or BinaryOperator!"); LLVM_DEBUG(dbgs() << "LINEARIZE: " << *I << '\n'); - unsigned Bitwidth = I->getType()->getScalarType()->getPrimitiveSizeInBits(); unsigned Opcode = I->getOpcode(); assert(I->isAssociative() && I->isCommutative() && "Expected an associative and commutative operation!"); @@ -490,8 +398,8 @@ static bool LinearizeExprTree(Instruction *I, // with their weights, representing a certain number of paths to the operator. // If an operator occurs in the worklist multiple times then we found multiple // ways to get to it. - SmallVector<std::pair<Instruction*, APInt>, 8> Worklist; // (Op, Weight) - Worklist.push_back(std::make_pair(I, APInt(Bitwidth, 1))); + SmallVector<std::pair<Instruction *, uint64_t>, 8> Worklist; // (Op, Weight) + Worklist.push_back(std::make_pair(I, 1)); bool Changed = false; // Leaves of the expression are values that either aren't the right kind of @@ -509,7 +417,7 @@ static bool LinearizeExprTree(Instruction *I, // Leaves - Keeps track of the set of putative leaves as well as the number of // paths to each leaf seen so far. - using LeafMap = DenseMap<Value *, APInt>; + using LeafMap = DenseMap<Value *, uint64_t>; LeafMap Leaves; // Leaf -> Total weight so far. SmallVector<Value *, 8> LeafOrder; // Ensure deterministic leaf output order. const DataLayout DL = I->getModule()->getDataLayout(); @@ -518,8 +426,8 @@ static bool LinearizeExprTree(Instruction *I, SmallPtrSet<Value *, 8> Visited; // For checking the iteration scheme. #endif while (!Worklist.empty()) { - std::pair<Instruction*, APInt> P = Worklist.pop_back_val(); - I = P.first; // We examine the operands of this binary operator. + // We examine the operands of this binary operator. + auto [I, Weight] = Worklist.pop_back_val(); if (isa<OverflowingBinaryOperator>(I)) { Flags.HasNUW &= I->hasNoUnsignedWrap(); @@ -528,7 +436,6 @@ static bool LinearizeExprTree(Instruction *I, for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) { // Visit operands. Value *Op = I->getOperand(OpIdx); - APInt Weight = P.second; // Number of paths to this operand. LLVM_DEBUG(dbgs() << "OPERAND: " << *Op << " (" << Weight << ")\n"); assert(!Op->use_empty() && "No uses, so how did we get to it?!"); @@ -562,7 +469,8 @@ static bool LinearizeExprTree(Instruction *I, "In leaf map but not visited!"); // Update the number of paths to the leaf. - IncorporateWeight(It->second, Weight, Opcode); + It->second += Weight; + assert(It->second >= Weight && "Weight overflows"); // If we still have uses that are not accounted for by the expression // then it is not safe to modify the value. @@ -625,10 +533,7 @@ static bool LinearizeExprTree(Instruction *I, // Node initially thought to be a leaf wasn't. continue; assert(!isReassociableOp(V, Opcode) && "Shouldn't be a leaf!"); - APInt Weight = It->second; - if (Weight.isMinValue()) - // Leaf already output or weight reduction eliminated it. - continue; + uint64_t Weight = It->second; // Ensure the leaf is only output once. It->second = 0; Ops.push_back(std::make_pair(V, Weight)); @@ -642,7 +547,7 @@ static bool LinearizeExprTree(Instruction *I, if (Ops.empty()) { Constant *Identity = ConstantExpr::getBinOpIdentity(Opcode, I->getType()); assert(Identity && "Associative operation without identity!"); - Ops.emplace_back(Identity, APInt(Bitwidth, 1)); + Ops.emplace_back(Identity, 1); } return Changed; @@ -1188,8 +1093,7 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor) { Factors.reserve(Tree.size()); for (unsigned i = 0, e = Tree.size(); i != e; ++i) { RepeatedValue E = Tree[i]; - Factors.append(E.second.getZExtValue(), - ValueEntry(getRank(E.first), E.first)); + Factors.append(E.second, ValueEntry(getRank(E.first), E.first)); } bool FoundFactor = false; @@ -2368,7 +2272,7 @@ void ReassociatePass::ReassociateExpression(BinaryOperator *I) { SmallVector<ValueEntry, 8> Ops; Ops.reserve(Tree.size()); for (const RepeatedValue &E : Tree) - Ops.append(E.second.getZExtValue(), ValueEntry(getRank(E.first), E.first)); + Ops.append(E.second, ValueEntry(getRank(E.first), E.first)); LLVM_DEBUG(dbgs() << "RAIn:\t"; PrintOps(I, Ops); dbgs() << '\n');
[ { "file": "llvm/test/Transforms/Reassociate/repeats.ll", "commands": [ "opt < %s -passes=reassociate -S" ], "tests": [ { "test_name": "foo4x11", "test_body": "define i4 @foo4x11(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n ret i4 %tmp10\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo3x5_nsw", "test_body": "define i3 @foo3x5_nsw(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul nsw i3 %tmp3, %x\n ret i3 %tmp4\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo3x5", "test_body": "define i3 @foo3x5(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul i3 %tmp3, %x\n ret i3 %tmp4\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x10", "test_body": "define i4 @foo4x10(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n ret i4 %tmp9\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x13", "test_body": "define i4 @foo4x13(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n %tmp12 = mul i4 %tmp11, %x\n ret i4 %tmp12\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x8", "test_body": "define i4 @foo4x8(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n ret i4 %tmp7\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x12", "test_body": "define i4 @foo4x12(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n ret i4 %tmp11\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x15", "test_body": "define i4 @foo4x15(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n %tmp12 = mul i4 %tmp11, %x\n %tmp13 = mul i4 %tmp12, %x\n %tmp14 = mul i4 %tmp13, %x\n ret i4 %tmp14\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x9", "test_body": "define i4 @foo4x9(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n ret i4 %tmp8\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo4x14", "test_body": "define i4 @foo4x14(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n %tmp12 = mul i4 %tmp11, %x\n %tmp13 = mul i4 %tmp12, %x\n ret i4 %tmp13\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo3x6", "test_body": "define i3 @foo3x6(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul i3 %tmp3, %x\n %tmp5 = mul i3 %tmp4, %x\n ret i3 %tmp5\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "foo3x7", "test_body": "define i3 @foo3x7(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul i3 %tmp3, %x\n %tmp5 = mul i3 %tmp4, %x\n %tmp6 = mul i3 %tmp5, %x\n ret i3 %tmp6\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "incorrect reassociation at low bitwidth", "body": "here's a function:\r\n```llvm\r\ndefine i3 @f(i3 %0) {\r\n %2 = mul i3 %0, %0\r\n %3 = mul i3 %2, %0\r\n %4 = mul i3 %3, %0\r\n %5 = mul nsw i3 %4, %0\r\n ret i3 %5\r\n}\r\n```\r\n\r\nreassociate seems to be getting it wrong:\r\n```\r\nJohns-MacBook-Pro:reduce regehr$ ~/alive2-regehr/build/alive-tv reduced.ll -passes=reassociate\r\n\r\n----------------------------------------\r\ndefine i3 @f(i3 %#0) {\r\n#1:\r\n %#2 = mul i3 %#0, %#0\r\n %#3 = mul i3 %#2, %#0\r\n %#4 = mul i3 %#3, %#0\r\n %#5 = mul nsw i3 %#4, %#0\r\n ret i3 %#5\r\n}\r\n=>\r\ndefine i3 @f(i3 %#0) {\r\n#1:\r\n %#2 = mul i3 %#0, %#0\r\n %#3 = mul nsw i3 %#2, %#0\r\n ret i3 %#3\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni3 %#0 = #x6 (6, -2)\r\n\r\nSource:\r\ni3 %#2 = #x4 (4, -4)\r\ni3 %#3 = #x0 (0)\r\ni3 %#4 = #x0 (0)\r\ni3 %#5 = #x0 (0)\r\n\r\nTarget:\r\ni3 %#2 = #x4 (4, -4)\r\ni3 %#3 = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\nJohns-MacBook-Pro:reduce regehr$ \r\n```\r\n\r\ncc @nunoplopes ", "author": "regehr", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "dtcxzyw", "body": "Introduced by https://github.com/llvm/llvm-project/commit/d7aeefebd6b049f017711cd7c6ef5f217a17b673.\r\n" } ] }
true
null
121459
https://github.com/llvm/llvm-project/issues/121459
miscompilation
68d265666e708bad1c63b419b6275aaba1a7dcd2
2025-01-02T09:03:32
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a4d92400a6db9566d84cb4b900149e36e117f452", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": [ [ 2782, 2787 ], [ 2838, 2843 ], [ 2847, 2852 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": [ "foldGEPOfPhi" ], "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit a4d92400a6db9566d84cb4b900149e36e117f452 Author: Yingwei Zheng <[email protected]> Date: Fri Jan 3 23:19:57 2025 +0800 [InstCombine] Fix GEPNoWrapFlags propagation in `foldGEPOfPhi` (#121572) Closes https://github.com/llvm/llvm-project/issues/121459. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 934156f04f7f..f63de1f0d410 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2782,6 +2782,7 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN, // loop iteration). if (Op1 == &GEP) return nullptr; + GEPNoWrapFlags NW = Op1->getNoWrapFlags(); int DI = -1; @@ -2838,6 +2839,8 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN, } } } + + NW &= Op2->getNoWrapFlags(); } // If not all GEPs are identical we'll have to create a new PHI node. @@ -2847,6 +2850,8 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN, return nullptr; auto *NewGEP = cast<GetElementPtrInst>(Op1->clone()); + NewGEP->setNoWrapFlags(NW); + if (DI == -1) { // All the GEPs feeding the PHI are identical. Clone one down into our // BB so that it can be merged with the current GEP.
[ { "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": "define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr i64, ptr %p, i64 2\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "gep_of_phi_of_gep_flags2", "test_body": "define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "gep_of_phi_of_gep_flags1", "test_body": "define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr i32, ptr %p, i64 2\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] GEPNoWrapFlags is propagated incorrectly", "body": "Alive2: https://alive2.llvm.org/ce/z/3ME7S7\n```\ndefine ptr @src(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif:\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\n br label %join\n\nelse:\n %gep2 = getelementptr i64, ptr %p, i64 2\n br label %join\n\njoin:\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n```\n```\n\n----------------------------------------\ndefine ptr @src(i1 %c, ptr %p) {\n#0:\n br i1 %c, label %if, label %else\n\nelse:\n %gep2 = gep ptr %p, 8 x i64 2\n br label %join\n\nif:\n %gep1 = gep inbounds ptr %p, 4 x i64 1\n br label %join\n\njoin:\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = gep ptr %phi, 4 x i64 1\n ret ptr %gep\n}\n=>\ndefine ptr @src(i1 %c, ptr %p) {\n#0:\n br i1 %c, label %if, label %else\n\nelse:\n br label %join\n\nif:\n br label %join\n\njoin:\n %#1 = phi i64 [ 4, %if ], [ 16, %else ]\n %#2 = gep inbounds nuw ptr %p, 1 x i64 %#1\n %gep = gep ptr %#2, 1 x i64 4\n ret ptr %gep\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\ni1 %c = #x0 (0)\nptr %p = null\n\nSource:\n >> Jump to %else\nptr %gep2 = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010\n >> Jump to %join\nptr %phi = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010\nptr %gep = pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 1\n\nTarget:\n >> Jump to %else\n >> Jump to %join\ni64 %#1 = #x0000000000000010 (16)\nptr %#2 = poison\nptr %gep = poison\nSource value: pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014\nTarget value: poison\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:instcombine" ], "comments": [] }
true
null
93769
https://github.com/llvm/llvm-project/issues/93769
miscompilation
d517f15e09e49e172387cb6deb76e4ee2d45d0e4
2024-05-30T04:55:57
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "971c49fbf361c22ccf20913f61a58c28b26c4e27", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": [ [ 2857, 2864 ] ], "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": [ "foldFNegIntoConstant" ], "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 971c49fbf361c22ccf20913f61a58c28b26c4e27 Author: SahilPatidar <[email protected]> Date: Thu Jun 12 16:01:43 2025 +0530 [InstCombine] Ensure Safe Handling of Flags in foldFNegIntoConstant (#94148) Fix #93769 alive2: https://alive2.llvm.org/ce/z/MHShQY diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index fc7dd302b27a..f0f709bb16d8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -2857,8 +2857,14 @@ static Instruction *foldFNegIntoConstant(Instruction &I, const DataLayout &DL) { // Fold negation into constant operand. // -(X * C) --> X * (-C) if (match(FNegOp, m_FMul(m_Value(X), m_Constant(C)))) - if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL)) - return BinaryOperator::CreateFMulFMF(X, NegC, &I); + if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL)) { + FastMathFlags FNegF = I.getFastMathFlags(); + FastMathFlags OpF = FNegOp->getFastMathFlags(); + FastMathFlags FMF = FastMathFlags::unionValue(FNegF, OpF) | + FastMathFlags::intersectRewrite(FNegF, OpF); + FMF.setNoInfs(FNegF.noInfs() && OpF.noInfs()); + return BinaryOperator::CreateFMulFMF(X, NegC, FMF); + } // -(X / C) --> X / (-C) if (match(FNegOp, m_FDiv(m_Value(X), m_Constant(C)))) if (Constant *NegC = ConstantFoldUnaryOpOperand(Instruction::FNeg, C, DL))
[ { "file": "llvm/test/Transforms/InstCombine/fneg.ll", "commands": [ "opt < %s -passes=instcombine -S", "opt < %s -passes=instcombine -use-constant-fp-for-fixed-length-splat -S" ], "tests": [ { "test_name": "test_fneg_mul_combine_nsz_ninf_with_vec_const", "test_body": "define <2 x float> @test_fneg_mul_combine_nsz_ninf_with_vec_const(<2 x float> %a) {\n %f1 = fmul nsz <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_reassoc_ninf_with_vec_const1", "test_body": "define <2 x float> @test_fneg_mul_combine_reassoc_ninf_with_vec_const1(<2 x float> %a) {\n %f1 = fmul <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_ninf_mul_with_anyzero", "test_body": "define float @test_fneg_ninf_mul_with_anyzero(float %a) {\n %mul = fmul float %a, 0.000000e+00\n %f = fneg ninf float %mul\n ret float %f\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_contract_ninf_with_vec_const2", "test_body": "define <2 x float> @test_fneg_mul_combine_contract_ninf_with_vec_const2(<2 x float> %a) {\n %f1 = fmul ninf <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fmul_fneg", "test_body": "define float @fmul_fneg(float %x) {\n %m = fmul float %x, 4.200000e+01\n %r = fneg float %m\n ret float %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fmul_fsub_fmf", "test_body": "define float @fmul_fsub_fmf(float %x) {\n %m = fmul float %x, 4.200000e+01\n %r = fsub nsz float -0.000000e+00, %m\n ret float %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_nnan_mul_with_anyzero", "test_body": "define float @test_fneg_nnan_mul_with_anyzero(float %a) {\n %f1 = fmul ninf float %a, 0.000000e+00\n %f2 = fneg nnan float %f1\n ret float %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_nnan_ninf_with_vec_const2", "test_body": "define <2 x float> @test_fneg_mul_combine_nnan_ninf_with_vec_const2(<2 x float> %a) {\n %f1 = fmul ninf <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg nnan ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fsub_ninf_mul_with_anyzero", "test_body": "define float @test_fsub_ninf_mul_with_anyzero(float %a) {\n %f1 = fmul nsz float %a, 0.000000e+00\n %f2 = fsub ninf float -0.000000e+00, %f1\n ret float %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_nsz_mul_with_anyzero", "test_body": "define float @test_fneg_nsz_mul_with_anyzero(float %a) {\n %f1 = fmul ninf float %a, 0.000000e+00\n %f2 = fneg nsz float %f1\n ret float %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_ninf_mul_nnan_with_const", "test_body": "define float @test_fneg_ninf_mul_nnan_with_const(float %a) {\n %f1 = fmul nnan float %a, 0.000000e+00\n %f2 = fneg ninf float %f1\n ret float %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_ninf_nnan_mul_with_vec_const", "test_body": "define <2 x float> @test_fneg_ninf_nnan_mul_with_vec_const(<2 x float> %a) {\n %f1 = fmul <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg nnan ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_reassoc_ninf_with_vec_const3", "test_body": "define <2 x float> @test_fneg_mul_combine_reassoc_ninf_with_vec_const3(<2 x float> %a) {\n %f1 = fmul <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_contract_ninf_with_vec_const1", "test_body": "define <2 x float> @test_fneg_mul_combine_contract_ninf_with_vec_const1(<2 x float> %a) {\n %f1 = fmul <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fmul_fneg_fmf", "test_body": "define float @fmul_fneg_fmf(float %x) {\n %m = fmul float %x, 4.200000e+01\n %r = fneg nsz float %m\n ret float %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_nnan_ninf_with_vec_const", "test_body": "define <2 x float> @test_fneg_mul_combine_nnan_ninf_with_vec_const(<2 x float> %a) {\n %f1 = fmul nnan <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_reassoc_ninf_with_vec_const2", "test_body": "define <2 x float> @test_fneg_mul_combine_reassoc_ninf_with_vec_const2(<2 x float> %a) {\n %f1 = fmul ninf <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_mul_combine_contract_ninf_with_vec_const3", "test_body": "define <2 x float> @test_fneg_mul_combine_contract_ninf_with_vec_const3(<2 x float> %a) {\n %f1 = fmul <2 x float> %a, <float 0.000000e+00, float -0.000000e+00>\n %f2 = fneg ninf <2 x float> %f1\n ret <2 x float> %f2\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fneg_ninf_mul_nsz_with_const", "test_body": "define float @test_fneg_ninf_mul_nsz_with_const(float %a) {\n %f1 = fmul nsz float %a, 0.000000e+00\n %f2 = fneg ninf float %f1\n ret float %f2\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "foldFNegIntoConstant incorrectly preserves fast math flags for 0 constants", "body": "> https://alive2.llvm.org/ce/z/MHShQY longer version\r\n\r\n_Originally posted by @arsenm in https://github.com/llvm/llvm-project/pull/92512#discussion_r1619895371_\r\n\r\n\r\nSome of the combines in foldFNegIntoConstant are unsafely taking the flags directly from the original fneg instruction, when the preservation logic requires dropping ninf in some cases. ", "author": "arsenm", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [ { "author": "SahilPatidar", "body": "@arsenm, could we use the same logic you shared in #92512 for dropping `ninf`?\r\n```cpp\r\n FastMathFlags FMF = match(C, m_AnyZeroFP())? I.getFastMathFlags() &\r\n cast<FPMathOperator>(I.getOperand(0))->getFastMathFlags():\r\n I.getFastMathFlags();\r\n```\r\nHowever, this logic will also drop `nnan` and other flags. Should we check specifically for ninf instead?" }, { "author": "arsenm", "body": "> However, this logic will also drop `nnan` and other flags. Should we check specifically for ninf instead?\r\n\r\nThat will be conservatively correct, but I think this can do better. For example, nnan on the fneg should be sufficient to preserve nnan on the final result, same with nsz " } ] }
true
null
135912
https://github.com/llvm/llvm-project/issues/135912
crash
d3153ad66c539ad146062b6e65741901e5b5e1cc
2025-04-16T05:32:48
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "af28c9c65a23806a09d7929792df5ed2e9bdf946", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7479, 7486 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::reorderBottomToTop" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit af28c9c65a23806a09d7929792df5ed2e9bdf946 Author: Alexey Bataev <[email protected]> Date: Wed Apr 16 06:20:34 2025 -0700 [SLP]Do not reorder split node operand with reuses, if not possible Need to check if the operand node of the split vectorize node has reuses and check if it is possible to build the order for this node to reorder it correctly. Fixes #135912 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index f9acc276f37f..f97386159d02 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7479,8 +7479,8 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) { for (const auto &P : Data.first->CombinedEntriesWithIndices) { TreeEntry &OpTE = *VectorizableTree[P.first].get(); OrdersType Order = OpTE.ReorderIndices; - if (Order.empty()) { - if (!OpTE.isGather()) + if (Order.empty() || !OpTE.ReuseShuffleIndices.empty()) { + if (!OpTE.isGather() && OpTE.ReuseShuffleIndices.empty()) continue; const auto BestOrder = getReorderingData(OpTE, /*TopToBottom=*/false, IgnoreReorder);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/split-vector-operand-with-reuses.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(ptr %p) {\n;\nentry:\n %arrayidx7.us.i.841 = getelementptr i8, ptr %p, i64 36\n %arrayidx7.us.i.946 = getelementptr i8, ptr %p, i64 40\n %arrayidx7.us.i.1051 = getelementptr i8, ptr %p, i64 44\n %arrayidx7.us.i.1156 = getelementptr i8, ptr %p, i64 48\n %arrayidx7.us.i.1261 = getelementptr i8, ptr %p, i64 52\n %arrayidx7.us.i.1366 = getelementptr i8, ptr %p, i64 56\n %arrayidx7.us.i.1471 = getelementptr i8, ptr %p, i64 60\n %arrayidx7.us.i.1576 = getelementptr i8, ptr %p, i64 64\n %add8.us.i.1.4 = add i32 0, 0\n %rem.us.i.1.4 = srem i32 %add8.us.i.1.4, 1\n %add8.us.i.1.5 = add i32 0, 0\n %rem.us.i.1.5 = srem i32 %add8.us.i.1.5, 1\n %invariant.op91 = add i32 %rem.us.i.1.4, %rem.us.i.1.5\n %add8.us.i.1.6 = add i32 0, 0\n %rem.us.i.1.6 = srem i32 %add8.us.i.1.6, 1\n %invariant.op92 = add i32 %invariant.op91, %rem.us.i.1.6\n %0 = load i32, ptr %arrayidx7.us.i.841, align 4\n %1 = load i32, ptr %arrayidx7.us.i.946, align 4\n %2 = load i32, ptr %arrayidx7.us.i.1051, align 4\n %3 = load i32, ptr %arrayidx7.us.i.1156, align 4\n %4 = load i32, ptr %arrayidx7.us.i.1261, align 4\n %5 = load i32, ptr %arrayidx7.us.i.1366, align 4\n %add8.us.i.7.6 = or i32 %5, 0\n %rem.us.i.7.6 = srem i32 %add8.us.i.7.6, 1\n %6 = load i32, ptr %arrayidx7.us.i.1471, align 4\n %add8.us.i.7.7 = or i32 %6, 0\n %rem.us.i.7.7 = srem i32 %add8.us.i.7.7, 1\n %invariant.op165 = add i32 %rem.us.i.7.6, %rem.us.i.7.7\n %7 = load i32, ptr %arrayidx7.us.i.1576, align 4\n %add8.us.i.7.8 = or i32 %7, 0\n %rem.us.i.7.8 = srem i32 %add8.us.i.7.8, 1\n %invariant.op166 = add i32 %invariant.op165, %rem.us.i.7.8\n %add8.us.i.8 = or i32 %0, 0\n %rem.us.i.8 = srem i32 %add8.us.i.8, 1\n %invariant.op167 = add i32 %invariant.op166, %rem.us.i.8\n %add8.us.i.8.1 = or i32 %1, 0\n %rem.us.i.8.1 = srem i32 %add8.us.i.8.1, 1\n %invariant.op168 = add i32 %invariant.op167, %rem.us.i.8.1\n %add8.us.i.8.2 = or i32 %2, 0\n %rem.us.i.8.2 = srem i32 %add8.us.i.8.2, 1\n %invariant.op169 = add i32 %invariant.op168, %rem.us.i.8.2\n %add8.us.i.8.3 = or i32 %3, 0\n %rem.us.i.8.3 = srem i32 %add8.us.i.8.3, 1\n %invariant.op170 = add i32 %invariant.op169, %rem.us.i.8.3\n %add8.us.i.8.4 = or i32 %4, 0\n %rem.us.i.8.4 = srem i32 %add8.us.i.8.4, 1\n %invariant.op171 = add i32 %invariant.op170, %rem.us.i.8.4\n %add8.us.i.8.5 = or i32 %5, 0\n %rem.us.i.8.5 = srem i32 %add8.us.i.8.5, 1\n %invariant.op172 = add i32 %invariant.op171, %rem.us.i.8.5\n %add8.us.i.8.6 = or i32 %6, 0\n %rem.us.i.8.6 = srem i32 %add8.us.i.8.6, 0\n %invariant.op173 = add i32 %invariant.op172, %rem.us.i.8.6\n %add8.us.i.8.7 = or i32 %7, 0\n %rem.us.i.8.7 = srem i32 %add8.us.i.8.7, 0\n %invariant.op174 = add i32 %invariant.op173, %rem.us.i.8.7\n %invariant.op181 = add i32 %invariant.op174, 0\n %invariant.op182 = add i32 %invariant.op181, 0\n %invariant.op183 = add i32 %invariant.op182, 0\n %invariant.op184 = add i32 %invariant.op183, 0\n %invariant.op185 = add i32 %invariant.op184, 0\n %invariant.op186 = add i32 %invariant.op185, 0\n %invariant.op187 = add i32 %invariant.op186, 0\n %invariant.op188 = add i32 %invariant.op187, 0\n %add8.us.i.11.1 = or i32 %4, 0\n %rem.us.i.11.1 = srem i32 %add8.us.i.11.1, 1\n %invariant.op189 = add i32 %invariant.op188, %rem.us.i.11.1\n %add8.us.i.11.2 = add i32 0, 0\n %rem.us.i.11.2 = srem i32 %add8.us.i.11.2, 1\n %invariant.op190 = add i32 %invariant.op189, %rem.us.i.11.2\n %add8.us.i.11.3 = add i32 %6, %2\n %rem.us.i.11.3 = srem i32 %add8.us.i.11.3, 1\n %invariant.op191 = add i32 %invariant.op190, %rem.us.i.11.3\n %add8.us.i.11.4 = add i32 %7, %2\n %rem.us.i.11.4 = srem i32 %add8.us.i.11.4, 1\n %invariant.op192 = add i32 %invariant.op191, %rem.us.i.11.4\n %8 = load i32, ptr %p, align 4\n %add8.us.i.12 = add i32 %4, %8\n %rem.us.i.12 = srem i32 %add8.us.i.12, 1\n %invariant.op193 = add i32 %invariant.op192, %rem.us.i.12\n %add8.us.i.12.1 = add i32 %5, %8\n %rem.us.i.12.1 = srem i32 %add8.us.i.12.1, 1\n %invariant.op194 = add i32 %invariant.op193, %rem.us.i.12.1\n %add8.us.i.12.2 = add i32 0, 0\n %rem.us.i.12.2 = srem i32 %add8.us.i.12.2, 1\n %invariant.op195 = add i32 %invariant.op194, %rem.us.i.12.2\n %add8.us.i.12.3 = add i32 0, 0\n %rem.us.i.12.3 = srem i32 %add8.us.i.12.3, 1\n %invariant.op196 = add i32 %invariant.op195, %rem.us.i.12.3\n %add8.us.i.13 = add i32 0, 0\n %rem.us.i.13 = srem i32 %add8.us.i.13, 0\n %invariant.op197 = add i32 %invariant.op196, %rem.us.i.13\n %add8.us.i.13.1 = add i32 0, 0\n %rem.us.i.13.1 = srem i32 %add8.us.i.13.1, 0\n %invariant.op198 = add i32 %invariant.op197, %rem.us.i.13.1\n %add8.us.i.13.2 = add i32 0, 0\n %rem.us.i.13.2 = srem i32 %add8.us.i.13.2, 1\n %invariant.op199 = add i32 %invariant.op198, %rem.us.i.13.2\n %add8.us.i.14 = add i32 0, 0\n %rem.us.i.14 = srem i32 %add8.us.i.14, 1\n %invariant.op200 = add i32 %invariant.op199, %rem.us.i.14\n %add8.us.i.14.1 = add i32 0, 0\n %rem.us.i.14.1 = srem i32 %add8.us.i.14.1, 1\n %invariant.op201 = add i32 %invariant.op200, %rem.us.i.14.1\n %add8.us.i.15 = add i32 0, 0\n %rem.us.i.15 = srem i32 %add8.us.i.15, 1\n %invariant.op202 = add i32 %invariant.op201, %rem.us.i.15\n br label %for.cond1.preheader.us.i\n\nfor.cond1.preheader.us.i:\n %a.promoted253537.us.i = phi i32 [ %add9.us.i.15.reass, %for.cond1.preheader.us.i ], [ 0, %entry ]\n %add9.us.i.15.reass = add i32 %invariant.op92, %invariant.op202\n br label %for.cond1.preheader.us.i\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Crash at -O3: Assertion `OpTE1.isSame...\"' failed.", "body": "This code crashes at `-O3`:\n\n```c\nint a, b, c, d;\nvoid *malloc();\nvoid e(int f) {\n int *g = malloc(sizeof(int));\n for (; d; d++) {\n b = 0;\n for (; b < f - 1; b++) {\n c = b + 1;\n for (; c < f; c++)\n a += (g[b] + g[c]) % 2;\n }\n }\n}\nvoid h() { e(1 + 16); }\n```\n\nCompiler Explorer: https://godbolt.org/z/h3h3qe174\n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:17358: llvm::Value* llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*): Assertion `OpTE1.isSame( ArrayRef(E->Scalars).take_front(OpTE1.getVectorFactor())) && \"Expected same first part of scalars.\"' failed.\n```\n\nBacktrace:\n\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"slp-vectorizer\" on function \"h\"\n #0 0x0000000003ee5798 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ee5798)\n #1 0x0000000003ee3424 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ee3424)\n #2 0x0000000003e27f68 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007c46db642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007c46db6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007c46db642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007c46db6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007c46db62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007c46db639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000000005b118bd llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b118bd)\n#10 0x0000000005b0b18e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b0b18e)\n#11 0x0000000005b0c98d llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b0c98d)\n#12 0x0000000005b0acc2 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b0acc2)\n#13 0x0000000005b0c98d llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b0c98d)\n#14 0x0000000005b2fdc4 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*, llvm::ArrayRef<std::tuple<llvm::Value*, unsigned int, bool>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b2fdc4)\n#15 0x0000000005b449ff (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#16 0x0000000005b476cf llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b476cf)\n#17 0x0000000005b4bee0 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b4bee0)\n#18 0x0000000005b50846 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b50846)\n#19 0x0000000005b5749e 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\n#20 0x0000000005b5805b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5b5805b)\n#21 0x00000000055bd0ee 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/clang+0x55bd0ee)\n#22 0x00000000038884b0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x38884b0)\n#23 0x00000000011f0b2e 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/clang+0x11f0b2e)\n#24 0x0000000003886d83 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3886d83)\n#25 0x00000000011efa6e 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/clang+0x11efa6e)\n#26 0x0000000003886790 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3886790)\n#27 0x0000000004198802 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#28 0x000000000419bfab clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x419bfab)\n#29 0x000000000487fea0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x487fea0)\n#30 0x00000000065342ec clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x65342ec)\n#31 0x0000000004880288 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4880288)\n#32 0x0000000004b72995 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b72995)\n#33 0x0000000004af188e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4af188e)\n#34 0x0000000004c6226e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c6226e)\n#35 0x0000000000d9ee9f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9ee9f)\n#36 0x0000000000d965aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#37 0x00000000048e6769 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#38 0x0000000003e28404 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e28404)\n#39 0x00000000048e6d7f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#40 0x00000000048a91dd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48a91dd)\n#41 0x00000000048aa26e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48aa26e)\n#42 0x00000000048b20c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48b20c5)\n#43 0x0000000000d9bbe8 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9bbe8)\n#44 0x0000000000c265e4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc265e4)\n#45 0x00007c46db629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#46 0x00007c46db629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#47 0x0000000000d96055 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd96055)\n```\n\n", "author": "cardigan1008", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "cardigan1008", "body": "This issue seems to be related to https://github.com/llvm/llvm-project/issues/130972. cc @alexey-bataev " }, { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/6b31EPqqr\n" } ] }
true
null
123639
https://github.com/llvm/llvm-project/issues/123639
miscompilation
5e4c34a9b67d9ce15d14f83bcea96ccb69de1eae
2025-01-20T16:05:11
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "7d01a8f2b9ac28ffe73bef4b513d383d3edf34b5", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13205, 13213 ], [ 14497, 14503 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledSingleRegisterEntry", "add" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 7d01a8f2b9ac28ffe73bef4b513d383d3edf34b5 Author: Alexey Bataev <[email protected]> Date: Mon Jan 20 14:22:20 2025 -0800 [SLP]Fix vector factor for repeated node for bv When adding a node vector, when it is used already in the shuffle for buildvector, need to calculate vector factor from all vector, not only this single vector, to avoid incorrect result. Also, need to increase stability of the reused entries detection to avoid mismatch in cost estimation/codegen. Fixes #123639 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index fc3afed391a0..ad4855d90874 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13205,9 +13205,12 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( VTE = *MIt; } } - Instruction &LastBundleInst = getLastInstructionInBundle(VTE); - if (&LastBundleInst == TEInsertPt || !CheckOrdering(&LastBundleInst)) - continue; + if (none_of(TE->CombinedEntriesWithIndices, + [&](const auto &P) { return P.first == VTE->Idx; })) { + Instruction &LastBundleInst = getLastInstructionInBundle(VTE); + if (&LastBundleInst == TEInsertPt || !CheckOrdering(&LastBundleInst)) + continue; + } VToTEs.insert(VTE); } if (VToTEs.empty()) @@ -14497,7 +14500,9 @@ public: break; } } - int VF = getVF(V1); + unsigned VF = 0; + for (Value *V : InVectors) + VF = std::max(VF, getVF(V)); for (unsigned Idx = 0, Sz = CommonMask.size(); Idx < Sz; ++Idx) if (Mask[Idx] != PoisonMaskElem && CommonMask[Idx] == PoisonMaskElem) CommonMask[Idx] = Mask[Idx] + (It == InVectors.begin() ? 0 : VF);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/multi-node-reuse-in-bv.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @main() {\nentry:\n %.neg15 = sub i32 0, 0\n %0 = trunc i64 1 to i32\n %.neg.1 = sub i32 0, 0\n %.neg15.1 = sub i32 0, %0\n %.neg16.1 = add i32 %.neg.1, %.neg15.1\n %1 = add i32 %.neg16.1, %.neg15\n %2 = trunc i64 0 to i32\n %.neg.2 = sub i32 0, %0\n %.neg15.2 = sub i32 0, %2\n %.neg16.2 = add i32 %.neg.2, %.neg15.2\n %3 = add i32 %.neg16.2, %1\n %4 = trunc i64 0 to i32\n %.neg.3 = sub i32 0, %2\n %.neg15.3 = sub i32 0, %4\n %.neg16.3 = add i32 %.neg.3, %.neg15.3\n %5 = add i32 %.neg16.3, %3\n %6 = trunc i64 0 to i32\n %.neg.4 = sub i32 0, %4\n %.neg15.4 = sub i32 0, %6\n %.neg16.4 = add i32 %.neg.4, %.neg15.4\n %7 = add i32 %.neg16.4, %5\n %.neg.5 = sub i32 0, %6\n %.neg15.5 = sub i32 0, 0\n %.neg16.5 = add i32 %.neg.5, %.neg15.5\n %8 = add i32 %.neg16.5, %7\n %.neg15.6 = sub i32 0, 0\n %.neg16.6 = add i32 0, %.neg15.6\n %9 = add i32 %.neg16.6, %8\n %.neg.7 = sub i32 0, 0\n %.neg15.7 = sub i32 0, 0\n %.neg16.7 = add i32 %.neg.7, %.neg15.7\n %10 = add i32 %.neg16.7, %9\n %11 = trunc i64 0 to i32\n %.neg.8 = sub i32 0, 0\n %.neg15.8 = sub i32 0, %11\n %.neg16.8 = add i32 %.neg.8, %.neg15.8\n %12 = add i32 %.neg16.8, %10\n %13 = trunc i64 0 to i32\n %.neg.9 = sub i32 0, %11\n %.neg15.9 = sub i32 0, %13\n %.neg16.9 = add i32 %.neg.9, %.neg15.9\n %14 = add i32 %.neg16.9, %12\n %15 = trunc i64 0 to i32\n %.neg.10 = sub i32 0, %13\n %.neg15.10 = sub i32 0, %15\n %.neg16.10 = add i32 %.neg.10, %.neg15.10\n %16 = add i32 %.neg16.10, %14\n %17 = trunc i64 0 to i32\n %.neg.11 = sub i32 0, %15\n %.neg15.11 = sub i32 0, %17\n %.neg16.11 = add i32 %.neg.11, %.neg15.11\n %18 = add i32 %.neg16.11, %16\n %19 = trunc i64 0 to i32\n %.neg.12 = sub i32 0, %17\n %.neg15.12 = sub i32 0, %19\n %.neg16.12 = add i32 %.neg.12, %.neg15.12\n %20 = add i32 %.neg16.12, %18\n %.neg.13 = sub i32 0, %19\n %.neg15.13 = sub i32 0, 0\n %.neg16.13 = add i32 %.neg.13, %.neg15.13\n %21 = add i32 %.neg16.13, %20\n %.neg.14 = sub i32 0, 0\n %.neg15.14 = sub i32 0, 0\n %.neg16.14 = add i32 %.neg.14, %.neg15.14\n %22 = add i32 %.neg16.14, %21\n %.neg.15 = sub i32 0, 0\n %.neg15.15 = sub i32 0, 0\n %.neg16.15 = add i32 %.neg.15, %.neg15.15\n %23 = add i32 %.neg16.15, %22\n %.neg.16 = sub i32 0, 0\n %.neg15.16 = sub i32 0, 0\n %.neg16.16 = add i32 %.neg.16, %.neg15.16\n %24 = add i32 %.neg16.16, %23\n %res = xor i32 %24, -2\n ret i32 %res\n}\n", "additional_args": null, "lli_expected_out": "" } ] } ]
{ "title": "SLP Vectorizer miscompilation", "body": "During our local testing, we identified a miscompilation where the SLP Vectorizer appears to be the cause. Here is the reproducer we managed to prepare:\nhttps://godbolt.org/z/9nePcq7Go\n\nThe issue can be demonstrated using the `lli` tool. Unfortunately, I cannot use alive2 due to unknown libcall errors, such as @llvm.vector.insert.v32i32.v16i32 not being recognized by alive2\n\n```\n$ bin/opt -passes=slp-vectorizer -mattr=+avx2 src.ll -S > tgt.ll\n$ bin/lli src.ll\nResult: -256\n$ bin/lli tgt.ll\nResult: -272\n```\n\nThe pseudocode represented by the IR is\n```\nt = 0\nfor (i = 0; i < 16; i++) {\n s -= (t + i)\n t = i\n}\n```\n```\ns -= (1 + 0) + (2 + 1) + (3 + 2) + (4 + 3) + ... + (14 + 15) + (15 + 16)\ns = -256\n```\nThis indicates that the SLP Vectorizer pass produces incorrect IR.\n\nThe issue became reproducible after patch `[SLP] Match poison as instruction with the same opcode` made by @alexey-bataev \nhttps://github.com/llvm/llvm-project/commit/b8703369daf777706196ff914c0376c27adde3cf\n\nI'll provide more details on how the patch affects the issue as soon as I receive them.", "author": "aleks-tmb", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [ { "author": "alexey-bataev", "body": "No related directly to this patch, reveals the bug that can be triggered even without patch. I reduced the reproducer, will commit fix soon" } ] }
true
null
116249
https://github.com/llvm/llvm-project/issues/116249
miscompilation
c1f6cb74634509d0e4204dadd46566185fa33e2b
2024-11-14T15:57:03
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "40a647fc7dc6048c92e2d580b61f5feca0785980", "components": [ "IndVarSimplify" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": [ [ 1530, 1535 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": [ "IndVarSimplify::canonicalizeExitCondition" ], "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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 40a647fc7dc6048c92e2d580b61f5feca0785980 Author: Yingwei Zheng <[email protected]> Date: Fri Nov 15 09:15:37 2024 +0800 [IndVarSimplify] Drop samesign flags after narrowing compares (#116263) Samesign flag cannot be preserved after narrowing the compare since the position of the sign bit is changed. Closes https://github.com/llvm/llvm-project/issues/116249. diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 2b2d516a7079..8a3e0bc3eb97 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -1530,6 +1530,8 @@ bool IndVarSimplify::canonicalizeExitCondition(Loop *L) { L->getLoopPreheader()->getTerminator()->getIterator()); ICmp->setOperand(Swapped ? 1 : 0, LHSOp); ICmp->setOperand(Swapped ? 0 : 1, NewRHS); + // Samesign flag cannot be preserved after narrowing the compare. + ICmp->setSameSign(false); if (LHS->use_empty()) DeadInsts.push_back(LHS); };
[ { "file": "llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll", "commands": [ "opt -passes=indvars -S < %s -indvars-predicate-loops=0" ], "tests": [ { "test_name": "test_drop_icmp_samesign", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i8 @test_drop_icmp_samesign(i1 %cond, i32 range(i32 0, 32) %x) {\nentry:\n br i1 %cond, label %for.body, label %else\n\nelse: ; preds = %entry\n %call1 = call i8 @callee()\n br label %exit\n\nfor.body: ; preds = %for.body, %entry\n %call2 = call i8 @callee()\n %ext = zext i8 %call2 to i32\n %cond2 = icmp samesign ugt i32 %x, %ext\n br i1 %cond2, label %for.body, label %exit\n\nexit: ; preds = %for.body, %else\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\n ret i8 %res\n}\n\ndeclare i8 @callee()\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[IndVarSimplify] samesign flag should be dropped after narrowing", "body": "Found with https://github.com/dtcxzyw/llvm-ub-aware-interpreter.\r\nReproducer: https://alive2.llvm.org/ce/z/fcnvLv\r\n```\r\n; bin/opt -passes=indvars test.ll -S\r\ndefine i8 @test(i1 %cond, i32 range(i32 0, 32) %x) {\r\nentry:\r\n br i1 %cond, label %for.body, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %ext = zext i8 %call2 to i32\r\n %cond2 = icmp samesign ugt i32 %x, %ext\r\n br i1 %cond2, label %for.body, label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\r\n ret i8 %res\r\n}\r\n```\r\n```\r\n\r\n----------------------------------------\r\ndeclare i8 @callee()\r\n\r\ndefine i8 @test(i1 %cond, i32 %x) {\r\ninit:\r\n %#range_0_%x = !range i32 %x, i32 0, i32 32\r\n br label %entry\r\n\r\nentry:\r\n br i1 %cond, label %for.body, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %ext = zext i8 %call2 to i32\r\n %cond2 = icmp samesign ugt i32 %#range_0_%x, %ext\r\n br i1 %cond2, label %for.body, label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\r\n ret i8 %res\r\n}\r\n=>\r\ndeclare i8 @callee()\r\n\r\ndefine i8 @test(i1 %cond, i32 %x) {\r\ninit:\r\n %#range_0_%x = !range i32 %x, i32 0, i32 32\r\n br label %entry\r\n\r\nentry:\r\n br i1 %cond, label %for.body.preheader, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body.preheader:\r\n %#0 = trunc i32 %#range_0_%x to i8\r\n br label %for.body\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %cond2 = icmp samesign ugt i8 %#0, %call2\r\n br i1 %cond2, label %for.body, label %exit.loopexit\r\n\r\nexit.loopexit:\r\n %call2.lcssa = phi i8 [ %call2, %for.body ]\r\n br label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2.lcssa, %exit.loopexit ]\r\n ret i8 %res\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni1 %cond = #x1 (1)\r\ni32 %x = #x00000000 (0)\r\n\r\nSource:\r\ni32 %#range_0_%x = #x00000000 (0)\r\n >> Jump to %entry\r\n >> Jump to %for.body\r\ni8 %call2 = #x80 (128, -128)\r\ni32 %ext = #x00000080 (128)\r\ni1 %cond2 = #x0 (0)\r\n >> Jump to %exit\r\ni8 %res = #x80 (128, -128)\r\n\r\nSOURCE MEMORY STATE\r\n===================\r\nNON-LOCAL BLOCKS:\r\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\r\nBlock 1 >\tsize: 4\talign: 1\talloc type: 0\talive: true\taddress: 1\r\n\r\nTarget:\r\ni32 %#range_0_%x = #x00000000 (0)\r\n >> Jump to %entry\r\n >> Jump to %for.body.preheader\r\ni8 %#0 = #x00 (0)\r\n >> Jump to %for.body\r\ni8 %call2 = #x80 (128, -128)\r\ni1 %cond2 = poison\r\nUB triggered on br\r\n\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [] }
true
null
112076
https://github.com/llvm/llvm-project/issues/112076
miscompilation
8c56dd3040f295874e3d5742b5dfc109adf1f728
2024-10-12T03:31:00
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "2c094ac761912eea0d7e8ccb140bc647b5378bdf", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 3466, 3472 ], [ 3501, 3506 ], [ 4148, 4154 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "InstCombinerImpl::visitSelectInst", "foldBitCeil" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 2c094ac761912eea0d7e8ccb140bc647b5378bdf Author: Yingwei Zheng <[email protected]> Date: Wed Nov 20 21:15:26 2024 +0800 [InstCombine] Drop range attributes in `foldBitCeil` (#116641) Closes https://github.com/llvm/llvm-project/issues/112076 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 28dbca027037..2526ce7704ab 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3466,7 +3466,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, // Note that the select is optimized away while the shift count is masked with // 31. We handle some variations of the input operand like std::bit_ceil(X + // 1). -static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) { +static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder, + InstCombinerImpl &IC) { Type *SelType = SI.getType(); unsigned BitWidth = SelType->getScalarSizeInBits(); @@ -3501,6 +3502,10 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) { // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth // is an integer constant. Masking with BitWidth-1 comes free on some // hardware as part of the shift instruction. + + // Drop range attributes and re-infer them in the next iteration. + cast<Instruction>(Ctlz)->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(cast<Instruction>(Ctlz)); Value *Neg = Builder.CreateNeg(Ctlz); Value *Masked = Builder.CreateAnd(Neg, ConstantInt::get(SelType, BitWidth - 1)); @@ -4148,7 +4153,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { if (sinkNotIntoOtherHandOfLogicalOp(SI)) return &SI; - if (Instruction *I = foldBitCeil(SI, Builder)) + if (Instruction *I = foldBitCeil(SI, Builder, *this)) return I; if (Instruction *I = foldSelectToCmp(SI))
[ { "file": "llvm/test/Transforms/InstCombine/bit_ceil.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_drop_range_attr", "test_body": "define i32 @test_drop_range_attr(i32 %x) {\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\n %sub = sub i32 32, %ctlz\n %shl = shl i32 1, %sub\n %dec = add i32 %x, -1\n %ult = icmp ult i32 %dec, -2\n %sel = select i1 %ult, i32 %shl, i32 1\n ret i32 %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr91691_keep_nsw", "test_body": "define i32 @pr91691_keep_nsw(i32 %0) {\n %2 = sub nsw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `range` attribute should be dropped in `foldBitCeil`", "body": "Reproducer: https://alive2.llvm.org/ce/z/NQTmkh (Please use latest alive2 with https://github.com/AliveToolkit/alive2/pull/1097)\r\n```\r\ndefine i32 @src(i32 %x) {\r\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %sub = sub i32 32, %ctlz\r\n %shl = shl i32 1, %sub\r\n %dec = add i32 %x, -1\r\n %ult = icmp ult i32 %dec, -2\r\n %sel = select i1 %ult, i32 %shl, i32 1\r\n ret i32 %sel\r\n}\r\n\r\ndefine i32 @tgt(i32 %x) {\r\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %1 = sub nsw i32 0, %ctlz\r\n %2 = and i32 %1, 31\r\n %sel = shl nuw i32 1, %2\r\n ret i32 %sel\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i32 @src(i32 %x) {\r\n#0:\r\n %ctlz = ctlz i32 %x, 0\r\n %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33\r\n %sub = sub i32 32, %#range_0_%ctlz\r\n %shl = shl i32 1, %sub\r\n %dec = add i32 %x, 4294967295\r\n %ult = icmp ult i32 %dec, 4294967294\r\n %sel = select i1 %ult, i32 %shl, i32 1\r\n ret i32 %sel\r\n}\r\n=>\r\ndefine i32 @tgt(i32 %x) {\r\n#0:\r\n %ctlz = ctlz i32 %x, 0\r\n %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33\r\n %#1 = sub nsw i32 0, %#range_0_%ctlz\r\n %#2 = and i32 %#1, 31\r\n %sel = shl nuw i32 1, %#2\r\n ret i32 %sel\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #xffffffff (4294967295, -1)\r\n\r\nSource:\r\ni32 %ctlz = #x00000000 (0)\r\ni32 %#range_0_%ctlz = poison\r\ni32 %sub = poison\r\ni32 %shl = poison\r\ni32 %dec = #xfffffffe (4294967294, -2)\r\ni1 %ult = #x0 (0)\r\ni32 %sel = #x00000001 (1)\r\n\r\nTarget:\r\ni32 %ctlz = #x00000000 (0)\r\ni32 %#range_0_%ctlz = poison\r\ni32 %#1 = poison\r\ni32 %#2 = poison\r\ni32 %sel = poison\r\nSource value: #x00000001 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
140481
https://github.com/llvm/llvm-project/issues/140481
miscompilation
f72a8ee489368dd20c1392b122b0736aa7c8ada1
2025-05-18T21:41:49
[ "llvm/test/Transforms/ConstraintElimination" ]
{ "fix_commit": "287294d54d7a806e70b0061cf5ccc1fc2bd03eea", "components": [ "ConstraintElimination" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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": [ [ 64, 83 ], [ 366, 391 ], [ 467, 474 ], [ 488, 498 ], [ 533, 553 ], [ 557, 564 ], [ 593, 600 ], [ 603, 609 ], [ 611, 643 ] ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ "Decomposition", "addWithOverflow", "decomposeGEP", "getContextInstForUse", "multiplyWithOverflow", "sub" ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 287294d54d7a806e70b0061cf5ccc1fc2bd03eea Author: Yingwei Zheng <[email protected]> Date: Thu May 22 11:31:04 2025 +0800 [ConstraintElim] Do not allow overflows in `Decomposition` (#140541) Consider the following case: ``` define i1 @pr140481(i32 %x) { %cond = icmp slt i32 %x, 0 call void @llvm.assume(i1 %cond) %add = add nsw i32 %x, 5001000 %mul1 = mul nsw i32 %add, -5001000 %mul2 = mul nsw i32 %mul1, 5001000 %cmp2 = icmp sgt i32 %mul2, 0 ret i1 %cmp2 } ``` Before this patch, `decompose(%mul2)` returns `-25010001000000 * %x + 4052193514966861312`. Therefore, `%cmp2` will be simplified into true because `%x s< 0 && -25010001000000 * %x + 4052193514966861312 s<= 0` is unsat. It is incorrect since the offset `-25010001000000 * 5001000 -> 4052193514966861312` signed wraps. This patch treats a decomposition as invalid if overflows occur when computing coefficients. Closes https://github.com/llvm/llvm-project/issues/140481. diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index da5be383df15..cbad5dd35768 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -64,20 +64,6 @@ static cl::opt<bool> DumpReproducers( static int64_t MaxConstraintValue = std::numeric_limits<int64_t>::max(); static int64_t MinSignedConstraintValue = std::numeric_limits<int64_t>::min(); -// A helper to multiply 2 signed integers where overflowing is allowed. -static int64_t multiplyWithOverflow(int64_t A, int64_t B) { - int64_t Result; - MulOverflow(A, B, Result); - return Result; -} - -// A helper to add 2 signed integers where overflowing is allowed. -static int64_t addWithOverflow(int64_t A, int64_t B) { - int64_t Result; - AddOverflow(A, B, Result); - return Result; -} - static Instruction *getContextInstForUse(Use &U) { Instruction *UserI = cast<Instruction>(U.getUser()); if (auto *Phi = dyn_cast<PHINode>(UserI)) @@ -366,26 +352,42 @@ struct Decomposition { Decomposition(int64_t Offset, ArrayRef<DecompEntry> Vars) : Offset(Offset), Vars(Vars) {} - void add(int64_t OtherOffset) { - Offset = addWithOverflow(Offset, OtherOffset); + /// Add \p OtherOffset and return true if the operation overflows, i.e. the + /// new decomposition is invalid. + [[nodiscard]] bool add(int64_t OtherOffset) { + return AddOverflow(Offset, OtherOffset, Offset); } - void add(const Decomposition &Other) { - add(Other.Offset); + /// Add \p Other and return true if the operation overflows, i.e. the new + /// decomposition is invalid. + [[nodiscard]] bool add(const Decomposition &Other) { + if (add(Other.Offset)) + return true; append_range(Vars, Other.Vars); + return false; } - void sub(const Decomposition &Other) { + /// Subtract \p Other and return true if the operation overflows, i.e. the new + /// decomposition is invalid. + [[nodiscard]] bool sub(const Decomposition &Other) { Decomposition Tmp = Other; - Tmp.mul(-1); - add(Tmp.Offset); + if (Tmp.mul(-1)) + return true; + if (add(Tmp.Offset)) + return true; append_range(Vars, Tmp.Vars); + return false; } - void mul(int64_t Factor) { - Offset = multiplyWithOverflow(Offset, Factor); + /// Multiply all coefficients by \p Factor and return true if the operation + /// overflows, i.e. the new decomposition is invalid. + [[nodiscard]] bool mul(int64_t Factor) { + if (MulOverflow(Offset, Factor, Offset)) + return true; for (auto &Var : Vars) - Var.Coefficient = multiplyWithOverflow(Var.Coefficient, Factor); + if (MulOverflow(Var.Coefficient, Factor, Var.Coefficient)) + return true; + return false; } }; @@ -467,8 +469,10 @@ static Decomposition decomposeGEP(GEPOperator &GEP, Decomposition Result(ConstantOffset.getSExtValue(), DecompEntry(1, BasePtr)); for (auto [Index, Scale] : VariableOffsets) { auto IdxResult = decompose(Index, Preconditions, IsSigned, DL); - IdxResult.mul(Scale.getSExtValue()); - Result.add(IdxResult); + if (IdxResult.mul(Scale.getSExtValue())) + return &GEP; + if (Result.add(IdxResult)) + return &GEP; if (!NW.hasNoUnsignedWrap()) { // Try to prove nuw from nusw and nneg. @@ -488,11 +492,13 @@ static Decomposition decompose(Value *V, SmallVectorImpl<ConditionTy> &Preconditions, bool IsSigned, const DataLayout &DL) { - auto MergeResults = [&Preconditions, IsSigned, &DL](Value *A, Value *B, - bool IsSignedB) { + auto MergeResults = [&Preconditions, IsSigned, + &DL](Value *A, Value *B, + bool IsSignedB) -> std::optional<Decomposition> { auto ResA = decompose(A, Preconditions, IsSigned, DL); auto ResB = decompose(B, Preconditions, IsSignedB, DL); - ResA.add(ResB); + if (ResA.add(ResB)) + return std::nullopt; return ResA; }; @@ -533,21 +539,26 @@ static Decomposition decompose(Value *V, V = Op0; } - if (match(V, m_NSWAdd(m_Value(Op0), m_Value(Op1)))) - return MergeResults(Op0, Op1, IsSigned); + if (match(V, m_NSWAdd(m_Value(Op0), m_Value(Op1)))) { + if (auto Decomp = MergeResults(Op0, Op1, IsSigned)) + return *Decomp; + return {V, IsKnownNonNegative}; + } if (match(V, m_NSWSub(m_Value(Op0), m_Value(Op1)))) { auto ResA = decompose(Op0, Preconditions, IsSigned, DL); auto ResB = decompose(Op1, Preconditions, IsSigned, DL); - ResA.sub(ResB); - return ResA; + if (!ResA.sub(ResB)) + return ResA; + return {V, IsKnownNonNegative}; } ConstantInt *CI; if (match(V, m_NSWMul(m_Value(Op0), m_ConstantInt(CI))) && canUseSExt(CI)) { auto Result = decompose(Op0, Preconditions, IsSigned, DL); - Result.mul(CI->getSExtValue()); - return Result; + if (!Result.mul(CI->getSExtValue())) + return Result; + return {V, IsKnownNonNegative}; } // (shl nsw x, shift) is (mul nsw x, (1<<shift)), with the exception of @@ -557,8 +568,9 @@ static Decomposition decompose(Value *V, if (Shift < Ty->getIntegerBitWidth() - 1) { assert(Shift < 64 && "Would overflow"); auto Result = decompose(Op0, Preconditions, IsSigned, DL); - Result.mul(int64_t(1) << Shift); - return Result; + if (!Result.mul(int64_t(1) << Shift)) + return Result; + return {V, IsKnownNonNegative}; } } @@ -593,8 +605,11 @@ static Decomposition decompose(Value *V, Value *Op1; ConstantInt *CI; if (match(V, m_NUWAdd(m_Value(Op0), m_Value(Op1)))) { - return MergeResults(Op0, Op1, IsSigned); + if (auto Decomp = MergeResults(Op0, Op1, IsSigned)) + return *Decomp; + return {V, IsKnownNonNegative}; } + if (match(V, m_NSWAdd(m_Value(Op0), m_Value(Op1)))) { if (!isKnownNonNegative(Op0, DL)) Preconditions.emplace_back(CmpInst::ICMP_SGE, Op0, @@ -603,7 +618,9 @@ static Decomposition decompose(Value *V, Preconditions.emplace_back(CmpInst::ICMP_SGE, Op1, ConstantInt::get(Op1->getType(), 0)); - return MergeResults(Op0, Op1, IsSigned); + if (auto Decomp = MergeResults(Op0, Op1, IsSigned)) + return *Decomp; + return {V, IsKnownNonNegative}; } if (match(V, m_Add(m_Value(Op0), m_ConstantInt(CI))) && CI->isNegative() && @@ -611,33 +628,41 @@ static Decomposition decompose(Value *V, Preconditions.emplace_back( CmpInst::ICMP_UGE, Op0, ConstantInt::get(Op0->getType(), CI->getSExtValue() * -1)); - return MergeResults(Op0, CI, true); + if (auto Decomp = MergeResults(Op0, CI, true)) + return *Decomp; + return {V, IsKnownNonNegative}; } // Decompose or as an add if there are no common bits between the operands. - if (match(V, m_DisjointOr(m_Value(Op0), m_ConstantInt(CI)))) - return MergeResults(Op0, CI, IsSigned); + if (match(V, m_DisjointOr(m_Value(Op0), m_ConstantInt(CI)))) { + if (auto Decomp = MergeResults(Op0, CI, IsSigned)) + return *Decomp; + return {V, IsKnownNonNegative}; + } if (match(V, m_NUWShl(m_Value(Op1), m_ConstantInt(CI))) && canUseSExt(CI)) { if (CI->getSExtValue() < 0 || CI->getSExtValue() >= 64) return {V, IsKnownNonNegative}; auto Result = decompose(Op1, Preconditions, IsSigned, DL); - Result.mul(int64_t{1} << CI->getSExtValue()); - return Result; + if (!Result.mul(int64_t{1} << CI->getSExtValue())) + return Result; + return {V, IsKnownNonNegative}; } if (match(V, m_NUWMul(m_Value(Op1), m_ConstantInt(CI))) && canUseSExt(CI) && (!CI->isNegative())) { auto Result = decompose(Op1, Preconditions, IsSigned, DL); - Result.mul(CI->getSExtValue()); - return Result; + if (!Result.mul(CI->getSExtValue())) + return Result; + return {V, IsKnownNonNegative}; } if (match(V, m_NUWSub(m_Value(Op0), m_Value(Op1)))) { auto ResA = decompose(Op0, Preconditions, IsSigned, DL); auto ResB = decompose(Op1, Preconditions, IsSigned, DL); - ResA.sub(ResB); - return ResA; + if (!ResA.sub(ResB)) + return ResA; + return {V, IsKnownNonNegative}; } return {V, IsKnownNonNegative};
[ { "file": "llvm/test/Transforms/ConstraintElimination/constraint-overflow.ll", "commands": [ "opt -passes=constraint-elimination -S %s" ], "tests": [ { "test_name": "pr140481", "test_body": "; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i1 @pr140481(i32 %x) {\nentry:\n %cond = icmp slt i32 %x, 0\n call void @llvm.assume(i1 %cond)\n %add = add nsw i32 %x, 5001000\n %mul1 = mul nsw i32 %add, -5001000\n %mul2 = mul nsw i32 %mul1, 5001000\n %cmp2 = icmp sgt i32 %mul2, 0\n ret i1 %cmp2\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "wrong code at -O{s,2,3} on x86_64-linux-gnu", "body": "Compiler Explorer: https://godbolt.org/z/KGW6a53xf\n\nIt appears to be a regression from 16.0.0, and affects 17.0.1 and later. \n\n```\n[590] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git fb86b3d96b73f4e628288b180ef4e038da8b7bc1)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[591] % \n[591] % clangtk -O1 small.c; ./a.out\n[592] % \n[592] % clangtk -O3 small.c\n[593] % ./a.out\nAborted\n[594] % \n[594] % cat small.c\nint a = 1, b, c;\nint main() {\n b = -5001001 * a + 5001000;\n while (b >= 5001001)\n b = a + 5001000;\n c = -5001000 * b - 5001001;\n if (5001000 * c >= b)\n __builtin_abort();\n return 0;\n}\n```", "author": "zhendongsu", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "hstk30-hw", "body": "https://godbolt.org/z/noce5aa3Y CC @nikic take a look" }, { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/JVTQCY\n" }, { "author": "dtcxzyw", "body": "Further reduced version: https://alive2.llvm.org/ce/z/3_XCwc" } ] }
true
null
98139
https://github.com/llvm/llvm-project/issues/98139
miscompilation
6aefa918768c834ec21e0b599fa14d03b9ce3dc0
2024-07-09T09:49:19
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "722151664ecfd53295392ad875ff9bfdcd1deaaf", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ [ 411, 417 ] ], "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ "InstCombinerImpl::SimplifyDemandedUseBits" ], "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 722151664ecfd53295392ad875ff9bfdcd1deaaf Author: Yingwei Zheng <[email protected]> Date: Tue Jul 9 22:04:55 2024 +0800 [InstCombine] Fix typo in `adjustKnownBitsForSelectArm` (#98155) Fixes https://github.com/llvm/llvm-project/issues/98139. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 98f085a2c756..081e783c964f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -411,7 +411,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, // Only known if known in both the LHS and RHS. adjustKnownBitsForSelectArm(LHSKnown, I->getOperand(0), I->getOperand(1), /*Invert=*/false, Depth, Q); - adjustKnownBitsForSelectArm(LHSKnown, I->getOperand(0), I->getOperand(2), + adjustKnownBitsForSelectArm(RHSKnown, I->getOperand(0), I->getOperand(2), /*Invert=*/true, Depth, Q); Known = LHSKnown.intersectWith(RHSKnown); break;
[ { "file": "llvm/test/Transforms/InstCombine/pr98139.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr98139", "test_body": "define i8 @pr98139(i16 %a, i16 %b, i1 %cond) {\n %sel = select i1 %cond, i16 1, i16 254\n %cond1 = icmp ne i16 %b, 0\n %mask = and i16 %a, 255\n %cond2 = icmp ne i16 %mask, 255\n %cond3 = or i1 %cond1, %cond2\n %sel2 = select i1 %cond3, i16 %sel, i16 255\n %sub = sub i16 %sel2, %a\n %trunc = trunc i16 %sub to i8\n ret i8 %trunc\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "wrong code at -O{s,2,3} on x86_64-linux-gnu", "body": "It appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier.\r\n\r\nCompiler Explorer: https://godbolt.org/z/o595xsMdb\r\n\r\n```\r\n[512] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 765e2f9a8de27cc8fd8c75540844e9630d8229ad)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[513] % \r\n[513] % clangtk -O1 small.c; ./a.out\r\n1\r\n[514] % clangtk -O3 small.c; ./a.out\r\n-2\r\n1\r\n[515] % cat small.c\r\nint printf(const char *, ...);\r\nint a, b, c, e;\r\nchar d;\r\nint main() {\r\n int f = 1;\r\n unsigned g = 1;\r\n for (; c < 2; c++) {\r\n if (g)\r\n b = 1;\r\n char h = f;\r\n f = ~h;\r\n d = ~b - ~g * (a || f);\r\n g = ~g;\r\n if (g < 1)\r\n break;\r\n if (d)\r\n printf(\"%d\\n\", g);\r\n f = e;\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "miscompilation", "confirmed", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "There is a bug in `SimplifyDemandedInstructionBits` :)\r\nI am working to provide a minimal reproducer.\r\n" }, { "author": "dtcxzyw", "body": "@nikic https://github.com/llvm/llvm-project/blob/a9183b8899f2c02ba3710b27c0cbdde6831a627b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L411-L416\r\n\r\nI will post a fix later.\r\n" }, { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/GAUsBC\r\n```\r\ndefine i8 @src(i16 %a, i16 %b, i1 %cond) {\r\n %sel = select i1 %cond, i16 1, i16 254\r\n %cond1 = icmp ne i16 %b, 0\r\n %mask = and i16 %a, 255\r\n %cond2 = icmp ne i16 %mask, 255\r\n %cond3 = or i1 %cond1, %cond2\r\n %sel2 = select i1 %cond3, i16 %sel, i16 255\r\n %sub = sub i16 %sel2, %a\r\n %trunc = trunc i16 %sub to i8\r\n ret i8 %trunc\r\n}\r\n\r\ndefine i8 @tgt(i16 %a1, i16 %a2, i1 %cond) {\r\n %1 = trunc i16 %a1 to i8\r\n %conv6 = xor i8 %1, -1\r\n ret i8 %conv6\r\n}\r\n```" } ] }
true
null
126181
https://github.com/llvm/llvm-project/issues/126181
miscompilation
317a644ae6d501f1a1ec54d17ea8559bcdea35c0
2025-02-07T05:51:32
[ "llvm/test/Transforms/DeadStoreElimination" ]
{ "fix_commit": "2d31a12dbe2339d20844ede70cbb54dbaf4ceea9", "components": [ "DeadStoreElimination" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [ [ 2283, 2289 ] ], "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/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/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/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": 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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": 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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Analysis/VectorUtils.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.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/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [ "DSEState::getInitializesArgMemLoc" ], "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "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/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.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/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/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.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/InstructionCombining.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.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/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.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/Scalar/LoopStrengthReduce.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/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 2d31a12dbe2339d20844ede70cbb54dbaf4ceea9 Author: Nikita Popov <[email protected]> Date: Mon Feb 10 10:34:03 2025 +0100 [DSE] Don't use initializes on byval argument (#126259) There are two ways we can fix this problem, depending on how the semantics of byval and initializes should interact: * Don't infer initializes on byval arguments. initializes on byval refers to the original caller memory (or having both attributes is made a verifier error). * Infer initializes on byval, but don't use it in DSE. initializes on byval refers to the callee copy. This matches the semantics of readonly on byval. This is slightly more powerful, for example, we could do a backend optimization where byval + initializes will allocate the full size of byval on the stack but not copy over the parts covered by initializes. I went with the second variant here, skipping byval + initializes in DSE (FunctionAttrs already doesn't propagate initializes past byval). I'm open to going in the other direction though. Fixes https://github.com/llvm/llvm-project/issues/126181. diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 05b4f176bfc3..38454053b039 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -2283,7 +2283,9 @@ DSEState::getInitializesArgMemLoc(const Instruction *I) { for (unsigned Idx = 0, Count = CB->arg_size(); Idx < Count; ++Idx) { ConstantRangeList Inits; Attribute InitializesAttr = CB->getParamAttr(Idx, Attribute::Initializes); - if (InitializesAttr.isValid()) + // initializes on byval arguments refers to the callee copy, not the + // original memory the caller passed in. + if (InitializesAttr.isValid() && !CB->isByValArgument(Idx)) Inits = InitializesAttr.getValueAsConstantRangeList(); Value *CurArg = CB->getArgOperand(Idx);
[ { "file": "llvm/test/Transforms/DeadStoreElimination/inter-procedural.ll", "commands": [ "opt < %s -passes=dse -enable-dse-initializes-attr-improvement -S" ], "tests": [ { "test_name": "test_byval", "test_body": "%struct.a = type { i32, i64, i32, i32 }\n\n@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8\n\ndefine i8 @ad(ptr byval(%struct.a) %ah) {\nentry:\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine i64 @af(ptr byval(%struct.a) initializes((0, 24)) %am) {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n\ndefine i32 @main() {\n %res = call i8 @ad(ptr @e)\n %val = sext i8 %res to i32\n ret i32 %val\n}\n", "additional_args": null, "lli_expected_out": "" } ] } ]
{ "title": "[FuncAttrs] `initializes` is incorrectly set on parameters with `byval`", "body": "Reproducer: https://godbolt.org/z/Mcx1nY4E7\n```\n; bin/opt -passes=function-attrs reduced.ll -S\n%struct.a = type { i32, i64, i32, i32 }\n\n@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8\n\ndefine i8 @ad(ptr byval(%struct.a) %ah) {\nentry:\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine i64 @af(ptr byval(%struct.a) %am) {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n\n```\n```\ndefine i8 @ad(ptr byval(%struct.a) captures(none) initializes((0, 4)) %ah) #0 {\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine noundef i64 @af(ptr writeonly byval(%struct.a) captures(none) initializes((0, 24)) %am) #0 {\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n```\nAfter DSE:\n```\ndefine i8 @ad(ptr byval(%struct.a) captures(none) initializes((0, 4)) %ah) #0 {\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine noundef i64 @af(ptr writeonly byval(%struct.a) captures(none) initializes((0, 24)) %am) #0 {\n ret i64 0\n}\n```\n\nllvm version: d21fc58aeeaa7f0369a24dbe70a0360e0edbf76f\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "nikic", "body": "> We should also emit the padding for %struct.a.\n\nWithout commenting on whether we should or shouldn't, why is not having the padding a miscompile? As this is not a packed struct, for a i64:64 target, LLVM will implicitly insert the padding and it should have the correct size." }, { "author": "dtcxzyw", "body": "> As this is not a packed struct, for a i64:64 target, LLVM will implicitly insert the padding and it should have the correct size.\n\nSorry. It is a DSE bug.\n" }, { "author": "dtcxzyw", "body": "cc @haopliu " }, { "author": "nikic", "body": "@dtcxzyw I think your new IR is over-reduced. You have `initializes((0, 24)` on `@af`, so I think eliminating the store is correct." }, { "author": "dtcxzyw", "body": "> [@dtcxzyw](https://github.com/dtcxzyw) I think your new IR is over-reduced. You have `initializes((0, 24)` on `@af`, so I think eliminating the store is correct.\n\nFixed." }, { "author": "nikic", "body": "There are two ways we can fix this, depending on what we want the semantics to do:\n\n 1. Don't infer initializes on byval arguments. initializes on byval refers to the original caller memory (or having both attributes is made a verifier error).\n 2. Infer initializes on byval, but don't use it in DSE. initializes on byval refers to the callee copy. This matches the semantics of readonly on byval.\n\nI think variant 2 is marginally more powerful. For example, we could do a backend optimization where byval + initializes will allocate the full size of byval on the stack but not copy over the parts covered by initializes." } ] }
true
null