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
95016
https://github.com/llvm/llvm-project/issues/95016
crash
1846523bb77275de954ac573110171bd39bfa930
2024-06-10T18:08:58
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "380beaec8633bad0148aec02f03a85d9a59b2a2d", "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": [ [ 835, 845 ] ], "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": [ "getSameOpcode" ], "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 380beaec8633bad0148aec02f03a85d9a59b2a2d Author: Gabriel Baraldi <[email protected]> Date: Tue Jul 2 09:15:51 2024 -0300 Fix potential crash in SLPVectorizer caused by missing check (#95937) I'm not super familiar with this code, but it seems that we were just missing a check. The original code that triggered this did not have uselistorders but llvm-reduce created them and it reproduces the same issue in a way more compact way. Fixes https://github.com/llvm/llvm-project/issues/95016 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c4876bb92a1c..868e9e2687f5 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -835,11 +835,11 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL, auto *CallBase = cast<CallInst>(IBase); if (Call->getCalledFunction() != CallBase->getCalledFunction()) return InstructionsState(VL[BaseIndex], nullptr, nullptr); - if (Call->hasOperandBundles() && + if (Call->hasOperandBundles() && (!CallBase->hasOperandBundles() || !std::equal(Call->op_begin() + Call->getBundleOperandsStartIndex(), Call->op_begin() + Call->getBundleOperandsEndIndex(), CallBase->op_begin() + - CallBase->getBundleOperandsStartIndex())) + CallBase->getBundleOperandsStartIndex()))) return InstructionsState(VL[BaseIndex], nullptr, nullptr); Intrinsic::ID ID = getVectorIntrinsicIDForCall(Call, &TLI); if (ID != BaseID)
[ { "file": "llvm/test/Transforms/SLPVectorizer/AArch64/uselistorder.ll", "commands": [ "opt < %s -passes=slp-vectorizer -S -pass-remarks-missed=slp-vectorizer 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-unknown-linux-gnu\"\n\n; This test has UB but the crash in #95016 only happens with it\ndefine void @uselistorder_test() {\n;\n %max1 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00) [ \"a_list\"(ptr null) ]\n %add1 = fadd double %max1, 0.000000e+00\n %mul1 = fmul double 0.000000e+00, %add1\n %mul2 = fmul double %mul1, 0.000000e+00\n %sel1 = select i1 false, double 0.000000e+00, double %mul2\n %max2 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00)\n %add2 = fadd double %max2, 0.000000e+00\n %mul3 = fmul double 0.000000e+00, %add2\n %mul4 = fmul double %mul3, 0.000000e+00\n %sel2 = select i1 false, double 0.000000e+00, double %mul4\n %mul5 = fmul double %sel2, 0.000000e+00\n %add3 = fadd double 0.000000e+00, %mul5\n %gep1 = getelementptr { double, [1 x [2 x double]] }, ptr null, i64 0, i32 1\n store double %add3, ptr %gep1, align 8\n %mul6 = fmul double %sel1, 0.000000e+00\n %add4 = fadd double %mul6, 0.000000e+00\n store double %add4, ptr null, align 8\n ret void\n}\n\ndeclare double @llvm.maximum.f64(double, double) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "SLPVectorizer (hasOperandBundles() && \"Don't call otherwise!\") assertion trigger with verified module", "body": "SLPVectorize asserts while optimizing the following module\r\n```llvm-ir\r\ntarget datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128-ni:10:11:12:13\"\r\ntarget triple = \"arm64-apple-darwin23.5.0\"\r\n\r\ndefine swiftcc void @julia_multiparameter_a_res_17823() {\r\ntop:\r\n %0 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00) [ \"jl_roots\"(ptr null) ]\r\n %1 = fadd double %0, 0.000000e+00\r\n %2 = fmul double 0.000000e+00, %1\r\n %3 = fmul double %2, 0.000000e+00\r\n %4 = select i1 false, double 0.000000e+00, double %3\r\n %5 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00)\r\n %6 = fadd double %5, 0.000000e+00\r\n %7 = fmul double 0.000000e+00, %6\r\n %8 = fmul double %7, 0.000000e+00\r\n %9 = select i1 false, double 0.000000e+00, double %8\r\n %10 = fmul double %9, 0.000000e+00\r\n %11 = fadd double 0.000000e+00, %10\r\n %12 = getelementptr { double, [1 x [2 x double]] }, ptr null, i64 0, i32 1\r\n store double %11, ptr %12, align 8\r\n %13 = fmul double %4, 0.000000e+00\r\n %14 = fadd double %13, 0.000000e+00\r\n store double %14, ptr null, align 8\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare double @llvm.maximum.f64(double, double) #0\r\n\r\n; uselistorder directives\r\nuselistorder ptr @llvm.maximum.f64, { 1, 0 }\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nThis also seems to trigger on godbolt on whatever version of trunk they have there\r\nhttps://godbolt.org/z/favErWG5K\r\n\r\n\r\nstacktrace:\r\n> #0 0x0000000004e258c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e258c8)\r\n #1 0x0000000004e2301c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c7148042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c71480969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c7148042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c71480287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007c714802871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007c7148039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003ee5e8f (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ee5e8f)\r\n #9 0x0000000003f5e546 getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n#10 0x0000000003f67928 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getShallowScore(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, llvm::ArrayRef<llvm::Value*>) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f67928)\r\n#11 0x0000000003f67de0 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getScoreAtLevelRec(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, int, llvm::ArrayRef<llvm::Value*>) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f67de0)\r\n#12 0x0000000003f6aaf5 llvm::slpvectorizer::BoUpSLP::VLOperands::getBestOperand(unsigned int, int, int, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::VLOperands::ReorderingMode>, llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6aaf5)\r\n#13 0x0000000003f6bfcb llvm::slpvectorizer::BoUpSLP::VLOperands::reorder() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6bfcb)\r\n#14 0x0000000003f6c4f6 llvm::slpvectorizer::BoUpSLP::reorderInputsAccordingToOpcode(llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<llvm::Value*>&, llvm::SmallVectorImpl<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6c4f6)\r\n#15 0x0000000003f702f4 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f702f4)\r\n#16 0x0000000003f70392 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70392)\r\n#17 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#18 0x0000000003f7022b llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f7022b)\r\n#19 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#20 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#21 0x0000000003f6fe47 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6fe47)\r\n#22 0x0000000003f71b59 llvm::slpvectorizer::BoUpSLP::buildTree(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f71b59)\r\n#23 0x0000000003f94622 llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f94622)\r\n#24 0x0000000003f95fb0 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#25 0x0000000003f97e88 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>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f97e88)\r\n#26 0x0000000003f985b3 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f985b3)\r\n#27 0x0000000003f9970f 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#28 0x0000000003f9a163 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f9a163)\r\n#29 0x0000000002e1013e 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+0x2e1013e)\r\n#30 0x0000000004c2e64c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2e64c)\r\n#31 0x0000000000db3bce 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+0xdb3bce)\r\n#32 0x0000000004c2cf8e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2cf8e)\r\n#33 0x0000000000db563e 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+0xdb563e)\r\n#34 0x0000000004c2ae9c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2ae9c)\r\n#35 0x00000000008d7b32 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+0x8d7b32)\r\n#36 0x00000000008cacdc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cacdc)\r\n#37 0x00007c7148029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#38 0x00007c7148029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#39 0x00000000008c212e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c212e)", "author": "gbaraldi", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
134013
https://github.com/llvm/llvm-project/issues/134013
crash
65ed35393cc8a3b896d794ab316e0357d907efff
2025-04-02T00:52:53
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "48a4b14cb65d56ec3bbb473887c31d251092c83c", "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": [ [ 8873, 8878 ] ], "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 48a4b14cb65d56ec3bbb473887c31d251092c83c Author: Alexey Bataev <[email protected]> Date: Wed Apr 2 05:57:16 2025 -0700 [SLP]Fix whole vector registers calculations for compares Need to check that the calculated number of the elements is not larger than the original number of scalars to prevent a compiler crash. Fixes #134013 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index f9284b3a5f21..838e952c024c 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -8873,6 +8873,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, // Find the number of elements, which forms full vectors. unsigned PWSz = getFullVectorNumberOfElements( *TTI, UniqueValues.front()->getType(), UniqueValues.size()); + PWSz = std::min<unsigned>(PWSz, VL.size()); if (PWSz == VL.size()) { ReuseShuffleIndices.clear(); } else {
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/whole-registers-compare.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nentry:\n br label %do.body\n\ndo.body:\n %val.sroa.66.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.66.1, %do.body ]\n %val.sroa.60.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.60.2, %do.body ]\n %val.sroa.54.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.54.2, %do.body ]\n %val.sroa.48.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.48.2, %do.body ]\n %val.sroa.42.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.42.2, %do.body ]\n %val.sroa.36.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.36.2, %do.body ]\n %val.sroa.30.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.30.2, %do.body ]\n %val.sroa.24.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.24.2, %do.body ]\n %val.sroa.18.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.18.2, %do.body ]\n %val.sroa.12.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.12.2, %do.body ]\n %val.sroa.6.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.6.2, %do.body ]\n %val.sroa.0.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.0.1, %do.body ]\n %cmp119 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.6.1 = select i1 %cmp119, float 0.000000e+00, float 0.000000e+00\n %val.sroa.0.1 = select i1 %cmp119, float 0.000000e+00, float 0.000000e+00\n %cmp119.1 = fcmp uge float %val.sroa.6.1, 0.000000e+00\n %val.sroa.6.2 = select i1 %cmp119.1, float 0.000000e+00, float 0.000000e+00\n %cmp119.2 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.12.2 = select i1 %cmp119.2, float 0.000000e+00, float 0.000000e+00\n %cmp119.3 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.18.2 = select i1 %cmp119.3, float 0.000000e+00, float 0.000000e+00\n %cmp119.4 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.24.2 = select i1 %cmp119.4, float 0.000000e+00, float 0.000000e+00\n %cmp119.5 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.30.2 = select i1 %cmp119.5, float 0.000000e+00, float 0.000000e+00\n %cmp119.6 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.36.2 = select i1 %cmp119.6, float 0.000000e+00, float 0.000000e+00\n %cmp119.7 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.42.2 = select i1 %cmp119.7, float 0.000000e+00, float 0.000000e+00\n %cmp119.8 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.48.2 = select i1 %cmp119.8, float 0.000000e+00, float 0.000000e+00\n %cmp119.9 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.54.2 = select i1 %cmp119.9, float 0.000000e+00, float 0.000000e+00\n %cmp119.10 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.66.1 = select i1 %cmp119.10, float 0.000000e+00, float 0.000000e+00\n %val.sroa.60.2 = select i1 %cmp119.10, float 0.000000e+00, float 0.000000e+00\n br label %do.body\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "crash in slp vectorizer after \"[SLP]Fix a check for the whole register use\"", "body": "After applying [bfd8cc0a3e82](https://github.com/llvm/llvm-project/commit/bfd8cc0a3e82), I am seeing a crash in SLPVectorize.cpp.\n\nReproducer:\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 <2 x float> @foo() {\nentry:\n br label %do.body\n\ndo.body: ; preds = %do.body, %entry\n %val.sroa.66.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.66.1, %do.body ]\n %val.sroa.60.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.60.2, %do.body ]\n %val.sroa.54.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.54.2, %do.body ]\n %val.sroa.48.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.48.2, %do.body ]\n %val.sroa.42.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.42.2, %do.body ]\n %val.sroa.36.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.36.2, %do.body ]\n %val.sroa.30.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.30.2, %do.body ]\n %val.sroa.24.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.24.2, %do.body ]\n %val.sroa.18.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.18.2, %do.body ]\n %val.sroa.12.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.12.2, %do.body ]\n %val.sroa.6.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.6.2, %do.body ]\n %val.sroa.0.0 = phi float [ 0.000000e+00, %entry ], [ %val.sroa.0.1, %do.body ]\n %cmp119 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.6.1 = select i1 %cmp119, float 0.000000e+00, float 0.000000e+00\n %val.sroa.0.1 = select i1 %cmp119, float 0.000000e+00, float 0.000000e+00\n %cmp119.1 = fcmp uge float %val.sroa.6.1, 0.000000e+00\n %val.sroa.6.2 = select i1 %cmp119.1, float 0.000000e+00, float 0.000000e+00\n %cmp119.2 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.12.2 = select i1 %cmp119.2, float 0.000000e+00, float 0.000000e+00\n %cmp119.3 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.18.2 = select i1 %cmp119.3, float 0.000000e+00, float 0.000000e+00\n %cmp119.4 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.24.2 = select i1 %cmp119.4, float 0.000000e+00, float 0.000000e+00\n %cmp119.5 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.30.2 = select i1 %cmp119.5, float 0.000000e+00, float 0.000000e+00\n %cmp119.6 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.36.2 = select i1 %cmp119.6, float 0.000000e+00, float 0.000000e+00\n %cmp119.7 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.42.2 = select i1 %cmp119.7, float 0.000000e+00, float 0.000000e+00\n %cmp119.8 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.48.2 = select i1 %cmp119.8, float 0.000000e+00, float 0.000000e+00\n %cmp119.9 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.54.2 = select i1 %cmp119.9, float 0.000000e+00, float 0.000000e+00\n %cmp119.10 = fcmp uge float 0.000000e+00, 0.000000e+00\n %val.sroa.66.1 = select i1 %cmp119.10, float 0.000000e+00, float 0.000000e+00\n %val.sroa.60.2 = select i1 %cmp119.10, float 0.000000e+00, float 0.000000e+00\n br label %do.body\n}\n```\nCrash is occurring on [SLPVectorizer.cpp:16251](https://github.com/llvm/llvm-project/blob/ad1ca5f4a2bc09f99fd82e5444f5da37c2985e97/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L16251).\nAt the time `VF:12` and `Scalars.size():16`.\n", "author": "macurtis-amd", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "macurtis-amd", "body": "@alexey-bataev Thanks!" } ] }
true
null
121584
https://github.com/llvm/llvm-project/issues/121584
miscompilation
4a7c0b8afe6bf616cd6bb4f13b5b706a43c10e74
2025-01-03T17:05:45
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "24c2ba07ce65a5bf7d1113e05c517169d950b663", "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": [ [ 2066, 2079 ], [ 2095, 2101 ], [ 2108, 2114 ], [ 2131, 2137 ] ], "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": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [ "simplifyIRemMulShl" ], "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 24c2ba07ce65a5bf7d1113e05c517169d950b663 Author: Yingwei Zheng <[email protected]> Date: Sun Jan 5 01:20:54 2025 +0800 [InstCombine] Drop NSW when converting `shl X, BW - 1` back into mul (#121633) `X <<s BW - 1` and `X *s INT_MIN` are not equivalent. Alive2: https://alive2.llvm.org/ce/z/MKKFrj Closes https://github.com/llvm/llvm-project/issues/121584 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index f85a3c936513..97a765ecfb6b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -2066,14 +2066,18 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I, bool ShiftByX = false; // If V is not nullptr, it will be matched using m_Specific. - auto MatchShiftOrMulXC = [](Value *Op, Value *&V, APInt &C) -> bool { + auto MatchShiftOrMulXC = [](Value *Op, Value *&V, APInt &C, + bool &PreserveNSW) -> bool { const APInt *Tmp = nullptr; if ((!V && match(Op, m_Mul(m_Value(V), m_APInt(Tmp)))) || (V && match(Op, m_Mul(m_Specific(V), m_APInt(Tmp))))) C = *Tmp; else if ((!V && match(Op, m_Shl(m_Value(V), m_APInt(Tmp)))) || - (V && match(Op, m_Shl(m_Specific(V), m_APInt(Tmp))))) + (V && match(Op, m_Shl(m_Specific(V), m_APInt(Tmp))))) { C = APInt(Tmp->getBitWidth(), 1) << *Tmp; + // We cannot preserve NSW when shifting by BW - 1. + PreserveNSW = Tmp->ult(Tmp->getBitWidth() - 1); + } if (Tmp != nullptr) return true; @@ -2095,7 +2099,9 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I, return false; }; - if (MatchShiftOrMulXC(Op0, X, Y) && MatchShiftOrMulXC(Op1, X, Z)) { + bool Op0PreserveNSW = true, Op1PreserveNSW = true; + if (MatchShiftOrMulXC(Op0, X, Y, Op0PreserveNSW) && + MatchShiftOrMulXC(Op1, X, Z, Op1PreserveNSW)) { // pass } else if (MatchShiftCX(Op0, Y, X) && MatchShiftCX(Op1, Z, X)) { ShiftByX = true; @@ -2108,7 +2114,7 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I, OverflowingBinaryOperator *BO0 = cast<OverflowingBinaryOperator>(Op0); // TODO: We may be able to deduce more about nsw/nuw of BO0/BO1 based on Y >= // Z or Z >= Y. - bool BO0HasNSW = BO0->hasNoSignedWrap(); + bool BO0HasNSW = Op0PreserveNSW && BO0->hasNoSignedWrap(); bool BO0HasNUW = BO0->hasNoUnsignedWrap(); bool BO0NoWrap = IsSRem ? BO0HasNSW : BO0HasNUW; @@ -2131,7 +2137,7 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I, }; OverflowingBinaryOperator *BO1 = cast<OverflowingBinaryOperator>(Op1); - bool BO1HasNSW = BO1->hasNoSignedWrap(); + bool BO1HasNSW = Op1PreserveNSW && BO1->hasNoSignedWrap(); bool BO1HasNUW = BO1->hasNoUnsignedWrap(); bool BO1NoWrap = IsSRem ? BO1HasNSW : BO1HasNUW; // (rem (mul X, Y), (mul nuw/nsw X, Z))
[ { "file": "llvm/test/Transforms/InstCombine/rem-mul-shl.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "srem_XY_XZ_with_CY_gt_CZ_no_nuw_out", "test_body": "define <2 x i8> @srem_XY_XZ_with_CY_gt_CZ_no_nuw_out(<2 x i8> %X) {\n %BO0 = mul nsw <2 x i8> %X, splat (i8 10)\n %BO1 = shl nuw nsw <2 x i8> %X, splat (i8 3)\n %r = srem <2 x i8> %BO0, %BO1\n ret <2 x i8> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "srem_XY_XZ_with_CY_gt_CZ_drop_nsw_commuted", "test_body": "define i8 @srem_XY_XZ_with_CY_gt_CZ_drop_nsw_commuted(i8 noundef %X) {\n %BO0 = mul nsw i8 %X, 127\n %BO1 = shl nsw i8 %X, 7\n %r = srem i8 %BO0, %BO1\n ret i8 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "srem_XY_XZ_with_CY_gt_CZ_drop_nsw", "test_body": "define i8 @srem_XY_XZ_with_CY_gt_CZ_drop_nsw(i8 noundef %X) {\n %BO0 = mul nsw i8 %X, 127\n %BO1 = shl nsw i8 %X, 7\n %r = srem i8 %BO1, %BO0\n ret i8 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "srem_XY_XZ_with_CY_gt_CZ_fail_missing_flag1", "test_body": "define i8 @srem_XY_XZ_with_CY_gt_CZ_fail_missing_flag1(i8 %X) {\n %BO0 = mul nuw nsw i8 %X, 10\n %BO1 = mul nuw i8 %X, 6\n %r = srem i8 %BO0, %BO1\n ret i8 %r\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Miscompilation in `simplifyIRemMulShl`", "body": "Alive2: https://alive2.llvm.org/ce/z/rdeehL\n```\n\n----------------------------------------\ndefine i8 @srem_XY_XZ_with_CY_gt_CZ_no_nuw_out1(i8 noundef %X) {\n#0:\n %BO0 = mul nsw i8 noundef %X, 127\n %BO1 = shl nsw i8 noundef %X, 7\n %r = srem i8 %BO1, %BO0\n ret i8 %r\n}\n=>\ndefine i8 @srem_XY_XZ_with_CY_gt_CZ_no_nuw_out1(i8 noundef %X) {\n#0:\n %r = sub nsw i8 0, noundef %X\n ret i8 %r\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\ni8 noundef %X = #xff (255, -1)\n\nSource:\ni8 %BO0 = #x81 (129, -127)\ni8 %BO1 = #x80 (128, -128)\ni8 %r = #xff (255, -1)\n\nTarget:\ni8 %r = #x01 (1)\nSource value: #xff (255, -1)\nTarget value: #x01 (1)\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
137797
https://github.com/llvm/llvm-project/issues/137797
crash
368fbc21631a16b66a2a5609271c467a025a08b9
2025-04-29T12:24:21
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "3aecbbcbf675bc4472dafff18d29f21457323f28", "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": [ [ 15245, 15250 ] ], "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 3aecbbcbf675bc4472dafff18d29f21457323f28 Author: Alexey Bataev <[email protected]> Date: Tue May 6 06:40:54 2025 -0700 [SLP]Do not match nodes if schedulability of parent nodes is different If one user node is non-schedulable and another one is schedulable, such nodes should be considered matched. The selection of the actual insert point in this case differs and the insert points may match, which may cause a compiler crash because of the broken def-use chain. Fixes #137797 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4d183bb42f0e..a6ae26f2f0e1 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -15245,6 +15245,11 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( continue; } + if (!TEUseEI.UserTE->isGather() && !UserPHI && + doesNotNeedToSchedule(TEUseEI.UserTE->Scalars) != + doesNotNeedToSchedule(UseEI.UserTE->Scalars) && + is_contained(UseEI.UserTE->Scalars, TEInsertPt)) + continue; // Check if the user node of the TE comes after user node of TEPtr, // otherwise TEPtr depends on TE. if ((TEInsertBlock != InsertPt->getParent() ||
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/matched-bv-schedulable.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s -slp-threshold=-99999" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nbb:\n br i1 false, label %bb1, label %bb5\n\nbb1:\n %phi = phi i32 [ %or4, %bb1 ], [ 0, %bb ]\n %phi2 = phi i32 [ %add, %bb1 ], [ 0, %bb ]\n %add = add i32 1, 0\n %or = or i32 0, %phi2\n %or3 = or i32 %or, 0\n %mul = mul i32 0, 0\n %or4 = or i32 %phi, %mul\n br i1 false, label %bb1, label %bb5\n\nbb5:\n %phi6 = phi i32 [ 0, %bb ], [ %or4, %bb1 ]\n %phi7 = phi i32 [ 0, %bb ], [ %or, %bb1 ]\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with the test below using -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() #0 gc \"statepoint-example\" {\nbb:\n br i1 false, label %bb1, label %bb5\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ %or4, %bb1 ], [ 0, %bb ]\n %phi2 = phi i32 [ %add, %bb1 ], [ 0, %bb ]\n %add = add i32 1, 0\n %or = or i32 0, %phi2\n %or3 = or i32 %or, 0\n %mul = mul i32 0, 0\n %or4 = or i32 %phi, %mul\n br i1 false, label %bb1, label %bb5\n\nbb5: ; preds = %bb1, %bb\n %phi6 = phi i32 [ 0, %bb ], [ %or4, %bb1 ]\n %phi7 = phi i32 [ 0, %bb ], [ %or, %bb1 ]\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,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-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,-avx512f\" }\n```\nReproducer: https://godbolt.org/z/YbPKn761h\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 \"verify\" on module \"<source>\"\n #0 0x00000000055242e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x55242e8)\n #1 0x0000000005521c74 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000073e542242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000073e5422969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000073e542242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000073e5422287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000000000080a091 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\n #7 0x00000000054600e8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54600e8)\n #8 0x000000000535c8d8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x535c8d8)\n #9 0x000000000093ee6e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93ee6e)\n#10 0x000000000531b5a0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x531b5a0)\n#11 0x00000000009492ba 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+0x9492ba)\n#12 0x000000000093ca8c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93ca8c)\n#13 0x000073e542229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#14 0x000073e542229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#15 0x00000000009346c5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9346c5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
82884
https://github.com/llvm/llvm-project/issues/82884
miscompilation
0c7a605ada6cb392e6e8c16dbccf2b7e59017399
2024-02-24T15:15:12
[ "llvm/test/Transforms/GVN" ]
{ "fix_commit": "892b4beeac50920e630f10905b2916295e2eb6d8", "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": [ [ 3369, 3379 ] ], "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::patchReplacementInstruction" ], "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 892b4beeac50920e630f10905b2916295e2eb6d8 Author: Yingwei Zheng <[email protected]> Date: Mon Feb 26 15:55:56 2024 +0800 [GVN] Drop nsw/nuw flags when replacing the result of a with.overflow intrinsic with a overflowing binary operator (#82935) Alive2: https://alive2.llvm.org/ce/z/gyL7mn Fixes https://github.com/llvm/llvm-project/issues/82884. diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 1373f5f7f449..075eeb5b19fd 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3369,11 +3369,17 @@ void llvm::patchReplacementInstruction(Instruction *I, Value *Repl) { // Patch the replacement so that it is not more restrictive than the value // being replaced. + WithOverflowInst *UnusedWO; + // When replacing the result of a llvm.*.with.overflow intrinsic with a + // overflowing binary operator, nuw/nsw flags may no longer hold. + if (isa<OverflowingBinaryOperator>(ReplInst) && + match(I, m_ExtractValue<0>(m_WithOverflowInst(UnusedWO)))) + ReplInst->dropPoisonGeneratingFlags(); // Note that if 'I' is a load being replaced by some operation, // for example, by an arithmetic operation, then andIRFlags() // would just erase all math flags from the original arithmetic // operation, which is clearly not wanted and not needed. - if (!isa<LoadInst>(I)) + else if (!isa<LoadInst>(I)) ReplInst->andIRFlags(I); // FIXME: If both the original and replacement value are part of the
[ { "file": "llvm/test/Transforms/GVN/pr82884.ll", "commands": [ "opt -S -passes=gvn < %s" ], "tests": [ { "test_name": "pr82884", "test_body": "define i32 @pr82884(i32 %x) {\n %mul = mul nuw nsw i32 %x, %x\n call void @use(i32 %mul)\n %mul2 = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %x, i32 %x)\n %ret = extractvalue { i32, i1 } %mul2, 0\n ret i32 %ret\n}\n\ndeclare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[GVN] GVNPass forgets to remove poison generating flags", "body": "```llvm\r\n; ModuleID = '1851685_debug_2.e4807e3094afc004-cgu.0'\r\nsource_filename = \"1851685_debug_2.e4807e3094afc004-cgu.0\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n%Adt58 = type { %Adt50 }\r\n%Adt50 = type { { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, { i16, i8, [5 x i8], i64 }, [8 x i32], { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr, [7 x i32], [3 x i32] }\r\n%Adt53 = type { { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] } }\r\n%Adt51 = type { { i64, i8, [7 x i8] }, { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, %Adt50, [8 x i32], i64, i64, [6 x i8], [10 x i8] }\r\n%Adt59 = type { { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, i64, ptr, i32, i16, [1 x i8], [1 x i8] }\r\n\r\[email protected] = private unnamed_addr constant <{ ptr, [16 x i8], ptr, ptr, ptr }> <{ ptr @\"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he9a486ff76ea726fE\", [16 x i8] c\"\\08\\00\\00\\00\\00\\00\\00\\00\\08\\00\\00\\00\\00\\00\\00\\00\", ptr @\"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h91c73705548d2f78E\", ptr @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\", ptr @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\" }>, align 8\r\n@alloc_2cdd8ac758b4c372b56d8683306290e0 = private unnamed_addr constant <{ [15 x i8] }> <{ [15 x i8] c\"hi:%ld lo:%ld\\0A\\00\" }>, align 1\r\n\r\n; std::sys_common::backtrace::__rust_begin_short_backtrace\r\n; Function Attrs: noinline nonlazybind uwtable\r\ndefine internal void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h176fc8086015470dE(ptr %f) unnamed_addr #0 {\r\nstart:\r\n; call core::ops::function::FnOnce::call_once\r\n call void @_ZN4core3ops8function6FnOnce9call_once17h23c7757b8dc992b5E(ptr %f)\r\n call void asm sideeffect \"\", \"~{memory}\"(), !srcloc !4\r\n ret void\r\n}\r\n\r\n; std::rt::lang_start::{{closure}}\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i32 @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\"(ptr align 8 %_1) unnamed_addr #2 {\r\nstart:\r\n %self = alloca i8, align 1\r\n %_4 = load ptr, ptr %_1, align 8, !nonnull !5, !noundef !5\r\n; call std::sys_common::backtrace::__rust_begin_short_backtrace\r\n call void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h176fc8086015470dE(ptr %_4)\r\n; call <() as std::process::Termination>::report\r\n %0 = call i8 @\"_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17hb8b4bfb25c4e0e48E\"()\r\n store i8 %0, ptr %self, align 1\r\n %_6 = load i8, ptr %self, align 1, !noundef !5\r\n %_0 = zext i8 %_6 to i32\r\n ret i32 %_0\r\n}\r\n\r\n; core::ops::function::FnOnce::call_once{{vtable.shim}}\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i32 @\"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h91c73705548d2f78E\"(ptr %_1) unnamed_addr #2 {\r\nstart:\r\n %_2 = alloca {}, align 1\r\n %0 = load ptr, ptr %_1, align 8, !nonnull !5, !noundef !5\r\n; call core::ops::function::FnOnce::call_once\r\n %_0 = call i32 @_ZN4core3ops8function6FnOnce9call_once17ha42f99eeb4429a31E(ptr %0)\r\n ret i32 %_0\r\n}\r\n\r\n; core::ops::function::FnOnce::call_once\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @_ZN4core3ops8function6FnOnce9call_once17h23c7757b8dc992b5E(ptr %_1) unnamed_addr #2 {\r\nstart:\r\n %_2 = alloca {}, align 1\r\n call void %_1()\r\n ret void\r\n}\r\n\r\n; core::ops::function::FnOnce::call_once\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i32 @_ZN4core3ops8function6FnOnce9call_once17ha42f99eeb4429a31E(ptr %0) unnamed_addr #2 personality ptr @rust_eh_personality {\r\nstart:\r\n %1 = alloca { ptr, i32, [1 x i32] }, align 8\r\n %_2 = alloca {}, align 1\r\n %_1 = alloca ptr, align 8\r\n store ptr %0, ptr %_1, align 8\r\n; invoke std::rt::lang_start::{{closure}}\r\n %_0 = invoke i32 @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\"(ptr align 8 %_1)\r\n to label %bb1 unwind label %cleanup\r\n\r\nbb3: ; preds = %cleanup\r\n %2 = load ptr, ptr %1, align 8, !noundef !5\r\n %3 = getelementptr inbounds i8, ptr %1, i64 8\r\n %4 = load i32, ptr %3, align 8, !noundef !5\r\n %5 = insertvalue { ptr, i32 } poison, ptr %2, 0\r\n %6 = insertvalue { ptr, i32 } %5, i32 %4, 1\r\n resume { ptr, i32 } %6\r\n\r\ncleanup: ; preds = %start\r\n %7 = landingpad { ptr, i32 }\r\n cleanup\r\n %8 = extractvalue { ptr, i32 } %7, 0\r\n %9 = extractvalue { ptr, i32 } %7, 1\r\n store ptr %8, ptr %1, align 8\r\n %10 = getelementptr inbounds i8, ptr %1, i64 8\r\n store i32 %9, ptr %10, align 8\r\n br label %bb3\r\n\r\nbb1: ; preds = %start\r\n ret i32 %_0\r\n}\r\n\r\n; core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @\"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he9a486ff76ea726fE\"(ptr align 8 %_1) unnamed_addr #2 {\r\nstart:\r\n ret void\r\n}\r\n\r\n; core::hint::black_box\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @_ZN4core4hint9black_box17h7d48bc7feb0af96eE(ptr sret({ i16, i8, [5 x i8], i64 }) align 8 %_0, ptr align 8 %dummy) unnamed_addr #2 {\r\nstart:\r\n call void @llvm.memcpy.p0.p0.i64(ptr align 8 %_0, ptr align 8 %dummy, i64 16, i1 false)\r\n call void asm sideeffect \"\", \"r,~{memory}\"(ptr %_0), !srcloc !4\r\n ret void\r\n}\r\n\r\n; core::hint::black_box\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @_ZN4core4hint9black_box17ha89c3f9cb79c398cE() unnamed_addr #2 {\r\nstart:\r\n call void asm sideeffect \"\", \"~{memory}\"(), !srcloc !4\r\n ret void\r\n}\r\n\r\n; <() as std::process::Termination>::report\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i8 @\"_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17hb8b4bfb25c4e0e48E\"() unnamed_addr #2 {\r\nstart:\r\n ret i8 0\r\n}\r\n\r\n; _1851685_debug_2::enter\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_25enter17h7e9cae7a334c5019E() unnamed_addr #1 {\r\nstart:\r\n %_3 = alloca [6 x i32], align 4\r\n %_2 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n %0 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_2, i32 0, i32 1\r\n store i8 0, ptr %0, align 2\r\n store i16 0, ptr %_2, align 8\r\n %1 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_2, i32 0, i32 3\r\n store i64 0, ptr %1, align 8\r\n %2 = getelementptr inbounds [6 x i32], ptr %_3, i64 0, i64 0\r\n call void @llvm.memset.p0.i64(ptr align 4 %2, i8 0, i64 24, i1 false)\r\n; call _1851685_debug_2::fn14\r\n call void @_ZN16_1851685_debug_24fn1417h1fc74d4c311bb23aE(ptr align 8 %_2, ptr align 4 %_3)\r\n ret void\r\n}\r\n\r\n; _1851685_debug_2::fn14\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_24fn1417h1fc74d4c311bb23aE(ptr align 8 %_1, ptr align 4 %_2) unnamed_addr #1 {\r\nstart:\r\n %_16 = alloca i8, align 1\r\n %_15 = alloca %Adt58, align 16\r\n %_14 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n %_13 = alloca { { i16, i8, [5 x i8], i64 }, [6 x i32], i32, [1 x i32], [4 x i64] }, align 8\r\n %_12 = alloca %Adt53, align 16\r\n %_10 = alloca %Adt51, align 16\r\n %_7 = alloca %Adt59, align 8\r\n %_5 = alloca i128, align 16\r\n %0 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n store i8 84, ptr %0, align 2\r\n store i16 -25440, ptr %_1, align 8\r\n %1 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n store i64 -9223372036854775808, ptr %1, align 8\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb4, %start\r\n store double 0x41A15ED4AE000000, ptr %_7, align 8\r\n %2 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 4\r\n %3 = load i16, ptr %_1, align 8, !noundef !5\r\n %4 = urem i16 %3, -3470\r\n store i16 %4, ptr %2, align 4\r\n %5 = call { i64, i1 } @llvm.ssub.with.overflow.i64(i64 3029947793098001587, i64 -3638983068927244405)\r\n %6 = extractvalue { i64, i1 } %5, 0\r\n %7 = extractvalue { i64, i1 } %5, 1\r\n store i64 %6, ptr %_10, align 16\r\n %8 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %9 = zext i1 %7 to i8\r\n store i8 %9, ptr %8, align 8\r\n %10 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %11 = load i8, ptr %10, align 8, !range !6, !noundef !5\r\n %12 = trunc i8 %11 to i1\r\n %13 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %14 = load i8, ptr %13, align 8, !range !6, !noundef !5\r\n %15 = trunc i8 %14 to i1\r\n %_9 = xor i1 %12, %15\r\n %16 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 2\r\n store ptr %_10, ptr %16, align 8\r\n %17 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 1\r\n store i64 -1498547728408969452, ptr %17, align 8\r\n %18 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %19 = getelementptr inbounds %Adt50, ptr %18, i32 0, i32 2\r\n %20 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 0\r\n store i32 168516996, ptr %20, align 16\r\n %21 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 1\r\n store i32 245529160, ptr %21, align 4\r\n %22 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 2\r\n store i32 1223136339, ptr %22, align 8\r\n %23 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 3\r\n store i32 1622354325, ptr %23, align 4\r\n %24 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 4\r\n store i32 -1002348909, ptr %24, align 16\r\n %25 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 5\r\n store i32 1976405017, ptr %25, align 4\r\n %26 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 6\r\n store i32 -1442509311, ptr %26, align 8\r\n %27 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 7\r\n store i32 1165829790, ptr %27, align 4\r\n %28 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %29 = getelementptr inbounds %Adt50, ptr %28, i32 0, i32 3\r\n %30 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %29, i32 0, i32 2\r\n %31 = load double, ptr %_7, align 8, !noundef !5\r\n %32 = fneg double %31\r\n store double %32, ptr %30, align 16\r\n %33 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %34 = load i64, ptr %33, align 8, !noundef !5\r\n %_8 = xor i64 %34, -1\r\n store i64 7564290096487423208, ptr %_10, align 16\r\n %35 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %36 = zext i1 %_9 to i8\r\n store i8 %36, ptr %35, align 8\r\n %37 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %38 = getelementptr inbounds %Adt50, ptr %37, i32 0, i32 3\r\n %39 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %38, i32 0, i32 1\r\n store i64 %_8, ptr %39, align 16\r\n %40 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %41 = load i64, ptr %_10, align 16, !noundef !5\r\n store i64 %41, ptr %40, align 8\r\n %42 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %43 = getelementptr inbounds %Adt50, ptr %42, i32 0, i32 3\r\n %44 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %43, i32 0, i32 1\r\n %45 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %44, i32 0, i32 5\r\n; call _1851685_debug_2::fn15\r\n %46 = call i128 @_ZN16_1851685_debug_24fn1517hfe3f07cbb5faefb0E()\r\n store i128 %46, ptr %45, align 16\r\n %47 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %48 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %47, i32 0, i32 1\r\n %49 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %50 = load i64, ptr %49, align 8, !noundef !5\r\n %51 = trunc i64 %50 to i16\r\n store i16 %51, ptr %48, align 16\r\n %52 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 4\r\n %53 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 1\r\n %54 = load i64, ptr %53, align 8, !noundef !5\r\n store i64 %54, ptr %52, align 16\r\n %55 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %56 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %57 = getelementptr inbounds %Adt50, ptr %56, i32 0, i32 3\r\n %58 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %57, i32 0, i32 1\r\n %59 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %58, i32 0, i32 5\r\n %60 = load i128, ptr %59, align 16, !noundef !5\r\n %61 = ashr i128 %60, 0\r\n store i128 %61, ptr %55, align 16\r\n %62 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %63 = getelementptr inbounds %Adt50, ptr %62, i32 0, i32 3\r\n %64 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %63, i32 0, i32 2\r\n %65 = load double, ptr %64, align 16, !noundef !5\r\n %66 = fneg double %65\r\n store double %66, ptr %_7, align 8\r\n %67 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %68 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %67, i32 0, i32 2\r\n %69 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %70 = load i8, ptr %69, align 8, !range !6, !noundef !5\r\n %71 = trunc i8 %70 to i1\r\n %72 = xor i1 %71, true\r\n %73 = zext i1 %72 to i8\r\n store i8 %73, ptr %68, align 2\r\n %74 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %75 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %74, i32 0, i32 4\r\n %76 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %77 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %76, i32 0, i32 1\r\n %78 = load i16, ptr %77, align 16, !noundef !5\r\n %79 = getelementptr inbounds [1 x i16], ptr %75, i64 0, i64 0\r\n store i16 %78, ptr %79, align 4\r\n %80 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %81 = getelementptr inbounds %Adt50, ptr %80, i32 0, i32 1\r\n %82 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %81, i32 0, i32 1\r\n %83 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %84 = load i8, ptr %83, align 2, !noundef !5\r\n store i8 %84, ptr %82, align 2\r\n %85 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 0\r\n store i32 -154507050, ptr %85, align 4\r\n %86 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 1\r\n store i32 2086635898, ptr %86, align 4\r\n %87 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 2\r\n store i32 468582002, ptr %87, align 4\r\n %88 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 3\r\n store i32 -21184342, ptr %88, align 4\r\n %89 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 4\r\n store i32 -1173629817, ptr %89, align 4\r\n %90 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 5\r\n store i32 -2078649110, ptr %90, align 4\r\n %91 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n store i128 0, ptr %91, align 16\r\n %92 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %_12, i32 0, i32 2\r\n %93 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %94 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %93, i32 0, i32 2\r\n %95 = load i8, ptr %94, align 2, !range !6, !noundef !5\r\n %96 = trunc i8 %95 to i1\r\n %97 = zext i1 %96 to i8\r\n store i8 %97, ptr %92, align 2\r\n %98 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %99 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %98, i32 0, i32 1\r\n %100 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %101 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %100, i32 0, i32 1\r\n %102 = load i16, ptr %101, align 16, !noundef !5\r\n %103 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %104 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %103, i32 0, i32 1\r\n %105 = load i16, ptr %104, align 16, !noundef !5\r\n %106 = mul i16 %102, %105\r\n store i16 %106, ptr %99, align 16\r\n %107 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 3\r\n store i32 630181660, ptr %107, align 8\r\n %108 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 3\r\n %109 = load i32, ptr %108, align 8, !noundef !5\r\n %110 = uitofp i32 %109 to double\r\n store double %110, ptr %_7, align 8\r\n %_11 = sub i64 0, %_8\r\n %111 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %112 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %113 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %112, i32 0, i32 1\r\n %114 = load i16, ptr %113, align 16, !noundef !5\r\n %115 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %111, i32 0, i32 1\r\n store i16 %114, ptr %115, align 16\r\n %116 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %117 = load i128, ptr %116, align 16, !noundef !5\r\n store i128 %117, ptr %111, align 16\r\n %118 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %111, i32 0, i32 2\r\n %119 = zext i1 %_9 to i8\r\n store i8 %119, ptr %118, align 2\r\n %120 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %121 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %120, i32 0, i32 4\r\n %122 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %111, i32 0, i32 4\r\n %123 = load i16, ptr %121, align 4\r\n store i16 %123, ptr %122, align 4\r\n %124 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %125 = load i64, ptr %124, align 8, !noundef !5\r\n %126 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %127 = load i64, ptr %126, align 8, !noundef !5\r\n %128 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %125, i64 %127)\r\n %129 = extractvalue { i64, i1 } %128, 0\r\n %130 = extractvalue { i64, i1 } %128, 1\r\n store i64 %129, ptr %_10, align 16\r\n %131 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %132 = zext i1 %130 to i8\r\n store i8 %132, ptr %131, align 8\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb6, %bb1\r\n %133 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %134 = getelementptr inbounds %Adt50, ptr %133, i32 0, i32 3\r\n %135 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %134, i32 0, i32 2\r\n %136 = load double, ptr %_7, align 8, !noundef !5\r\n %137 = fdiv double %136, 0x92917F04BFA33\r\n store double %137, ptr %135, align 16\r\n %138 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 5\r\n store i64 -6496701646011298800, ptr %138, align 8\r\n %139 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %140 = getelementptr inbounds %Adt50, ptr %139, i32 0, i32 1\r\n %141 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %140, i32 0, i32 1\r\n %142 = load i8, ptr %141, align 2, !noundef !5\r\n %143 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n store i8 %142, ptr %143, align 2\r\n %144 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 4\r\n %145 = load i16, ptr %144, align 4, !noundef !5\r\n store i16 %145, ptr %_1, align 8\r\n %146 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n store i64 %_11, ptr %146, align 8\r\n %147 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %148 = getelementptr inbounds %Adt50, ptr %147, i32 0, i32 3\r\n %149 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %148, i32 0, i32 1\r\n %150 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %149, i32 0, i32 2\r\n %151 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 3\r\n %152 = load i32, ptr %151, align 8, !noundef !5\r\n store i32 %152, ptr %150, align 16\r\n %153 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %154 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %153, i32 0, i32 2\r\n %155 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %156 = load i128, ptr %155, align 16, !noundef !5\r\n %157 = icmp sge i128 %156, 0\r\n %158 = zext i1 %157 to i8\r\n store i8 %158, ptr %154, align 2\r\n %159 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %160 = getelementptr inbounds %Adt50, ptr %159, i32 0, i32 1\r\n %161 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %160, i32 0, i32 3\r\n %162 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %163 = load i64, ptr %162, align 8, !noundef !5\r\n %164 = and i64 %163, %_8\r\n store i64 %164, ptr %161, align 8\r\n %165 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 6\r\n %166 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %167 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %166, i32 0, i32 2\r\n %168 = load i8, ptr %167, align 2, !range !6, !noundef !5\r\n %169 = trunc i8 %168 to i1\r\n %170 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 0\r\n %171 = zext i1 %169 to i8\r\n store i8 %171, ptr %170, align 16\r\n %172 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %173 = load i8, ptr %172, align 8, !range !6, !noundef !5\r\n %174 = trunc i8 %173 to i1\r\n %175 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 1\r\n %176 = zext i1 %174 to i8\r\n store i8 %176, ptr %175, align 1\r\n %177 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %_12, i32 0, i32 2\r\n %178 = load i8, ptr %177, align 2, !range !6, !noundef !5\r\n %179 = trunc i8 %178 to i1\r\n %180 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 2\r\n %181 = zext i1 %179 to i8\r\n store i8 %181, ptr %180, align 2\r\n %182 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %_12, i32 0, i32 2\r\n %183 = load i8, ptr %182, align 2, !range !6, !noundef !5\r\n %184 = trunc i8 %183 to i1\r\n %185 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 3\r\n %186 = zext i1 %184 to i8\r\n store i8 %186, ptr %185, align 1\r\n %187 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %188 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %187, i32 0, i32 2\r\n %189 = load i8, ptr %188, align 2, !range !6, !noundef !5\r\n %190 = trunc i8 %189 to i1\r\n %191 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 4\r\n %192 = zext i1 %190 to i8\r\n store i8 %192, ptr %191, align 4\r\n %193 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %194 = load i8, ptr %193, align 8, !range !6, !noundef !5\r\n %195 = trunc i8 %194 to i1\r\n %196 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 5\r\n %197 = zext i1 %195 to i8\r\n store i8 %197, ptr %196, align 1\r\n %198 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %199 = getelementptr inbounds %Adt50, ptr %198, i32 0, i32 3\r\n %200 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %199, i32 0, i32 1\r\n %201 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %200, i32 0, i32 5\r\n %202 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %203 = load i128, ptr %202, align 16, !noundef !5\r\n store i128 %203, ptr %201, align 16\r\n %204 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 2\r\n %205 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %206 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %205, i32 0, i32 1\r\n %207 = load i16, ptr %206, align 16, !noundef !5\r\n %208 = sub i16 0, %207\r\n store i16 %208, ptr %204, align 8\r\n %209 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %210 = getelementptr inbounds %Adt50, ptr %209, i32 0, i32 4\r\n %211 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 1\r\n store ptr %211, ptr %210, align 16\r\n %212 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 5\r\n %213 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %214 = load i8, ptr %213, align 2, !noundef !5\r\n %215 = getelementptr inbounds [1 x i8], ptr %212, i64 0, i64 0\r\n store i8 %214, ptr %215, align 2\r\n %216 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 3\r\n %217 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %218 = getelementptr inbounds %Adt50, ptr %217, i32 0, i32 2\r\n %219 = load <8 x i32>, ptr %218, align 16\r\n store <8 x i32> %219, ptr %216, align 16\r\n %220 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %221 = getelementptr inbounds %Adt50, ptr %220, i32 0, i32 3\r\n %222 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %221, i32 0, i32 1\r\n %223 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %222, i32 0, i32 3\r\n %224 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 5\r\n %225 = load i64, ptr %224, align 8, !noundef !5\r\n %226 = trunc i64 %225 to i32\r\n store i32 %226, ptr %223, align 4\r\n %227 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %228 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %229 = getelementptr inbounds %Adt50, ptr %228, i32 0, i32 1\r\n %230 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %229, i32 0, i32 3\r\n %231 = load i64, ptr %230, align 8, !noundef !5\r\n %232 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %233 = getelementptr inbounds %Adt50, ptr %232, i32 0, i32 3\r\n %234 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %233, i32 0, i32 1\r\n %235 = load i64, ptr %234, align 16, !noundef !5\r\n %236 = xor i64 %231, %235\r\n store i64 %236, ptr %227, align 8\r\n %237 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %238 = getelementptr inbounds %Adt50, ptr %237, i32 0, i32 3\r\n %239 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %238, i32 0, i32 2\r\n %240 = load double, ptr %_7, align 8, !noundef !5\r\n store double %240, ptr %239, align 16\r\n %241 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n %242 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %243 = load i8, ptr %242, align 2, !noundef !5\r\n %244 = xor i8 %243, -1\r\n store i8 %244, ptr %241, align 2\r\n %245 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %246 = getelementptr inbounds %Adt50, ptr %245, i32 0, i32 1\r\n %247 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %248 = load i8, ptr %247, align 8, !range !6, !noundef !5\r\n %249 = trunc i8 %248 to i1\r\n %250 = zext i1 %249 to i16\r\n store i16 %250, ptr %246, align 16\r\n %251 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %252 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %253 = getelementptr inbounds %Adt50, ptr %252, i32 0, i32 3\r\n %254 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %253, i32 0, i32 1\r\n %255 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %254, i32 0, i32 3\r\n %256 = load i32, ptr %255, align 4, !noundef !5\r\n %257 = sext i32 %256 to i128\r\n store i128 %257, ptr %251, align 16\r\n %258 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %259 = getelementptr inbounds %Adt50, ptr %258, i32 0, i32 3\r\n %260 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %259, i32 0, i32 1\r\n %261 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %260, i32 0, i32 3\r\n %262 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %263 = getelementptr inbounds %Adt50, ptr %262, i32 0, i32 1\r\n %264 = load i16, ptr %263, align 16, !noundef !5\r\n %265 = zext i16 %264 to i32\r\n store i32 %265, ptr %261, align 4\r\n br label %bb4\r\n\r\nbb4: ; preds = %bb4, %bb3\r\n %266 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n %267 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %268 = getelementptr inbounds %Adt50, ptr %267, i32 0, i32 3\r\n %269 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %268, i32 0, i32 1\r\n %270 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %269, i32 0, i32 3\r\n %271 = load i32, ptr %270, align 4, !noundef !5\r\n %272 = trunc i32 %271 to i8\r\n store i8 %272, ptr %266, align 2\r\n %273 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n %274 = load i8, ptr %273, align 2, !noundef !5\r\n %275 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_13, i32 0, i32 1\r\n store i8 %274, ptr %275, align 2\r\n %276 = load i16, ptr %_1, align 8, !noundef !5\r\n store i16 %276, ptr %_13, align 8\r\n %277 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %278 = getelementptr inbounds %Adt50, ptr %277, i32 0, i32 1\r\n %279 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %278, i32 0, i32 3\r\n %280 = load i64, ptr %279, align 8, !noundef !5\r\n %281 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_13, i32 0, i32 3\r\n store i64 %280, ptr %281, align 8\r\n %282 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 3\r\n %283 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 4\r\n %284 = load i16, ptr %283, align 4, !noundef !5\r\n %285 = zext i16 %284 to i64\r\n store i64 %285, ptr %282, align 8\r\n %286 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %287 = getelementptr inbounds %Adt50, ptr %286, i32 0, i32 3\r\n %288 = load i64, ptr %_10, align 16, !noundef !5\r\n %289 = sext i64 %288 to i128\r\n store i128 %289, ptr %287, align 16\r\n %290 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %291 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %290, i32 0, i32 2\r\n %292 = load i8, ptr %291, align 2, !range !6, !noundef !5\r\n %293 = trunc i8 %292 to i1\r\n %294 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %295 = load i8, ptr %294, align 8, !range !6, !noundef !5\r\n %296 = trunc i8 %295 to i1\r\n %297 = and i1 %293, %296\r\n %298 = zext i1 %297 to i8\r\n store i8 %298, ptr %_16, align 1\r\n %299 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %300 = getelementptr inbounds { i64, i64, i64 }, ptr %299, i32 0, i32 2\r\n %301 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %302 = load i64, ptr %301, align 8, !noundef !5\r\n %303 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 3\r\n %304 = load i64, ptr %303, align 8, !noundef !5\r\n %305 = xor i64 %302, %304\r\n store i64 %305, ptr %300, align 8\r\n %306 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_13, i32 0, i32 1\r\n %307 = load i8, ptr %306, align 2, !noundef !5\r\n %308 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n store i8 %307, ptr %308, align 2\r\n %309 = load i16, ptr %_1, align 8, !noundef !5\r\n store i16 %309, ptr %_14, align 8\r\n %310 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %311 = getelementptr inbounds { i64, i64, i64 }, ptr %310, i32 0, i32 2\r\n %312 = load i64, ptr %311, align 8, !noundef !5\r\n %313 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 3\r\n store i64 %312, ptr %313, align 8\r\n %314 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %315 = getelementptr inbounds %Adt50, ptr %314, i32 0, i32 5\r\n %316 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %317 = getelementptr inbounds %Adt50, ptr %316, i32 0, i32 3\r\n %318 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %317, i32 0, i32 1\r\n %319 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %318, i32 0, i32 3\r\n %320 = load i32, ptr %319, align 4, !noundef !5\r\n %321 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 0\r\n store i32 %320, ptr %321, align 8\r\n %322 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %323 = getelementptr inbounds %Adt50, ptr %322, i32 0, i32 3\r\n %324 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %323, i32 0, i32 1\r\n %325 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %324, i32 0, i32 3\r\n %326 = load i32, ptr %325, align 4, !noundef !5\r\n %327 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 1\r\n store i32 %326, ptr %327, align 4\r\n %328 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %329 = getelementptr inbounds %Adt50, ptr %328, i32 0, i32 3\r\n %330 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %329, i32 0, i32 1\r\n %331 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %330, i32 0, i32 3\r\n %332 = load i32, ptr %331, align 4, !noundef !5\r\n %333 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 2\r\n store i32 %332, ptr %333, align 8\r\n %334 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %335 = getelementptr inbounds %Adt50, ptr %334, i32 0, i32 3\r\n %336 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %335, i32 0, i32 1\r\n %337 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %336, i32 0, i32 3\r\n %338 = load i32, ptr %337, align 4, !noundef !5\r\n %339 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 3\r\n store i32 %338, ptr %339, align 4\r\n %340 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %341 = getelementptr inbounds %Adt50, ptr %340, i32 0, i32 3\r\n %342 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %341, i32 0, i32 1\r\n %343 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %342, i32 0, i32 3\r\n %344 = load i32, ptr %343, align 4, !noundef !5\r\n %345 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 4\r\n store i32 %344, ptr %345, align 8\r\n %346 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %347 = getelementptr inbounds %Adt50, ptr %346, i32 0, i32 3\r\n %348 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %347, i32 0, i32 1\r\n %349 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %348, i32 0, i32 3\r\n %350 = load i32, ptr %349, align 4, !noundef !5\r\n %351 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 5\r\n store i32 %350, ptr %351, align 4\r\n %352 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %353 = getelementptr inbounds %Adt50, ptr %352, i32 0, i32 3\r\n %354 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %353, i32 0, i32 1\r\n %355 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %354, i32 0, i32 3\r\n %356 = load i32, ptr %355, align 4, !noundef !5\r\n %357 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 6\r\n store i32 %356, ptr %357, align 8\r\n %358 = getelementptr inbounds %Adt50, ptr %_15, i32 0, i32 3\r\n %359 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %358, i32 0, i32 1\r\n %360 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %359, i32 0, i32 5\r\n %361 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %362 = getelementptr inbounds %Adt50, ptr %361, i32 0, i32 3\r\n %363 = load i128, ptr %362, align 16, !noundef !5\r\n store i128 %363, ptr %360, align 16\r\n %364 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %365 = getelementptr inbounds %Adt50, ptr %364, i32 0, i32 3\r\n %366 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %365, i32 0, i32 1\r\n %367 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %366, i32 0, i32 1\r\n %368 = load double, ptr %_7, align 8, !noundef !5\r\n store double %368, ptr %367, align 8\r\n %369 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %370 = getelementptr inbounds %Adt50, ptr %369, i32 0, i32 3\r\n %371 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %370, i32 0, i32 2\r\n %372 = load double, ptr %371, align 16, !noundef !5\r\n store double %372, ptr %_7, align 8\r\n %373 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %374 = load i8, ptr %373, align 2, !noundef !5\r\n switch i8 %374, label %bb4 [\r\n i8 0, label %bb1\r\n i8 84, label %bb5\r\n ]\r\n\r\nbb5: ; preds = %bb4\r\n %375 = getelementptr inbounds %Adt50, ptr %_15, i32 0, i32 3\r\n %376 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %375, i32 0, i32 1\r\n %377 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %376, i32 0, i32 5\r\n %378 = load i128, ptr %377, align 16, !noundef !5\r\n store i128 %378, ptr %_5, align 16\r\n %379 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %380 = load i64, ptr %379, align 8, !noundef !5\r\n store i64 %380, ptr %_10, align 16\r\n %381 = load i8, ptr %_16, align 1, !range !6, !noundef !5\r\n %382 = trunc i8 %381 to i1\r\n %383 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %384 = zext i1 %382 to i8\r\n store i8 %384, ptr %383, align 8\r\n %385 = load i64, ptr %_10, align 16, !noundef !5\r\n switch i64 %385, label %bb8 [\r\n i64 2, label %bb6\r\n i64 7564290096487423208, label %bb7\r\n ]\r\n\r\nbb8: ; preds = %bb7, %bb5\r\n ret void\r\n\r\nbb6: ; preds = %bb5\r\n %386 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %387 = getelementptr inbounds %Adt50, ptr %386, i32 0, i32 1\r\n %388 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %387, i32 0, i32 1\r\n %389 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %390 = load i8, ptr %389, align 2, !noundef !5\r\n store i8 %390, ptr %388, align 2\r\n %391 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %392 = load i64, ptr %391, align 8, !noundef !5\r\n %393 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %394 = load i64, ptr %393, align 8, !noundef !5\r\n %395 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %392, i64 %394)\r\n %396 = extractvalue { i64, i1 } %395, 0\r\n %397 = extractvalue { i64, i1 } %395, 1\r\n store i64 %396, ptr %_10, align 16\r\n %398 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %399 = zext i1 %397 to i8\r\n store i8 %399, ptr %398, align 8\r\n br label %bb3\r\n\r\nbb7: ; preds = %bb5\r\n %400 = load i128, ptr %_5, align 16, !noundef !5\r\n; call _1851685_debug_2::bbox2\r\n call void @_ZN16_1851685_debug_25bbox217he0199f2e11de3e04E(i128 %400, ptr align 8 %_14)\r\n br label %bb8\r\n}\r\n\r\n; _1851685_debug_2::fn15\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal i128 @_ZN16_1851685_debug_24fn1517hfe3f07cbb5faefb0E() unnamed_addr #1 {\r\nstart:\r\n %_0 = alloca i128, align 16\r\n store i128 0, ptr %_0, align 16\r\n; call core::hint::black_box\r\n call void @_ZN4core4hint9black_box17ha89c3f9cb79c398cE()\r\n %0 = load i128, ptr %_0, align 16, !noundef !5\r\n ret i128 %0\r\n}\r\n\r\n; _1851685_debug_2::main\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_24main17he76cece459490d8aE() unnamed_addr #1 {\r\nstart:\r\n; call _1851685_debug_2::enter\r\n call void @_ZN16_1851685_debug_25enter17h7e9cae7a334c5019E()\r\n ret void\r\n}\r\n\r\n; _1851685_debug_2::bbox2\r\n; Function Attrs: noinline nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_25bbox217he0199f2e11de3e04E(i128 %val1, ptr align 8 %val2) unnamed_addr #0 {\r\nstart:\r\n %_6 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n %_5 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n; call _1851685_debug_2::print_i128\r\n call void @_ZN16_1851685_debug_210print_i12817h036b4f930abaf46cE(i128 %val1)\r\n call void @llvm.memcpy.p0.p0.i64(ptr align 8 %_6, ptr align 8 %val2, i64 16, i1 false)\r\n; call core::hint::black_box\r\n call void @_ZN4core4hint9black_box17h7d48bc7feb0af96eE(ptr sret({ i16, i8, [5 x i8], i64 }) align 8 %_5, ptr align 8 %_6)\r\n ret void\r\n}\r\n\r\n; _1851685_debug_2::print_i128\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_210print_i12817h036b4f930abaf46cE(i128 %x) unnamed_addr #1 {\r\nstart:\r\n %_9 = lshr i128 %x, 64\r\n %_8 = trunc i128 %_9 to i64\r\n %_14 = trunc i128 %x to i64\r\n %_2 = call i32 (ptr, ...) @printf(ptr @alloc_2cdd8ac758b4c372b56d8683306290e0, i64 %_8, i64 %_14)\r\n ret void\r\n}\r\n\r\n; Function Attrs: nonlazybind uwtable\r\ndefine i32 @rust_eh_personality(i32, i32, i64, ptr, ptr) unnamed_addr #1 {\r\nstart:\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3\r\n\r\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\r\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i64, i1 } @llvm.ssub.with.overflow.i64(i64, i64) #5\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i64, i1 } @llvm.smul.with.overflow.i64(i64, i64) #5\r\n\r\n; Function Attrs: nonlazybind uwtable\r\ndeclare i32 @printf(ptr, ...) unnamed_addr #1\r\n\r\n; Function Attrs: nonlazybind\r\ndefine i32 @main(i32 %0, ptr %1) unnamed_addr #6 {\r\ntop:\r\n call void @_ZN16_1851685_debug_25enter17h7e9cae7a334c5019E()\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { noinline nonlazybind uwtable \"probe-stack\"=\"inline-asm\" \"target-cpu\"=\"x86-64\" }\r\nattributes #1 = { nonlazybind uwtable \"probe-stack\"=\"inline-asm\" \"target-cpu\"=\"x86-64\" }\r\nattributes #2 = { inlinehint nonlazybind uwtable \"probe-stack\"=\"inline-asm\" \"target-cpu\"=\"x86-64\" }\r\nattributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\r\nattributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }\r\nattributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #6 = { nonlazybind \"target-cpu\"=\"x86-64\" }\r\n\r\n!llvm.module.flags = !{!0, !1, !2}\r\n!llvm.ident = !{!3}\r\n\r\n!0 = !{i32 8, !\"PIC Level\", i32 2}\r\n!1 = !{i32 7, !\"PIE Level\", i32 2}\r\n!2 = !{i32 2, !\"RtLibUseGOT\", i32 1}\r\n!3 = !{!\"rustc version 1.78.0-dev\"}\r\n!4 = !{i32 753499}\r\n!5 = !{}\r\n!6 = !{i8 0, i8 2}\r\n\r\n```\r\n\r\nRight:\r\n```console\r\n$ clang -O1 1851685_debug_2.ll && ./a.out\r\nhi:-1 lo:-2580139605333929408\r\n```\r\n\r\nWrong:\r\n```console\r\n$ clang -O2 1851685_debug_2.ll && ./a.out\r\nhi:0 lo:-2580139605333929408\r\n```\r\n\r\nBisects down to \r\n```\r\nBISECT: running pass (504) InstCombinePass on _ZN16_1851685_debug_25enter17h7e9cae7a334c5019E\r\n```\r\n\r\nVersion:\r\n```\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git cd1d4d8dd31f527615de26f5b62d687c6b2982a6)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /opt/compiler-explorer/clang-trunk/bin\r\nCompiler returned: 0\r\n```\r\n\r\n\r\n<details>\r\n<summary>From Rust custom MIR</summary>\r\n\r\n```rust\r\n#![feature(custom_mir, core_intrinsics)]\r\nextern crate core;\r\nuse core::intrinsics::mir::*;\r\n\r\npub fn enter() {\r\n fn14((0, 0, 0), [0; 6]);\r\n}\r\n\r\n#[custom_mir(dialect = \"runtime\", phase = \"initial\")]\r\npub fn fn14(mut _3: (i8, u16, isize), mut _6: [i32; 6]) {\r\n mir! {\r\n let _1: u128;\r\n let _2: i128;\r\n let _4: (i128,);\r\n let _5: i128;\r\n let _9: Adt59;\r\n let _11: isize;\r\n let _12: bool;\r\n let _13: Adt51;\r\n let _15: isize;\r\n let _16: Adt53;\r\n let _21: (i32, [i32; 6], (i8, u16, isize), [usize; 4]);\r\n let _23: (i8, u16, isize);\r\n let _25: Adt58;\r\n let _26: Adt52;\r\n let _44: ();\r\n {\r\n _2 = 0;\r\n _5 = 0;\r\n _3 = (84_i8, 40096_u16, (-9223372036854775808_isize));\r\n Goto(bb2)\r\n }\r\n bb1 = {\r\n Return()\r\n }\r\n bb2 = {\r\n _9.fld3.1.0.0 = 145713751_u32 as f64;\r\n _9.fld5 = _3.1 % 62066_u16;\r\n _13.fld1 = Checked(3029947793098001587_i64 - (-3638983068927244405_i64));\r\n _12 = _13.fld1.1 ^ _13.fld1.1;\r\n _9.fld6 = core::ptr::addr_of!(_13.fld1);\r\n _9.fld4 = (16948196345300582164_u64,);\r\n _13.fld3.fld4 = [168516996_i32,245529160_i32,1223136339_i32,1622354325_i32,(-1002348909_i32),1976405017_i32,(-1442509311_i32),1165829790_i32];\r\n _13.fld3.fld6.1 = -_9.fld3.1.0.0;\r\n _11 = !_3.2;\r\n _13.fld1 = (7564290096487423208_i64, _12);\r\n _13.fld3.fld6.2.0 = _11;\r\n _9.fld3.2.0 = _13.fld1.0;\r\n Call(_13.fld3.fld6.2.4 = fn15(), ReturnTo(bb3), UnwindUnreachable())\r\n }\r\n bb3 = {\r\n _13.fld0.0 = _9.fld3.2.0 as i16;\r\n _13.fld2 = _9.fld4.0 as isize;\r\n _13.fld3.fld5.1.0 = _13.fld3.fld6.2.4.0 >> _2;\r\n _9.fld3.1.0.0 = -_13.fld3.fld6.1;\r\n _13.fld0.2 = !_13.fld1.1;\r\n _13.fld3.fld5.3 = [_13.fld0.0];\r\n Goto(bb4)\r\n }\r\n bb4 = {\r\n _13.fld3.fld3.0 = _3.0;\r\n _6 = [(-154507050_i32),2086635898_i32,468582002_i32,(-21184342_i32),(-1173629817_i32),(-2078649110_i32)];\r\n _13.fld3.fld5.1.0 = _5;\r\n _16.fld0.2 = _13.fld0.2;\r\n _13.fld3.fld5.0 = _13.fld0.0 * _13.fld0.0;\r\n _9.fld2 = 2797771210_u32 + 2127377746_u32;\r\n _9.fld3.1.0.0 = _9.fld2 as f64;\r\n _15 = -_11;\r\n _13.fld0 = (_13.fld3.fld5.0, _13.fld3.fld5.1, _12, _13.fld3.fld5.3);\r\n _13.fld1 = Checked(_9.fld3.2.0 * _9.fld3.2.0);\r\n Goto(bb5)\r\n }\r\n bb5 = {\r\n _13.fld3.fld6.1 = _9.fld3.1.0.0 / 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012739273109665954_f64;\r\n _13.fld4 = !6496701646011298799_usize;\r\n _3 = (_13.fld3.fld3.0, _9.fld5, _15);\r\n _13.fld3.fld6.2.1 = _9.fld2;\r\n _13.fld0.2 = _13.fld0.1.0 >= _5;\r\n _13.fld3.fld3.2 = _3.2 & _11;\r\n _13.fld6 = [_13.fld0.2,_13.fld1.1,_16.fld0.2,_16.fld0.2,_13.fld0.2,_13.fld1.1];\r\n _13.fld3.fld6.2.4 = _13.fld3.fld5.1;\r\n _9.fld3.0 = -_13.fld0.0;\r\n _13.fld3.fld0 = core::ptr::addr_of!(_9.fld4.0);\r\n _9.fld0 = [_3.0];\r\n _13.fld5 = _13.fld3.fld4;\r\n _13.fld3.fld6.2.3 = _13.fld4 as i32;\r\n _3.2 = _13.fld3.fld3.2 ^ _13.fld3.fld6.2.0;\r\n _13.fld3.fld6.1 = _9.fld3.1.0.0;\r\n _23.0 = !_3.0;\r\n _13.fld3.fld3.1 = _13.fld1.1 as u16;\r\n _13.fld3.fld5.1.0 = _13.fld3.fld6.2.3 as i128;\r\n _13.fld3.fld6.2.3 = _13.fld3.fld3.1 as i32;\r\n Goto(bb7)\r\n }\r\n bb7 = {\r\n _23.0 = _13.fld3.fld6.2.3 as i8;\r\n _21.2 = (_23.0, _3.1, _13.fld3.fld3.2);\r\n _23.2 = _9.fld5 as isize;\r\n _13.fld3.fld6.0 = _13.fld1.0 as i128;\r\n _26.fld0 = _13.fld0.2 & _13.fld1.1;\r\n _9.fld3.2.2 = _3.2 ^ _23.2;\r\n _23 = (_21.2.0, _3.1, _9.fld3.2.2);\r\n _13.fld3.fld2 = [_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3];\r\n _25.fld3.fld6.2.4 = (_13.fld3.fld6.0,);\r\n _13.fld3.fld6.2.2 = _9.fld3.1.0.0;\r\n _9.fld3.1.0.0 = _13.fld3.fld6.1;\r\n match _3.0 {\r\n 0 => bb2,\r\n 84 => bb10,\r\n _ => bb7\r\n }\r\n }\r\n bb10 = {\r\n _4 = (_25.fld3.fld6.2.4.0,);\r\n _13.fld1 = (_9.fld3.2.0, _26.fld0);\r\n match _13.fld1.0 {\r\n 2 => bb14,\r\n 7564290096487423208 => bb18,\r\n _ => bb19\r\n }\r\n }\r\n bb14 = {\r\n _13.fld3.fld3.0 = _3.0;\r\n _13.fld1 = Checked(_9.fld3.2.0 * _9.fld3.2.0);\r\n Goto(bb5)\r\n }\r\n bb18 = {\r\n Call(_44 = bbox2(_4, Move(_23)), ReturnTo(bb19), UnwindUnreachable())\r\n }\r\n bb19 = {\r\n Return()\r\n }\r\n\r\n }\r\n}\r\n\r\n#[custom_mir(dialect = \"runtime\", phase = \"initial\")]\r\nfn fn15() -> (i128,) {\r\n mir! {\r\n let unit:();\r\n let _37: ();\r\n {\r\n RET = (0,);\r\n Call(_37 = core::hint::black_box(unit), ReturnTo(bb16), UnwindUnreachable())\r\n }\r\n bb16 = {\r\n Return()\r\n }\r\n\r\n }\r\n}\r\npub fn main() {\r\n enter();\r\n}\r\n\r\n#[derive(Debug)]\r\npub struct Adt49 {}\r\n#[derive(Debug)]\r\npub struct Adt50 {\r\n fld0: *const u64,\r\n fld2: [i32; 7],\r\n fld3: (i8, u16, isize),\r\n fld4: [i32; 8],\r\n fld5: (i16, (i128,), bool, [i16; 1]),\r\n fld6: (i128, f64, (isize, u32, f64, i32, (i128,)), [i32; 6]),\r\n}\r\n#[derive(Debug)]\r\npub struct Adt51 {\r\n fld0: (i16, (i128,), bool, [i16; 1]),\r\n fld1: (i64, bool),\r\n fld2: isize,\r\n fld3: Adt50,\r\n fld4: usize,\r\n fld5: [i32; 8],\r\n fld6: [bool; 6],\r\n}\r\n#[derive(Debug)]\r\npub struct Adt52 {\r\n fld0: bool,\r\n}\r\n#[derive(Debug)]\r\npub struct Adt53 {\r\n fld0: (i16, (i128,), bool, [i16; 1]),\r\n}\r\n#[derive(Debug)]\r\npub struct Adt58 {\r\n fld3: Adt50,\r\n}\r\n#[derive(Debug, Copy, Clone)]\r\npub struct Adt59 {\r\n fld0: [i8; 1],\r\n fld2: u32,\r\n fld3: (i16, ((f64,),), (i64, isize, isize), u8),\r\n fld4: (u64,),\r\n fld5: u16,\r\n fld6: *const (i64, bool),\r\n}\r\n\r\n#[inline(never)]\r\npub fn bbox2(val1: (i128,), val2: (i8, u16, isize)) {\r\n use core::hint::black_box;\r\n print_i128(val1.0);\r\n black_box(val2);\r\n}\r\n\r\n#[cfg(not(miri))]\r\nfn print_i128(x: i128) {\r\n extern \"C\" {\r\n fn printf(fmt: *const core::ffi::c_char, ...) -> core::ffi::c_int;\r\n }\r\n unsafe {\r\n printf(\r\n b\"hi:%ld lo:%ld\\n\\0\".as_ptr().cast(),\r\n (x as u128 >> 64) as i64,\r\n x as i64,\r\n );\r\n }\r\n}\r\n\r\n#[cfg(miri)]\r\nfn print_i128(x: i128) {\r\n println!(\"hi:{} lo:{}\", (x as u128 >> 64) as i64, x as i64);\r\n}\r\n\r\n```\r\n\r\n</details>\r\n", "author": "cbeuw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/xs1rhnMvb\r\nAlive2: https://alive2.llvm.org/ce/z/gyL7mn\r\n\r\nI will post a fix later.\r\n" } ] }
true
null
77468
https://github.com/llvm/llvm-project/issues/77468
crash
39b2104b4a4e0990eddc763eab99b28e8deab953
2024-01-09T13:19:28
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "59d6f033a25d161e494457e8bb6e30375eb7f40f", "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": [ [ 895, 901 ], [ 948, 953 ], [ 979, 995 ] ], "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": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::truncateToMinimalBitwidths" ], "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 59d6f033a25d161e494457e8bb6e30375eb7f40f Author: Florian Hahn <[email protected]> Date: Fri Jan 12 13:14:13 2024 +0000 [VPlan] Support narrowing widened loads in truncateToMinimimalBitwidths. MinBWs may also contain widened load instructions, handle them by only narrowing their result. Fixes https://github.com/llvm/llvm-project/issues/77468 diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 5c430620a2dc..b3694e74a385 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -895,7 +895,10 @@ void VPlanTransforms::truncateToMinimalBitwidths( vp_depth_first_deep(Plan.getVectorLoopRegion()))) { for (VPRecipeBase &R : make_early_inc_range(*VPBB)) { if (!isa<VPWidenRecipe, VPWidenCastRecipe, VPReplicateRecipe, - VPWidenSelectRecipe>(&R)) + VPWidenSelectRecipe, VPWidenMemoryInstructionRecipe>(&R)) + continue; + if (isa<VPWidenMemoryInstructionRecipe>(&R) && + cast<VPWidenMemoryInstructionRecipe>(&R)->isStore()) continue; VPValue *ResultVPV = R.getVPSingleValue(); @@ -948,6 +951,23 @@ void VPlanTransforms::truncateToMinimalBitwidths( auto *NewResTy = IntegerType::get(Ctx, NewResSizeInBits); + // Any wrapping introduced by shrinking this operation shouldn't be + // considered undefined behavior. So, we can't unconditionally copy + // arithmetic wrapping flags to VPW. + if (auto *VPW = dyn_cast<VPRecipeWithIRFlags>(&R)) + VPW->dropPoisonGeneratingFlags(); + + // Extend result to original width. + auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy); + Ext->insertAfter(&R); + ResultVPV->replaceAllUsesWith(Ext); + Ext->setOperand(0, ResultVPV); + + if (isa<VPWidenMemoryInstructionRecipe>(&R)) { + assert(!cast<VPWidenMemoryInstructionRecipe>(&R)->isStore() && "stores cannot be narrowed"); + continue; + } + // Shrink operands by introducing truncates as needed. unsigned StartIdx = isa<VPWidenSelectRecipe>(&R) ? 1 : 0; for (unsigned Idx = StartIdx; Idx != R.getNumOperands(); ++Idx) { @@ -979,17 +999,6 @@ void VPlanTransforms::truncateToMinimalBitwidths( } } - // Any wrapping introduced by shrinking this operation shouldn't be - // considered undefined behavior. So, we can't unconditionally copy - // arithmetic wrapping flags to VPW. - if (auto *VPW = dyn_cast<VPRecipeWithIRFlags>(&R)) - VPW->dropPoisonGeneratingFlags(); - - // Extend result to original width. - auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy); - Ext->insertAfter(&R); - ResultVPV->replaceAllUsesWith(Ext); - Ext->setOperand(0, ResultVPV); } }
[ { "file": "llvm/test/Transforms/LoopVectorize/trunc-loads-p16.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "pr77468", "test_body": "target datalayout = \"p:16:16\"\n\ndefine void @pr77468(ptr noalias %src, ptr noalias %dst, i1 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr i32, ptr %src, i16 %iv\n %l = load i32, ptr %gep.src, align 1\n %x.ext = zext i1 %x to i32\n %and = and i32 %x.ext, %l\n %gep.dst = getelementptr i16, ptr %dst, i16 %iv\n %t = trunc i32 %and to i16\n store i16 %t, ptr %gep.dst, align 2\n %iv.next = add i16 %iv, 1\n %exitcond.not = icmp eq i16 %iv.next, 100\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `MinBWs.size() == NumProcessedRecipes && \"some entries in MinBWs haven't been processed\"' failed. for opt -passes=loop-vectorize", "body": "llvm commit: c1ed45a271145\r\nReproduce with: ```opt -passes=\"loop-vectorize\" bbi-90681_2.ll -S -o /dev/null -mtriple=x86_64```\r\nResult:\r\n```\r\nopt: ../lib/Transforms/Vectorize/VPlanTransforms.cpp:997: static void llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan &, const MapVector<llvm::Instruction *, uint64_t> &, llvm::LLVMContext &): Assertion `MinBWs.size() == NumProcessedRecipes && \"some entries in MinBWs haven't been processed\"' 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: ../../main-github/llvm/build-all/bin/opt -passes=loop-vectorize bbi-90681_2.ll -S -o /dev/null -mtriple=x86_64\r\n #0 0x0000563bdd2b15d7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x63c95d7)\r\n #1 0x0000563bdd2af12e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x63c712e)\r\n #2 0x0000563bdd2b1c9f SignalHandler(int) (../../main-github/llvm/build-all/bin/opt+0x63c9c9f)\r\n #3 0x00007f87a7de7630 __restore_rt (/lib64/libpthread.so.0+0xf630)\r\n #4 0x00007f87a552e387 raise (/lib64/libc.so.6+0x36387)\r\n #5 0x00007f87a552fa78 abort (/lib64/libc.so.6+0x37a78)\r\n #6 0x00007f87a55271a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)\r\n #7 0x00007f87a5527252 (/lib64/libc.so.6+0x2f252)\r\n #8 0x0000563bdd584d86 (../../main-github/llvm/build-all/bin/opt+0x669cd86)\r\n #9 0x0000563bdd50f875 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (../../main-github/llvm/build-all/bin/opt+0x6627875)\r\n#10 0x0000563bdd50eeec llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (../../main-github/llvm/build-all/bin/opt+0x6626eec)\r\n#11 0x0000563bdd522bc9 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (../../main-github/llvm/build-all/bin/opt+0x663abc9)\r\n#12 0x0000563bdd5289b3 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*) (../../main-github/llvm/build-all/bin/opt+0x66409b3)\r\n#13 0x0000563bdd529318 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x6641318)\r\n#14 0x0000563bdd4cafad llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x65e2fad)\r\n#15 0x0000563bdcce36d4 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x5dfb6d4)\r\n#16 0x0000563bdb09c87d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x41b487d)\r\n#17 0x0000563bdcce7abe llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x5dffabe)\r\n#18 0x0000563bdb09c61d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x41b461d)\r\n#19 0x0000563bdcce27f6 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x5dfa7f6)\r\n#20 0x0000563bdabb7143 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) (../../main-github/llvm/build-all/bin/opt+0x3ccf143)\r\n#21 0x0000563bdabc5844 main (../../main-github/llvm/build-all/bin/opt+0x3cdd844)\r\n#22 0x00007f87a551a555 __libc_start_main (/lib64/libc.so.6+0x22555)\r\n#23 0x0000563bdabb12e9 _start (../../main-github/llvm/build-all/bin/opt+0x3cc92e9)\r\nAbort (core dumped)\r\n```\r\n[bbi-90681_2.ll.gz](https://github.com/llvm/llvm-project/files/13874170/bbi-90681_2.ll.gz)\r\n", "author": "mikaelholmen", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "mikaelholmen", "body": "This starts happening with 70535f5e609f747c28\r\n```\r\n[VPlan] Replace IR based truncateToMinimalBitwidths with VPlan version.\r\n```\r\nPing @fhahn \r\n" }, { "author": "mikaelholmen", "body": "Thanks!" } ] }
true
null
88849
https://github.com/llvm/llvm-project/issues/88849
crash
6b98ab95f0d36705b5a1fc1e755c992ba2329c89
2024-04-16T07:36:13
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "b8741cc185e89a95c9161218084f7c8b5578cf96", "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": [ [ 254, 259 ] ], "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 b8741cc185e89a95c9161218084f7c8b5578cf96 Author: Florian Hahn <[email protected]> Date: Fri Jul 19 10:33:07 2024 +0100 [VPlan] Relax assertion retrieving a scalar from VPTransformState::get. The current assertion VPTransformState::get when retrieving a single scalar only does not account for cases where a def has multiple users, some demanding all scalar lanes, some demanding only a single scalar. For an example, see the modified test case. Relax the assertion by also allowing requesting scalar lanes only when the Def doesn't have only its first lane used. Fixes https://github.com/llvm/llvm-project/issues/88849. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index 83a035fb4df8..58de6256900f 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -254,6 +254,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() || hasVectorValue(Def, Part) || + !vputils::onlyFirstLaneUsed(Def) || (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/SystemZ/scalar-steps-with-users-demanding-all-lanes-and-first-lane-only.ll", "commands": [ "opt -p loop-vectorize -mtriple=s390x-unknown-linux -mcpu=z16 -S %s" ], "tests": [ { "test_name": "test_scalar_iv_steps_used_by_replicate_and_first_lane_only_vpinst", "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\n@src = external global [8 x i32], align 4\n\ndefine void @test_scalar_iv_steps_used_by_replicate_and_first_lane_only_vpinst(ptr noalias %dst, ptr noalias %src.1) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %mul.iv = mul nsw i64 %iv, 4\n %gep.src.1 = getelementptr inbounds i8, ptr %src.1, i64 %mul.iv\n %l.1 = load i8, ptr %gep.src.1, align 1\n %c = icmp eq i8 %l.1, 0\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %iv.or = or disjoint i64 %iv, 4\n %gep.src = getelementptr inbounds [8 x i32], ptr @src, i64 0, i64 %iv.or\n %l.2 = load i32, ptr %gep.src, align 4\n store i32 %l.2, ptr %dst, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 4\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "LoopVectorizer asserts: Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.", "body": "[tc_crash35_aftercreduce.ll.tar.gz](https://github.com/llvm/llvm-project/files/14988465/tc_crash35_aftercreduce.ll.tar.gz)\r\n\r\nopt -mtriple=s390x-unknown-linux -mcpu=z16 -O3 tc_crash35_aftercreduce.ll -o /dev/null\r\n\r\nVPlan.cpp:253: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\n\r\n@fhahn ", "author": "JonPsson1", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Should be fixed now, sorry for the delay @JonPsson1 !" } ] }
true
null
106655
https://github.com/llvm/llvm-project/issues/106655
crash
2d5613afec0f4afeeb03cfd4edac556a65ad0eaf
2024-08-30T03:04:59
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "87a988e881ac92e3d87aae01dc632f33c1fb36aa", "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": [ [ 13137, 13143 ], [ 13197, 13203 ], [ 13249, 13255 ], [ 13259, 13265 ], [ 13474, 13480 ], [ 13518, 13524 ], [ 13571, 13577 ], [ 13593, 13599 ], [ 13611, 13617 ], [ 13655, 13661 ], [ 13688, 13694 ], [ 13780, 13786 ], [ 13794, 13800 ], [ 13859, 13865 ], [ 13941, 13947 ], [ 14039, 14044 ] ], "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" ], "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 87a988e881ac92e3d87aae01dc632f33c1fb36aa Author: Alexey Bataev <[email protected]> Date: Fri Aug 30 05:16:57 2024 -0700 [SLP]Fix PR106655: Use FinalShuffle for alternate cast nodes. Need to use FinalShuffle function for all vectorized results to correctly produce vectorized value. Fixes https://github.com/llvm/llvm-project/issues/106655 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index edb2567fa057..345b01b82c6a 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13137,7 +13137,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { } bool IsReverseOrder = isReverseOrder(E->ReorderIndices); - auto FinalShuffle = [&](Value *V, const TreeEntry *E, VectorType *VecTy) { + auto FinalShuffle = [&](Value *V, const TreeEntry *E) { ShuffleInstructionBuilder ShuffleBuilder(ScalarTy, Builder, *this); if (E->getOpcode() == Instruction::Store && E->State == TreeEntry::Vectorize) { @@ -13197,7 +13197,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { PH->getParent()->getFirstInsertionPt()); Builder.SetCurrentDebugLocation(PH->getDebugLoc()); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; if (PostponedPHIs) @@ -13249,7 +13249,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { if (const TreeEntry *TE = getTreeEntry(V)) V = TE->VectorizedValue; setInsertPointAfterBundle(E); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; return V; } @@ -13259,7 +13259,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *Ptr = LI->getPointerOperand(); LoadInst *V = Builder.CreateAlignedLoad(VecTy, Ptr, LI->getAlign()); Value *NewV = propagateMetadata(V, E->Scalars); - NewV = FinalShuffle(NewV, E, VecTy); + NewV = FinalShuffle(NewV, E); E->VectorizedValue = NewV; return NewV; } @@ -13474,7 +13474,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *V = (VecOpcode != ShuffleOrOp && VecOpcode == Instruction::BitCast) ? InVec : Builder.CreateCast(VecOpcode, InVec, VecTy); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13518,7 +13518,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { propagateIRFlags(V, E->Scalars, VL0); // Do not cast for cmps. VecTy = cast<FixedVectorType>(V->getType()); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13571,7 +13571,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { assert(getNumElements(Cond->getType()) == TrueNumElements && "Cannot vectorize Instruction::Select"); Value *V = Builder.CreateSelect(Cond, True, False); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13593,7 +13593,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { if (auto *I = dyn_cast<Instruction>(V)) V = propagateMetadata(I, E->Scalars); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13611,7 +13611,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { } Value *V = Builder.CreateFreeze(Op); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13655,7 +13655,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { auto *CI = dyn_cast<ConstantInt>(Op); return CI && CI->getValue().countr_one() >= It->second.first; })) { - V = FinalShuffle(I == 0 ? RHS : LHS, E, VecTy); + V = FinalShuffle(I == 0 ? RHS : LHS, E); E->VectorizedValue = V; ++NumVectorInstructions; return V; @@ -13688,7 +13688,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { I->setHasNoUnsignedWrap(/*b=*/false); } - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13780,7 +13780,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { } Value *V = propagateMetadata(NewLI, E->Scalars); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; return V; @@ -13794,7 +13794,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { if (VecValue->getType() != VecTy) VecValue = Builder.CreateIntCast(VecValue, VecTy, GetOperandSignedness(0)); - VecValue = FinalShuffle(VecValue, E, VecTy); + VecValue = FinalShuffle(VecValue, E); Value *Ptr = SI->getPointerOperand(); Instruction *ST; @@ -13859,7 +13859,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { V = propagateMetadata(I, GEPs); } - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13941,7 +13941,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *V = Builder.CreateCall(CF, OpVecs, OpBundles); propagateIRFlags(V, E->Scalars, VL0); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -14039,6 +14039,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { "Expected same type as operand."); if (auto *I = dyn_cast<Instruction>(LHS)) LHS = propagateMetadata(I, E->Scalars); + LHS = FinalShuffle(LHS, E); E->VectorizedValue = LHS; ++NumVectorInstructions; return LHS;
[ { "file": "llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-vectorize-hor=false < %s" ], "tests": [ { "test_name": "func", "test_body": "define void @func(i32 %0) {\n %2 = shl i32 %0, 0\n %3 = sext i32 %2 to i64\n %4 = shl i32 0, 0\n %5 = sext i32 %4 to i64\n %6 = or i32 0, 0\n %7 = or i32 0, 0\n %8 = zext i32 %6 to i64\n %9 = zext i32 %7 to i64\n %10 = zext i32 0 to i64\n %11 = zext i32 0 to i64\n %12 = zext i32 0 to i64\n %13 = zext i32 0 to i64\n %14 = zext i32 0 to i64\n %15 = zext i32 0 to i64\n %16 = zext i32 0 to i64\n %17 = zext i32 0 to i64\n %18 = zext i32 0 to i64\n %19 = zext i32 0 to i64\n %20 = zext i32 0 to i64\n %21 = zext i32 0 to i64\n %22 = zext i32 0 to i64\n %23 = zext i32 0 to i64\n %24 = zext i32 0 to i64\n %25 = zext i32 0 to i64\n %26 = zext i32 0 to i64\n %27 = or i64 %3, 0\n %28 = or i64 %3, %8\n %29 = or i64 %3, %9\n %30 = or i64 %3, %10\n %31 = or i64 %3, %11\n %32 = or i64 %3, %12\n %33 = or i64 %3, %13\n %34 = or i64 %3, %14\n %35 = or i64 %3, %15\n %36 = or i64 %3, %16\n %37 = or i64 %3, %17\n %38 = or i64 %3, %18\n %39 = or i64 %3, %19\n %40 = or i64 %3, %20\n %41 = or i64 %3, %21\n %42 = or i64 %3, %22\n %43 = or i64 %3, %23\n %44 = or i64 %3, %24\n %45 = or i64 %3, %25\n %46 = or i64 %3, 0\n %47 = or i64 %3, 0\n %48 = or i64 %3, 0\n %49 = or i64 %3, 0\n %50 = or i64 %3, 0\n %51 = or i64 %3, 0\n %52 = or i64 %3, 0\n %53 = or i64 %3, 0\n %54 = or i64 %3, 0\n %55 = or i64 %3, 0\n %56 = or i64 %3, 0\n %57 = or i64 %3, 0\n %58 = or i64 %3, 0\n %59 = icmp slt i64 %28, 0\n %60 = icmp slt i64 %29, 0\n %61 = icmp slt i64 %30, 0\n %62 = icmp slt i64 %31, 0\n %63 = icmp slt i64 %32, 0\n %64 = icmp slt i64 %33, 0\n %65 = icmp slt i64 %34, 0\n %66 = icmp slt i64 %35, 0\n %67 = icmp slt i64 %36, 0\n %68 = icmp slt i64 %37, 0\n %69 = icmp slt i64 %38, 0\n %70 = icmp slt i64 %39, 0\n %71 = icmp slt i64 %40, 0\n %72 = icmp slt i64 %41, 0\n %73 = icmp slt i64 %42, 0\n %74 = icmp slt i64 %43, 0\n %75 = icmp slt i64 %44, 0\n %76 = icmp slt i64 %45, 0\n %77 = icmp slt i64 %46, 0\n %78 = icmp slt i64 %47, 0\n %79 = icmp slt i64 %48, 0\n %80 = icmp slt i64 %49, 0\n %81 = icmp slt i64 %50, 0\n %82 = icmp slt i64 %51, 0\n %83 = icmp slt i64 %52, 0\n %84 = icmp slt i64 %53, 0\n %85 = icmp slt i64 %54, 0\n %86 = icmp slt i64 %55, 0\n %87 = icmp slt i64 %56, 0\n %88 = icmp slt i64 %57, 0\n %89 = icmp slt i64 %58, 0\n %90 = and i1 false, %59\n %91 = and i1 false, %60\n %92 = and i1 false, %61\n %93 = and i1 false, %62\n %94 = and i1 false, %63\n %95 = and i1 false, %64\n %96 = and i1 false, %65\n %97 = and i1 false, %66\n %98 = and i1 false, %67\n %99 = and i1 false, %68\n %100 = and i1 false, %69\n %101 = and i1 false, %70\n %102 = and i1 false, %71\n %103 = and i1 false, %72\n %104 = and i1 false, %73\n %105 = and i1 false, %74\n %106 = and i1 false, %75\n %107 = and i1 false, %76\n %108 = icmp eq i32 %2, 0\n %109 = and i1 false, %77\n %110 = and i1 false, %78\n %111 = and i1 false, %79\n %112 = and i1 false, %80\n %113 = and i1 false, %81\n %114 = and i1 false, %82\n %115 = and i1 false, %83\n %116 = and i1 false, %84\n %117 = and i1 false, %85\n %118 = and i1 false, %86\n %119 = or i64 %5, %26\n %120 = getelementptr float, ptr addrspace(1) null, i64 %119\n %121 = icmp slt i64 %119, 0\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP] Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.", "body": "Live link: https://godbolt.org/z/nePMscjGr\r\n\r\nTest case:\r\n\r\n```ll\r\ndefine void @func(i32 %0) {\r\n %2 = shl i32 %0, 0\r\n %3 = sext i32 %2 to i64\r\n %4 = shl i32 0, 0\r\n %5 = sext i32 %4 to i64\r\n %6 = or i32 0, 0\r\n %7 = or i32 0, 0\r\n %8 = zext i32 %6 to i64\r\n %9 = zext i32 %7 to i64\r\n %10 = zext i32 0 to i64\r\n %11 = zext i32 0 to i64\r\n %12 = zext i32 0 to i64\r\n %13 = zext i32 0 to i64\r\n %14 = zext i32 0 to i64\r\n %15 = zext i32 0 to i64\r\n %16 = zext i32 0 to i64\r\n %17 = zext i32 0 to i64\r\n %18 = zext i32 0 to i64\r\n %19 = zext i32 0 to i64\r\n %20 = zext i32 0 to i64\r\n %21 = zext i32 0 to i64\r\n %22 = zext i32 0 to i64\r\n %23 = zext i32 0 to i64\r\n %24 = zext i32 0 to i64\r\n %25 = zext i32 0 to i64\r\n %26 = zext i32 0 to i64\r\n %27 = or i64 %3, 0\r\n %28 = or i64 %3, %8\r\n %29 = or i64 %3, %9\r\n %30 = or i64 %3, %10\r\n %31 = or i64 %3, %11\r\n %32 = or i64 %3, %12\r\n %33 = or i64 %3, %13\r\n %34 = or i64 %3, %14\r\n %35 = or i64 %3, %15\r\n %36 = or i64 %3, %16\r\n %37 = or i64 %3, %17\r\n %38 = or i64 %3, %18\r\n %39 = or i64 %3, %19\r\n %40 = or i64 %3, %20\r\n %41 = or i64 %3, %21\r\n %42 = or i64 %3, %22\r\n %43 = or i64 %3, %23\r\n %44 = or i64 %3, %24\r\n %45 = or i64 %3, %25\r\n %46 = or i64 %3, 0\r\n %47 = or i64 %3, 0\r\n %48 = or i64 %3, 0\r\n %49 = or i64 %3, 0\r\n %50 = or i64 %3, 0\r\n %51 = or i64 %3, 0\r\n %52 = or i64 %3, 0\r\n %53 = or i64 %3, 0\r\n %54 = or i64 %3, 0\r\n %55 = or i64 %3, 0\r\n %56 = or i64 %3, 0\r\n %57 = or i64 %3, 0\r\n %58 = or i64 %3, 0\r\n %59 = icmp slt i64 %28, 0\r\n %60 = icmp slt i64 %29, 0\r\n %61 = icmp slt i64 %30, 0\r\n %62 = icmp slt i64 %31, 0\r\n %63 = icmp slt i64 %32, 0\r\n %64 = icmp slt i64 %33, 0\r\n %65 = icmp slt i64 %34, 0\r\n %66 = icmp slt i64 %35, 0\r\n %67 = icmp slt i64 %36, 0\r\n %68 = icmp slt i64 %37, 0\r\n %69 = icmp slt i64 %38, 0\r\n %70 = icmp slt i64 %39, 0\r\n %71 = icmp slt i64 %40, 0\r\n %72 = icmp slt i64 %41, 0\r\n %73 = icmp slt i64 %42, 0\r\n %74 = icmp slt i64 %43, 0\r\n %75 = icmp slt i64 %44, 0\r\n %76 = icmp slt i64 %45, 0\r\n %77 = icmp slt i64 %46, 0\r\n %78 = icmp slt i64 %47, 0\r\n %79 = icmp slt i64 %48, 0\r\n %80 = icmp slt i64 %49, 0\r\n %81 = icmp slt i64 %50, 0\r\n %82 = icmp slt i64 %51, 0\r\n %83 = icmp slt i64 %52, 0\r\n %84 = icmp slt i64 %53, 0\r\n %85 = icmp slt i64 %54, 0\r\n %86 = icmp slt i64 %55, 0\r\n %87 = icmp slt i64 %56, 0\r\n %88 = icmp slt i64 %57, 0\r\n %89 = icmp slt i64 %58, 0\r\n %90 = and i1 false, %59\r\n %91 = and i1 false, %60\r\n %92 = and i1 false, %61\r\n %93 = and i1 false, %62\r\n %94 = and i1 false, %63\r\n %95 = and i1 false, %64\r\n %96 = and i1 false, %65\r\n %97 = and i1 false, %66\r\n %98 = and i1 false, %67\r\n %99 = and i1 false, %68\r\n %100 = and i1 false, %69\r\n %101 = and i1 false, %70\r\n %102 = and i1 false, %71\r\n %103 = and i1 false, %72\r\n %104 = and i1 false, %73\r\n %105 = and i1 false, %74\r\n %106 = and i1 false, %75\r\n %107 = and i1 false, %76\r\n %108 = icmp eq i32 %2, 0\r\n %109 = and i1 false, %77\r\n %110 = and i1 false, %78\r\n %111 = and i1 false, %79\r\n %112 = and i1 false, %80\r\n %113 = and i1 false, %81\r\n %114 = and i1 false, %82\r\n %115 = and i1 false, %83\r\n %116 = and i1 false, %84\r\n %117 = and i1 false, %85\r\n %118 = and i1 false, %86\r\n %119 = or i64 %5, %26\r\n %120 = getelementptr float, ptr addrspace(1) null, i64 %119\r\n %121 = icmp slt i64 %119, 0\r\n ret void\r\n}\r\n```\r\n\r\nRunning via `opt --passes=slp-vectorizer -slp-vectorize-hor=false`:\r\n\r\n```sh\r\nopt: /root/llvm-project/llvm/lib/IR/Instructions.cpp:1853: bool isSingleSourceMaskImpl(llvm::ArrayRef<int>, int): Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' 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 -slp-vectorize-hor=false <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"func\"\r\n #0 0x0000000004fa4138 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fa4138)\r\n #1 0x0000000004fa18ac SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000073f701e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000073f701e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000073f701e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000073f701e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000073f701e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000073f701e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004d097f6 isSingleSourceMaskImpl(llvm::ArrayRef<int>, int) Instructions.cpp:0:0\r\n #9 0x0000000004d1097a llvm::ShuffleVectorInst::isExtractSubvectorMask(llvm::ArrayRef<int>, int, int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d1097a)\r\n#10 0x000000000400fc53 (anonymous namespace)::BaseShuffleAnalysis::isIdentityMask(llvm::ArrayRef<int>, llvm::FixedVectorType const*, bool) SLPVectorizer.cpp:0:0\r\n#11 0x0000000004043781 (anonymous namespace)::BaseShuffleAnalysis::peekThroughShuffles(llvm::Value*&, llvm::SmallVectorImpl<int>&, bool) SLPVectorizer.cpp:0:0\r\n#12 0x000000000405bd21 llvm::Value* (anonymous namespace)::BaseShuffleAnalysis::createShuffle<llvm::Value*, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder>(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000405c50a llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::createShuffle(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>) (.isra.0) SLPVectorizer.cpp:0:0\r\n#14 0x000000000405ce73 llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x405ce73)\r\n#15 0x000000000405d3d9 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool)::'lambda1'(llvm::Value*, llvm::ArrayRef<int>)::operator()(llvm::Value*, llvm::ArrayRef<int>) const SLPVectorizer.cpp:0:0\r\n#16 0x0000000004095c0a llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4095c0a)\r\n#17 0x0000000004097032 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4097032)\r\n#18 0x0000000004095aa8 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4095aa8)\r\n#19 0x0000000004097294 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4097294)\r\n#20 0x00000000040b31cc 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*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b31cc)\r\n#21 0x00000000040b6d45 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b6d45)\r\n#22 0x00000000040c3b2a llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40c3b2a)\r\n#23 0x00000000040c78a7 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+0x40c78a7)\r\n#24 0x00000000040cb5d0 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40cb5d0)\r\n#25 0x00000000040d1d49 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#26 0x00000000040d29fb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40d29fb)\r\n...\r\n```\r\n\r\nBisected to f3d2609af3031ddb54030548e86335f295cf49ca / https://github.com/llvm/llvm-project/pull/104144", "author": "rupprecht", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "dklimkin", "body": "Confirmed this resolved the issue. Thanks!" } ] }
true
null
91177
https://github.com/llvm/llvm-project/issues/91177
miscompilation
de8cf69abf4f8b16d5c5ecb77a6dfb1f5c09e45a
2024-05-06T09:27:25
[ "llvm/test/Transforms/FunctionAttrs" ]
{ "fix_commit": "f34d30cdae0f59698f660d5cc8fb993fb3441064", "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": [ [ 1186, 1195 ] ], "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": [ "isReturnNonNull" ], "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 f34d30cdae0f59698f660d5cc8fb993fb3441064 Author: Nikita Popov <[email protected]> Date: Tue May 7 09:47:28 2024 +0900 [FunctionAttrs] Fix incorrect nonnull inference for non-inbounds GEP (#91180) For inbounds GEPs, if the source pointer is non-null, the result must also be non-null. However, this does not hold for non-inbounds GEPs. Fixes https://github.com/llvm/llvm-project/issues/91177. diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 8e11cbf1cee4..26a4508aa151 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -1186,10 +1186,15 @@ static bool isReturnNonNull(Function *F, const SCCNodeSet &SCCNodes, switch (RVI->getOpcode()) { // Extend the analysis by looking upwards. case Instruction::BitCast: - case Instruction::GetElementPtr: case Instruction::AddrSpaceCast: FlowsToReturn.insert(RVI->getOperand(0)); continue; + case Instruction::GetElementPtr: + if (cast<GEPOperator>(RVI)->isInBounds()) { + FlowsToReturn.insert(RVI->getOperand(0)); + continue; + } + return false; case Instruction::Select: { SelectInst *SI = cast<SelectInst>(RVI); FlowsToReturn.insert(SI->getTrueValue());
[ { "file": "llvm/test/Transforms/FunctionAttrs/nocapture.ll", "commands": [ "opt -passes=function-attrs -S < %s", "opt -passes=attributor-light -S < %s" ], "tests": [ { "test_name": "lookup_bit", "test_body": "@lookup_table = external global [2 x i1]\n\n; Function Attrs: nounwind memory(none)\ndefine ptr @lookup_bit(ptr %q, i32 %bitno) #0 {\n %tmp = ptrtoint ptr %q to i32\n %tmp2 = lshr i32 %tmp, %bitno\n %bit = and i32 %tmp2, 1\n %lookup = getelementptr [2 x i1], ptr @lookup_table, i32 0, i32 %bit\n ret ptr %lookup\n}\n\nattributes #0 = { nounwind memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/FunctionAttrs/nonnull.ll", "commands": [ "opt -S -passes=function-attrs -enable-nonnull-arg-prop %s", "opt -S -passes=attributor-light %s" ], "tests": [ { "test_name": "pr91177_non_inbounds_gep", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine ptr @pr91177_non_inbounds_gep(ptr nonnull %arg) {\n %res = getelementptr i8, ptr %arg, i64 -8\n ret ptr %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "PR43833_simple", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndeclare void @sink(ptr)\n\ndefine void @PR43833_simple(ptr %0, i32 %1) {\n %3 = icmp ne i32 %1, 0\n br i1 %3, label %4, label %7\n\n4: ; preds = %2\n %5 = zext i32 %1 to i64\n %6 = getelementptr inbounds i32, ptr %0, i64 %5\n br label %8\n\n7: ; preds = %8, %2\n ret void\n\n8: ; preds = %8, %4\n %9 = phi i32 [ 1, %4 ], [ %10, %8 ]\n tail call void @sink(ptr %6)\n %10 = add nuw nsw i32 %9, 1\n %11 = icmp eq i32 %10, %1\n br i1 %11, label %7, label %8\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[FunctionAttrs] Incorrect nonnull inference for non-inbounds GEP", "body": "FunctionAttrs incorrectly infers that the following function returns nonnull (https://llvm.godbolt.org/z/49Kbq15xn):\r\n```llvm\r\ndefine ptr @test(ptr nonnull %arg) {\r\n %res = getelementptr i8, ptr %arg, i64 -8\r\n ret ptr %res\r\n}\r\n```\r\nThis is because the code assumes that the result of a GEP is non-null if the source is non-null here: https://github.com/llvm/llvm-project/blob/d98a78590f4f9e43fdfb69fde7d154a985e4560f/llvm/lib/Transforms/IPO/FunctionAttrs.cpp#L1189 This is not correct for non-inbounds GEPs.", "author": "nikic", "labels": [ "miscompilation", "ipo" ], "comments": [] }
true
null
144279
https://github.com/llvm/llvm-project/issues/144279
crash
7e6c1bd3edf4fc19be70587a4ac33a76bab78c02
2025-06-15T21:04:55
[ "llvm/test/Transforms/InstSimplify/ConstProp" ]
{ "fix_commit": "80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca", "components": [ "ConstantFold" ], "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": 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": [ [ 432, 437 ] ], "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": 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": [ "ReadDataFromGlobal" ], "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 80b79ce432bbe12701fd9fe495ff9feeb5e4b9ca Author: Nikita Popov <[email protected]> Date: Tue Jun 17 09:30:28 2025 +0200 [ConstantFolding] Handle reading from type padding (#144330) ReadDataFromGlobal() did not handle reads from the padding of types (in the sense of type store size != type alloc size, rather than struct padding). Return zero in that case. Fixes https://github.com/llvm/llvm-project/issues/144279. diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 2b7a438a9ef0..b58f9b26a865 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -432,6 +432,10 @@ bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr, assert(ByteOffset <= DL.getTypeAllocSize(C->getType()) && "Out of range access"); + // Reading type padding, return zero. + if (ByteOffset >= DL.getTypeStoreSize(C->getType())) + return true; + // If this element is zero or undefined, we can just return since *CurPtr is // zero initialized. if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
[ { "file": "llvm/test/Transforms/InstSimplify/ConstProp/loads.ll", "commands": [ "opt < %s -passes=instsimplify -S" ], "tests": [ { "test_name": "<module>", "test_body": "@i40_struct = constant { i40, i8 } { i40 0, i8 1 }\n@i40_array = constant [2 x i40] [i40 0, i40 1]\n\ndefine i8 @load_i40_struct_padding() {\n %v = load i8, ptr getelementptr (i8, ptr @i40_struct, i64 6)\n ret i8 %v\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[AggressiveInstCombine] assertion failure loading from non-power-of-two byte-sized zero field of global struct", "body": "```llvm\n@0 = constant { i40, i1 } { i40 0, i1 1 }\ndefine void @f() {\n %1 = load i1, ptr @0\n ret void\n}\n```\n```\n$ opt --version\nLLVM (http://llvm.org/):\n LLVM version 20.1.7\n DEBUG build with assertions.\n Default target: x86_64-unknown-linux-gnu\n Host CPU: znver5\n$ opt -S -passes aggressive-instcombine reduced.ll\nopt: llvm/lib/Support/APInt.cpp:457: APInt llvm::APInt::extractBits(unsigned int, unsigned int) const: Assertion `bitPosition < BitWidth && (numBits + bitPosition) <= BitWidth && \"Illegal bit extraction\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: 20.x-Debug/bin/opt -passes aggressive-instcombine reduced.ll -S\n1.\tRunning pass \"function(aggressive-instcombine)\" on module \"reduced.ll\"\n2.\tRunning pass \"aggressive-instcombine\" on function \"f\"\n #0 0x00007f6af9311bc6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm/lib/Support/Unix/Signals.inc:799:11\n #1 0x00007f6af931212f PrintStackTraceSignalHandler(void*) llvm/lib/Support/Unix/Signals.inc:875:1\n #2 0x00007f6af93101a0 llvm::sys::RunSignalHandlers() llvm/lib/Support/Signals.cpp:105:5\n #3 0x00007f6af931275e SignalHandler(int) llvm/lib/Support/Unix/Signals.inc:415:1\n #4 0x00007f6af8b56750 (/usr/lib64/libc.so.6+0x3d750)\n #5 0x00007f6af8bafa9c (/usr/lib64/libc.so.6+0x96a9c)\n #6 0x00007f6af8b56616 raise (/usr/lib64/libc.so.6+0x3d616)\n #7 0x00007f6af8b3e28d abort (/usr/lib64/libc.so.6+0x2528d)\n #8 0x00007f6af8b3e1f5 __assert_perror_fail (/usr/lib64/libc.so.6+0x251f5)\n #9 0x00007f6af91021db llvm::APInt::extractBits(unsigned int, unsigned int) const llvm/lib/Support/APInt.cpp:0:3\n#10 0x00007f6afaa4c319 (anonymous namespace)::ReadDataFromGlobal(llvm::Constant*, unsigned long, unsigned char*, unsigned int, llvm::DataLayout const&) llvm/lib/Analysis/ConstantFolding.cpp:445:45\n#11 0x00007f6afaa4c68b (anonymous namespace)::ReadDataFromGlobal(llvm::Constant*, unsigned long, unsigned char*, unsigned int, llvm::DataLayout const&) llvm/lib/Analysis/ConstantFolding.cpp:478:32\n#12 0x00007f6afaa4d3ee (anonymous namespace)::FoldReinterpretLoadFromConst(llvm::Constant*, llvm::Type*, long, llvm::DataLayout const&) llvm/lib/Analysis/ConstantFolding.cpp:622:7\n#13 0x00007f6afaa4cf72 llvm::ConstantFoldLoadFromConst(llvm::Constant*, llvm::Type*, llvm::APInt const&, llvm::DataLayout const&) llvm/lib/Analysis/ConstantFolding.cpp:723:19\n#14 0x00007f6afc550eb3 foldPatternedLoads(llvm::Instruction&, llvm::DataLayout const&) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp:910:15\n#15 0x00007f6afc54dca8 foldUnusualPatterns(llvm::Function&, llvm::DominatorTree&, llvm::TargetTransformInfo&, llvm::TargetLibraryInfo&, llvm::AAResults&, llvm::AssumptionCache&, bool&) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp:1253:21\n#16 0x00007f6afc54d9bd runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::TargetTransformInfo&, llvm::TargetLibraryInfo&, llvm::DominatorTree&, llvm::AAResults&, bool&) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp:1278:17\n#17 0x00007f6afc54d855 llvm::AggressiveInstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp:1290:7\n#18 0x00007f6aff99a1d8 llvm::detail::PassModel<llvm::Function, llvm::AggressiveInstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/include/llvm/IR/PassManagerInternal.h:91:17\n#19 0x00007f6af9de0ed2 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/include/llvm/IR/PassManagerImpl.h:85:5\n#20 0x00007f6b06c0be58 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/include/llvm/IR/PassManagerInternal.h:91:17\n#21 0x00007f6af9ddf7f5 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm/lib/IR/PassManager.cpp:124:38\n#22 0x00007f6b06c2d648 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm/include/llvm/IR/PassManagerInternal.h:91:17\n#23 0x00007f6af9ddfdf2 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm/include/llvm/IR/PassManagerImpl.h:85:5\n#24 0x00007f6b088241ce 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) llvm/tools/opt/NewPMDriver.cpp:541:3\n#25 0x00007f6b08861f85 optMain llvm/tools/opt/optdriver.cpp:739:12\n#26 0x00005575215c34a9 main llvm/tools/opt/opt.cpp:25:42\n#27 0x00007f6af8b403fb (/usr/lib64/libc.so.6+0x273fb)\n#28 0x00007f6af8b404ab __libc_start_main (/usr/lib64/libc.so.6+0x274ab)\n#29 0x00005575215c33b5 _start (20.x-Debug/bin/opt+0x23b5)\n```\nAlso repros at 087a6ac420ad99c523b9dd517351e0c6d1f1a980.", "author": "jacobly0", "labels": [ "crash", "llvm:analysis" ], "comments": [ { "author": "nikic", "body": "To make it clearer what the core problem is:\n```\n; RUN: opt -S -passes=instsimplify\n@g = constant { i40, i8 } { i40 0, i8 1 }\ndefine i8 @f() {\n %v = load i8, ptr getelementptr (i8, ptr @g, i64 6)\n ret i8 %v\n}\n```\nThis is accessing the padding between the store size and the alloc size of `i40`, which ReadDataFromGlobal does not correctly handle." } ] }
true
null
114947
https://github.com/llvm/llvm-project/issues/114947
miscompilation
1e5bfac933ea90ec4361446398551dd6b967c67f
2024-11-05T07:42:44
[ "llvm/test/Transforms/SCCP" ]
{ "fix_commit": "cd88bfcb5906049e1387b856fc7256e5fae22e5f", "components": [ "ConstantFold" ], "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": 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": [ [ 1266, 1279 ], [ 1298, 1344 ] ], "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": 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": [ "llvm::ConstantFoldBinaryOpOperands", "llvm::ConstantFoldCompareInstOperands", "llvm::ConstantFoldFPInstOperands", "llvm::FlushFPConstant" ], "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 cd88bfcb5906049e1387b856fc7256e5fae22e5f Author: Matt Arsenault <[email protected]> Date: Wed Nov 13 07:43:50 2024 -0800 ConstantFolding: Do not fold fcmp of denormal without known mode (#115407) Fixes #114947 diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 88db315ffd0b..1971c28fc4c4 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1266,14 +1266,16 @@ Constant *llvm::ConstantFoldCompareInstOperands( return ConstantFoldCompareInstOperands(Predicate, Ops1, Ops0, DL, TLI); } - // Flush any denormal constant float input according to denormal handling - // mode. - Ops0 = FlushFPConstant(Ops0, I, /* IsOutput */ false); - if (!Ops0) - return nullptr; - Ops1 = FlushFPConstant(Ops1, I, /* IsOutput */ false); - if (!Ops1) - return nullptr; + if (CmpInst::isFPPredicate(Predicate)) { + // Flush any denormal constant float input according to denormal handling + // mode. + Ops0 = FlushFPConstant(Ops0, I, /*IsOutput=*/false); + if (!Ops0) + return nullptr; + Ops1 = FlushFPConstant(Ops1, I, /*IsOutput=*/false); + if (!Ops1) + return nullptr; + } return ConstantFoldCompareInstruction(Predicate, Ops0, Ops1); } @@ -1298,47 +1300,110 @@ Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, return ConstantFoldBinaryInstruction(Opcode, LHS, RHS); } -Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *I, - bool IsOutput) { - if (!I || !I->getParent() || !I->getFunction()) - return Operand; +static ConstantFP *flushDenormalConstant(Type *Ty, const APFloat &APF, + DenormalMode::DenormalModeKind Mode) { + switch (Mode) { + case DenormalMode::Dynamic: + return nullptr; + case DenormalMode::IEEE: + return ConstantFP::get(Ty->getContext(), APF); + case DenormalMode::PreserveSign: + return ConstantFP::get( + Ty->getContext(), + APFloat::getZero(APF.getSemantics(), APF.isNegative())); + case DenormalMode::PositiveZero: + return ConstantFP::get(Ty->getContext(), + APFloat::getZero(APF.getSemantics(), false)); + default: + break; + } - ConstantFP *CFP = dyn_cast<ConstantFP>(Operand); - if (!CFP) - return Operand; + llvm_unreachable("unknown denormal mode"); +} + +/// Return the denormal mode that can be assumed when executing a floating point +/// operation at \p CtxI. +static DenormalMode getInstrDenormalMode(const Instruction *CtxI, Type *Ty) { + if (!CtxI || !CtxI->getParent() || !CtxI->getFunction()) + return DenormalMode::getDynamic(); + return CtxI->getFunction()->getDenormalMode(Ty->getFltSemantics()); +} +static ConstantFP *flushDenormalConstantFP(ConstantFP *CFP, + const Instruction *Inst, + bool IsOutput) { const APFloat &APF = CFP->getValueAPF(); - // TODO: Should this canonicalize nans? if (!APF.isDenormal()) - return Operand; + return CFP; - Type *Ty = CFP->getType(); - DenormalMode DenormMode = - I->getFunction()->getDenormalMode(Ty->getFltSemantics()); - DenormalMode::DenormalModeKind Mode = - IsOutput ? DenormMode.Output : DenormMode.Input; - switch (Mode) { - default: - llvm_unreachable("unknown denormal mode"); - case DenormalMode::Dynamic: - return nullptr; - case DenormalMode::IEEE: + DenormalMode Mode = getInstrDenormalMode(Inst, CFP->getType()); + return flushDenormalConstant(CFP->getType(), APF, + IsOutput ? Mode.Output : Mode.Input); +} + +Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *Inst, + bool IsOutput) { + if (ConstantFP *CFP = dyn_cast<ConstantFP>(Operand)) + return flushDenormalConstantFP(CFP, Inst, IsOutput); + + if (isa<ConstantAggregateZero, UndefValue, ConstantExpr>(Operand)) return Operand; - case DenormalMode::PreserveSign: - if (APF.isDenormal()) { - return ConstantFP::get( - Ty->getContext(), - APFloat::getZero(Ty->getFltSemantics(), APF.isNegative())); + + Type *Ty = Operand->getType(); + VectorType *VecTy = dyn_cast<VectorType>(Ty); + if (VecTy) { + if (auto *Splat = dyn_cast_or_null<ConstantFP>(Operand->getSplatValue())) { + ConstantFP *Folded = flushDenormalConstantFP(Splat, Inst, IsOutput); + if (!Folded) + return nullptr; + return ConstantVector::getSplat(VecTy->getElementCount(), Folded); } - return Operand; - case DenormalMode::PositiveZero: - if (APF.isDenormal()) { - return ConstantFP::get(Ty->getContext(), - APFloat::getZero(Ty->getFltSemantics(), false)); + + Ty = VecTy->getElementType(); + } + + if (const auto *CV = dyn_cast<ConstantVector>(Operand)) { + SmallVector<Constant *, 16> NewElts; + for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) { + Constant *Element = CV->getAggregateElement(i); + if (isa<UndefValue>(Element)) { + NewElts.push_back(Element); + continue; + } + + ConstantFP *CFP = dyn_cast<ConstantFP>(Element); + if (!CFP) + return nullptr; + + ConstantFP *Folded = flushDenormalConstantFP(CFP, Inst, IsOutput); + if (!Folded) + return nullptr; + NewElts.push_back(Folded); } - return Operand; + + return ConstantVector::get(NewElts); + } + + if (const auto *CDV = dyn_cast<ConstantDataVector>(Operand)) { + SmallVector<Constant *, 16> NewElts; + for (unsigned I = 0, E = CDV->getNumElements(); I < E; ++I) { + const APFloat &Elt = CDV->getElementAsAPFloat(I); + if (!Elt.isDenormal()) { + NewElts.push_back(ConstantFP::get(Ty, Elt)); + } else { + DenormalMode Mode = getInstrDenormalMode(Inst, Ty); + ConstantFP *Folded = + flushDenormalConstant(Ty, Elt, IsOutput ? Mode.Output : Mode.Input); + if (!Folded) + return nullptr; + NewElts.push_back(Folded); + } + } + + return ConstantVector::get(NewElts); } - return Operand; + + return nullptr; } Constant *llvm::ConstantFoldFPInstOperands(unsigned Opcode, Constant *LHS,
[ { "file": "llvm/test/Transforms/SCCP/no-fold-fcmp-dynamic-denormal-mode-issue114947.ll", "commands": [ "opt -S -passes=ipsccp < %s" ], "tests": [ { "test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_vector_nonsplat", "test_body": "define <2 x i1> @no_fold_fcmp_denormal_double_ieee_dynamic_vector_nonsplat() #0 {\n %cmp = fcmp une <2 x double> <double 0x8000000000000, double 1.000000e+00>, zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat_undef", "test_body": "define <3 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat_undef() #0 {\n %cmp = fcmp une <3 x double> <double 2.000000e+00, double undef, double 4.000000e+00>, <double 1.000000e+00, double undef, double 4.000000e+00>\n ret <3 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_denormal_undef", "test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic_denormal_undef() #0 {\n %cmp = fcmp une double 0x8000000000000, undef\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat", "test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat() #0 {\n %cmp = fcmp une <2 x double> <double 2.000000e+00, double 4.000000e+00>, <double 2.000000e+00, double 8.000000e+00>\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_splat", "test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_splat() #0 {\n %cmp = fcmp une <2 x double> splat (double 2.000000e+00), zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fold_fcmp_nondenormal_double_ieee_dynamic", "test_body": "define i1 @fold_fcmp_nondenormal_double_ieee_dynamic() #0 {\n %cmp = fcmp une double 2.000000e+00, 0.000000e+00\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_zero", "test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_zero() #0 {\n %cmp = fcmp une <2 x double> zeroinitializer, zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_denormal_poison", "test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic_denormal_poison() #0 {\n %cmp = fcmp une double 0x8000000000000, poison\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_vector_splat", "test_body": "define <2 x i1> @no_fold_fcmp_denormal_double_ieee_dynamic_vector_splat() #0 {\n %cmp = fcmp une <2 x double> splat (double 0x8000000000000), zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "no_fold_fcmp_denormal_double_ieee_dynamic", "test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic() #0 {\n %cmp = fcmp une double 0x8000000000000, 0.000000e+00\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "`fcmp` miscompiled to a constant", "body": "Alive2 report: https://alive2.llvm.org/ce/z/324E7x\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @fcmp_double_dynamic_dynamic.2() denormal-fp-math=dynamic,dynamic {\r\n#0:\r\n %cmp = fcmp une double 0x0008000000000000, -0.000000\r\n ret i1 %cmp\r\n}\r\n=>\r\ndefine i1 @fcmp_double_dynamic_dynamic.2() nofree noundef willreturn denormal-fp-math=dynamic,dynamic memory(none) {\r\n#0:\r\n ret i1 1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n\r\nSource:\r\ni1 %cmp = #x0 (0)\r\n\r\nTarget:\r\nSource value: #x0 (0)\r\nTarget value: #x1 (1)\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", "author": "bongjunj", "labels": [ "miscompilation", "floating-point", "llvm:analysis" ], "comments": [ { "author": "arsenm", "body": "I don't see the issue? Those values are in fact not equal, so this is true. Alive bug? " }, { "author": "jcranmer-intel", "body": "it's comparing a denormal to 0, and the `denormal-fp-mode` is set to `dynamic`, so `fcmp` may or may not be flushing denormals to 0." }, { "author": "arsenm", "body": "InstCombine doesn't fold this, IPSCCP does " }, { "author": "nikic", "body": "I expect this is because we got through ValueLattice comparison, which does not have access to the denormal mode: https://github.com/llvm/llvm-project/blob/9501af5f92bb31fa9527d12a4b17b88d9fd651c4/llvm/lib/Analysis/ValueLattice.cpp#L28-L29\r\n\r\nReally, the constant folding implementation should be defaulting to the conservatively correct behavior if the denormal mode is unknown." } ] }
true
null
87856
https://github.com/llvm/llvm-project/issues/87856
crash
b17d44558ba4c30a3005089b334f68593d6a9c7c
2024-04-06T02:19:05
[ "llvm/test/Transforms/Attributor" ]
{ "fix_commit": "2d61692d4b75b7d92b44bfafb1011c1723955151", "components": [ "Attributor" ], "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": 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": [ [ 5899, 5908 ] ], "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": 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": [ "AANoCaptureImpl::updateImpl" ], "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 2d61692d4b75b7d92b44bfafb1011c1723955151 Author: Matt Arsenault <[email protected]> Date: Thu May 23 19:31:33 2024 +0200 Attributor: Do not assume function context in AANoCapture (#91462) If the calling function has the null_pointer_is_valid attribute, somehow a null constant reaches here. I'm not sure why exactly, it doesn't happen for other types of constants. Fixes #87856 diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 41b66aafe7d3..1b3bf3c732ed 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -5690,6 +5690,9 @@ bool AANoCapture::isImpliedByIR(Attributor &A, const IRPosition &IRP, return V.use_empty(); // You cannot "capture" null in the default address space. + // + // FIXME: This should use NullPointerIsDefined to account for the function + // attribute. if (isa<UndefValue>(V) || (isa<ConstantPointerNull>(V) && V.getType()->getPointerAddressSpace() == 0)) { return true; @@ -5899,10 +5902,13 @@ ChangeStatus AANoCaptureImpl::updateImpl(Attributor &A) { const Function *F = isArgumentPosition() ? IRP.getAssociatedFunction() : IRP.getAnchorScope(); - assert(F && "Expected a function!"); - const IRPosition &FnPos = IRPosition::function(*F); + + // TODO: Is the checkForAllUses below useful for constants? + if (!F) + return indicatePessimisticFixpoint(); AANoCapture::StateType T; + const IRPosition &FnPos = IRPosition::function(*F); // Readonly means we cannot capture through memory. bool IsKnown;
[ { "file": "llvm/test/Transforms/Attributor/issue87856.ll", "commands": [ "opt -S -passes=attributor < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @null_ptr_is_valid_call_with_null() #0 {\n;\n call void @store_as0(ptr null)\n ret void\n}\n\ndefine void @null_ptr_is_valid_call_with_undef() #0 {\n;\n call void @store_as0(ptr undef)\n ret void\n}\n\ndefine void @store_as0(ptr %0) {\n;\n store i16 0, ptr %0, align 2\n ret void\n}\n\ndefine void @call_store_as1() {\n;\n call void @store_as1(ptr addrspace(1) null)\n ret void\n}\n\ndefine void @store_as1(ptr addrspace(1) %arg) {\n;\n store i16 0, ptr addrspace(1) %arg, align 2\n ret void\n}\n\nattributes #0 = { null_pointer_is_valid }\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[attributor] Crash on `null_pointer_is_valid` function", "body": "With\r\n\r\n```\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"aarch64-none-linux-android28\"\r\n\r\n; Function Attrs: null_pointer_is_valid\r\ndefine i64 @foo() #0 {\r\n call fastcc void @bar(ptr null)\r\n ret i64 0\r\n}\r\n\r\ndefine fastcc void @bar(ptr %0) {\r\n store i16 0, ptr %0, align 2\r\n ret void\r\n}\r\n\r\nattributes #0 = { null_pointer_is_valid }\r\n```\r\n\r\nand running\r\n\r\n```\r\nopt -passes=attributor file.ll\r\n```\r\n\r\nwe crash with\r\n\r\n```\r\nopt: llvm-project/llvm/lib/Transforms/IPO/AttributorAttributes.cpp:5901: virtual ChangeStatus (anonymous namespace)::AANoCaptureImpl::updateImpl(Attributor &): Assertion `F && \"Expected a function!\"' 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: opt -passes=attributor reduced.ll\r\n #0 0x000000000165bf38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (llvm-project/build/Release/bin/opt+0x165bf38)\r\n #1 0x0000000001659a40 llvm::sys::RunSignalHandlers() (llvm-project/build/Release/bin/opt+0x1659a40)\r\n #2 0x000000000165c938 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f3ec923e6f0 __restore_rt (/lib64/libc.so.6+0x3e6f0)\r\n #4 0x00007f3ec928b94c __pthread_kill_implementation (/lib64/libc.so.6+0x8b94c)\r\n #5 0x00007f3ec923e646 gsignal (/lib64/libc.so.6+0x3e646)\r\n #6 0x00007f3ec92287f3 abort (/lib64/libc.so.6+0x287f3)\r\n #7 0x00007f3ec922871b _nl_load_domain.cold (/lib64/libc.so.6+0x2871b)\r\n #8 0x00007f3ec9237386 (/lib64/libc.so.6+0x37386)\r\n #9 0x0000000002f2a65b (anonymous namespace)::AANoCaptureImpl::updateImpl(llvm::Attributor&) AttributorAttributes.cpp:0:0\r\n#10 0x0000000002ec8492 llvm::AbstractAttribute::update(llvm::Attributor&) (llvm-project/build/Release/bin/opt+0x2ec8492)\r\n#11 0x0000000002ed3b83 llvm::Attributor::updateAA(llvm::AbstractAttribute&) (llvm-project/build/Release/bin/opt+0x2ed3b83)\r\n#12 0x0000000002eec289 llvm::AANoCapture const* llvm::Attributor::getOrCreateAAFor<llvm::AANoCapture>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) Attributor.cpp:0:0\r\n#13 0x0000000002f1ab57 (anonymous namespace)::AANoAliasCallSiteArgument::updateImpl(llvm::Attributor&) AttributorAttributes.cpp:0:0\r\n#14 0x0000000002ec8492 llvm::AbstractAttribute::update(llvm::Attributor&) (llvm-project/build/Release/bin/opt+0x2ec8492)\r\n#15 0x0000000002ed3b83 llvm::Attributor::updateAA(llvm::AbstractAttribute&) (llvm-project/build/Release/bin/opt+0x2ed3b83)\r\n#16 0x0000000002efba19 llvm::AANoAlias const* llvm::Attributor::getOrCreateAAFor<llvm::AANoAlias>(llvm::IRPosition, llvm::AbstractAttribute const*, llvm::DepClassTy, bool, bool) Attributor.cpp:0:0\r\n#17 0x0000000002ede880 void llvm::Attributor::checkAndQueryIRAttr<(llvm::Attribute::AttrKind)20, llvm::AANoAlias>(llvm::IRPosition const&, llvm::AttributeSet) (llvm-project/build/Release/bin/opt+0x2ede880)\r\n#18 0x0000000002edd545 llvm::Attributor::identifyDefaultAbstractAttributes(llvm::Function&) (llvm-project/build/Release/bin/opt+0x2edd545)\r\n#19 0x0000000002ee0800 runAttributorOnFunctions(llvm::InformationCache&, llvm::SetVector<llvm::Function*, llvm::SmallVector<llvm::Function*, 0u>, llvm::DenseSet<llvm::Function*, llvm::DenseMapInfo<llvm::Function*, void>>, 0u>&, llvm::AnalysisGetter&, llvm::CallGraphUpdater&, bool, bool) Attributor.cpp:0:0\r\n#20 0x0000000002edfc41 llvm::AttributorPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (llvm-project/build/Release/bin/opt+0x2edfc41)\r\n#21 0x0000000002b6fcdd llvm::detail::PassModel<llvm::Module, llvm::AttributorPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilderPipelines.cpp:0:0\r\n#22 0x0000000001853e56 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (llvm-project/build/Release/bin/opt+0x1853e56)\r\n#23 0x0000000002afaa4b 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) (llvm-project/build/Release/bin/opt+0x2afaa4b)\r\n#24 0x0000000001622f36 optMain (llvm-project/build/Release/bin/opt+0x1622f36)\r\n```", "author": "lanza", "labels": [ "crash-on-valid", "llvm::Attributor" ], "comments": [ { "author": "lanza", "body": "https://github.com/llvm/llvm-project/blob/0f52f4ddd909eb38f2a691ffed8469263fe5f635/llvm/lib/Transforms/IPO/AttributorAttributes.cpp#L5901" }, { "author": "dtcxzyw", "body": "cc @arsenm " }, { "author": "arsenm", "body": "Just returning on the null function seems to work, but I don't understand exactly why it reaches here. AANoCapture::isImpliedByIR is incorrectly reimplementing NullPointerIsDefined but fixing that doesn't seem to help any " } ] }
true
null
110494
https://github.com/llvm/llvm-project/issues/110494
crash
1ba19d6c49663a35baf5d6cdc4a149e2aca9ae6c
2024-09-30T11:42:07
[ "llvm/test/Transforms/LoopStrengthReduce" ]
{ "fix_commit": "7506872afc6c1cc7556eed5128a2030b6eb8ca29", "components": [ "LoopStrengthReduce" ], "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": 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": [ [ 6870, 6875 ] ], "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": 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": [ "SalvageDVI" ], "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 7506872afc6c1cc7556eed5128a2030b6eb8ca29 Author: Orlando Cazalet-Hyams <[email protected]> Date: Thu Oct 3 11:47:08 2024 +0100 [DebugInfo][LSR] Fix assertion failure salvaging IV with offset > 64 bits wide (#110979) Fixes #110494 diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index f69db57c25ed..575395eda1c5 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6870,6 +6870,8 @@ static bool SalvageDVI(llvm::Loop *L, ScalarEvolution &SE, SE.computeConstantDifference(DVIRec.SCEVs[i], SCEVInductionVar)) { if (Offset->getSignificantBits() <= 64) SalvageExpr->createOffsetExpr(Offset->getSExtValue(), LSRInductionVar); + else + return false; } else if (!SalvageExpr->createIterCountExpr(DVIRec.SCEVs[i], IterCountExpr, SE)) return false;
[ { "file": "llvm/test/Transforms/LoopStrengthReduce/debuginfo-scev-salvage-large-width.ll", "commands": [ "opt -S -loop-reduce %s" ], "tests": [ { "test_name": "main", "test_body": "define i16 @main() {\nentry:\n br label %for.cond29\n\nfor.cond29: ; preds = %for.body32, %entry\n %il_1000.0 = phi i128 [ 0, %entry ], [ %inc72, %for.body32 ]\n %l_995.0 = phi i128 [ 4704496199548239085565, %entry ], [ %inc70, %for.body32 ]\n #dbg_value(i128 %l_995.0, !4, !DIExpression(), !9)\n %cmp30 = icmp slt i128 %il_1000.0, 0\n br i1 %cmp30, label %for.body32, label %for.cond.cleanup31\n\nfor.cond.cleanup31: ; preds = %for.cond29\n ret i16 0\n\nfor.body32: ; preds = %for.cond29\n %inc70 = add i128 %l_995.0, 1\n %inc72 = add i128 %il_1000.0, 1\n br label %for.cond29\n}\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: \"foo.c\", directory: \"/tmp\")\n!2 = !{}\n!3 = !{i32 2, !\"Debug Info Version\", i32 3}\n!4 = !DILocalVariable(name: \"l_995\", scope: !5, file: !1, line: 414, type: !7)\n!5 = distinct !DISubprogram(name: \"main\", scope: !1, file: !1, line: 397, type: !6, scopeLine: 398, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)\n!6 = !DISubroutineType(types: !2)\n!7 = !DIDerivedType(tag: DW_TAG_typedef, name: \"__uint128_t\", file: !1, baseType: !8)\n!8 = !DIBasicType(name: \"unsigned __int128\", size: 128, encoding: DW_ATE_unsigned)\n!9 = !DILocation(line: 0, scope: !5)\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "llc: ../lib/Transforms/Scalar/LoopStrengthReduce.cpp:6630: [...] Assertion `!LocationOps.empty() && \"Expected the location ops to contain the IV.\"' failed.", "body": "llvm commit: 82e594a022d\r\nReproduce with: ```llc bbi-99605.ll -o /dev/null```\r\nResult:\r\n```\r\nllc: ../lib/Transforms/Scalar/LoopStrengthReduce.cpp:6630: void (anonymous namespace)::SCEVDbgValueBuilder::appendToVectors(SmallVectorImpl<uint64_t> &, SmallVectorImpl<llvm::Value *> &): Assertion `!LocationOps.empty() && \"Expected the location ops to contain the IV.\"' 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: build-all/bin/llc bbi-99605.ll -o /dev/null\r\n1.\tRunning pass 'Function Pass Manager' on module 'bbi-99605.ll'.\r\n2.\tRunning pass 'Loop Pass Manager' on function '@main'\r\n3.\tRunning pass 'Loop Strength Reduction' on basic block '%for.cond29'\r\n #0 0x000055e150599557 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/llc+0x6dee557)\r\n #1 0x000055e1505970be llvm::sys::RunSignalHandlers() (build-all/bin/llc+0x6dec0be)\r\n #2 0x000055e150599bff SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f66b410bcf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)\r\n #4 0x00007f66b1cc4acf raise (/lib64/libc.so.6+0x4eacf)\r\n #5 0x00007f66b1c97ea5 abort (/lib64/libc.so.6+0x21ea5)\r\n #6 0x00007f66b1c97d79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)\r\n #7 0x00007f66b1cbd426 (/lib64/libc.so.6+0x47426)\r\n #8 0x000055e15005db21 (build-all/bin/llc+0x68b2b21)\r\n #9 0x000055e15005c0c3 SalvageDVI(llvm::Loop*, llvm::ScalarEvolution&, llvm::PHINode*, (anonymous namespace)::DVIRecoveryRec&, llvm::SCEV const*, (anonymous namespace)::SCEVDbgValueBuilder) LoopStrengthReduce.cpp:0:0\r\n#10 0x000055e15002dca8 ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSA*) LoopStrengthReduce.cpp:0:0\r\n#11 0x000055e15005e7e8 (anonymous namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&) LoopStrengthReduce.cpp:0:0\r\n#12 0x000055e14f26f0f9 llvm::LPPassManager::runOnFunction(llvm::Function&) (build-all/bin/llc+0x5ac40f9)\r\n#13 0x000055e14fba9e38 llvm::FPPassManager::runOnFunction(llvm::Function&) (build-all/bin/llc+0x63fee38)\r\n#14 0x000055e14fbb2171 llvm::FPPassManager::runOnModule(llvm::Module&) (build-all/bin/llc+0x6407171)\r\n#15 0x000055e14fbaa8b5 llvm::legacy::PassManagerImpl::run(llvm::Module&) (build-all/bin/llc+0x63ff8b5)\r\n#16 0x000055e14d988be8 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0\r\n#17 0x000055e14d98626d main (build-all/bin/llc+0x41db26d)\r\n#18 0x00007f66b1cb0d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)\r\n#19 0x000055e14d9822ee _start (build-all/bin/llc+0x41d72ee)\r\nAbort (core dumped)\r\n```\r\nThe input contains the new debug info:\r\n```#dbg_value(i128 %l_995.0, !4, !DIExpression(), !9)```\r\n\r\n[bbi-99605.ll.gz](https://github.com/user-attachments/files/17189125/bbi-99605.ll.gz)\r\n", "author": "mikaelholmen", "labels": [ "debuginfo", "crash", "llvm:transforms" ], "comments": [ { "author": "OCHyams", "body": "Thanks for the small reproducer. That is fixed in #110979 - this PR just avoids us crash/asserting when a salvage attempt is made with an offset over 64 bits wide and poisons the dbg record instead. I didn't look into whether we could theoretically or practically salvage it.\r\n\r\nn.b., this case was broken with debug intrinsics too, not just the new debug record format." } ] }
true
null
141628
https://github.com/llvm/llvm-project/issues/141628
crash
8a49db35f45e56c92522c6079e51553e80c07aec
2025-05-27T16:04:50
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "cb648ba97003bc0aa94e86f8e89ea6e3e3d09a11", "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": [ [ 15317, 15322 ] ], "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 cb648ba97003bc0aa94e86f8e89ea6e3e3d09a11 Author: Alexey Bataev <[email protected]> Date: Thu May 29 08:49:31 2025 -0700 [SLP]Check if the user node has instructions, used only outside Gather nodes with parents, which scalar instructions are used only outside, are generated before the whole tree vectorization. Need to teach isGatherShuffledSingleRegisterEntry to check that such nodes are emitted first and they cannot depend on other nodes, which are emitted later. Fixes #141628 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 831703b375d9..3e7f4cb56c0b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -15317,6 +15317,20 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( UserPHI ? UserPHI->getIncomingBlock(UseEI.EdgeIdx)->getTerminator() : &getLastInstructionInBundle(UseEI.UserTE); if (TEInsertPt == InsertPt) { + // Check nodes, which might be emitted first. + if (TEUseEI.UserTE->State == TreeEntry::Vectorize && + (TEUseEI.UserTE->getOpcode() != Instruction::PHI || + TEUseEI.UserTE->isAltShuffle()) && + all_of(TEUseEI.UserTE->Scalars, + [](Value *V) { return isUsedOutsideBlock(V); })) { + if (UseEI.UserTE->State != TreeEntry::Vectorize || + (UseEI.UserTE->getOpcode() == Instruction::PHI && + !UseEI.UserTE->isAltShuffle()) || + any_of(UseEI.UserTE->Scalars, + [](Value *V) { return !isUsedOutsideBlock(V); })) + continue; + } + // If the schedulable insertion point is used in multiple entries - just // exit, no known ordering at this point, available only after real // scheduling.
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/many-uses-parent-node.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(ptr addrspace(1) %arg) {\n;\nbb:\n br label %bb1\n\nbb1: ; preds = %bb\n %getelementptr = getelementptr i8, ptr addrspace(1) %arg, i64 20\n %getelementptr2 = getelementptr i8, ptr addrspace(1) %arg, i64 21\n %getelementptr3 = getelementptr i8, ptr addrspace(1) %arg, i64 22\n br i1 false, label %bb73, label %bb150\nbb4: ; No predecessors!\n br i1 false, label %bb68, label %bb70\nbb5: ; No predecessors!\n br i1 false, label %bb64, label %bb66\nbb6: ; No predecessors!\n br i1 false, label %bb60, label %bb62\nbb7: ; No predecessors!\n br i1 false, label %bb8, label %bb58\nbb8: ; preds = %bb7\n br i1 false, label %bb54, label %bb56\nbb9: ; No predecessors!\n br i1 false, label %bb50, label %bb52\nbb10: ; No predecessors!\n br i1 false, label %bb46, label %bb48\nbb11: ; No predecessors!\n br i1 false, label %bb42, label %bb44\nbb12: ; No predecessors!\n br i1 false, label %bb38, label %bb40\nbb13: ; No predecessors!\n br i1 false, label %bb36, label %bb122\nbb14: ; No predecessors!\n br i1 false, label %bb32, label %bb34\nbb15: ; No predecessors!\n br i1 false, label %bb28, label %bb30\nbb16: ; No predecessors!\n br i1 false, label %bb17, label %bb26\nbb17: ; preds = %bb16\n br i1 false, label %bb22, label %bb24\nbb18: ; No predecessors!\n br i1 false, label %bb19, label %bb20\nbb19: ; preds = %bb18\n %load = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb20: ; preds = %bb18\n %load21 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb22: ; preds = %bb17\n %load23 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb24: ; preds = %bb17\n %load25 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb26: ; preds = %bb16\n %load27 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb28: ; preds = %bb15\n %load29 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb30: ; preds = %bb15\n %load31 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb32: ; preds = %bb14\n %load33 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb34: ; preds = %bb14\n %load35 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb36: ; preds = %bb13\n %load37 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb38: ; preds = %bb12\n %load39 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb40: ; preds = %bb12\n %load41 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb42: ; preds = %bb11\n %load43 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb44: ; preds = %bb11\n %load45 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb46: ; preds = %bb10\n %load47 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb48: ; preds = %bb10\n %load49 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb50: ; preds = %bb9\n %load51 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb52: ; preds = %bb9\n %load53 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb54: ; preds = %bb8\n %load55 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb56: ; preds = %bb8\n %load57 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb58: ; preds = %bb7\n %load59 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb60: ; preds = %bb6\n %load61 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb62: ; preds = %bb6\n %load63 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb64: ; preds = %bb5\n %load65 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb66: ; preds = %bb5\n %load67 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb68: ; preds = %bb4\n %load69 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb70: ; preds = %bb4\n %load71 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb72: ; No predecessors!\n br i1 false, label %bb142, label %bb79\nbb73: ; preds = %bb1\n br i1 false, label %bb146, label %bb74\nbb74: ; preds = %bb73\n br i1 false, label %bb75, label %bb76\nbb75: ; preds = %bb74\n br label %bb150\nbb76: ; preds = %bb74\n br i1 false, label %bb153, label %bb77\nbb77: ; preds = %bb76\n %load78 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb79: ; preds = %bb72\n br i1 false, label %bb146, label %bb81\nbb80: ; No predecessors!\n br label %bb150\nbb81: ; preds = %bb79\n %load82 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb83: ; No predecessors!\n br label %bb138\nbb84: ; No predecessors!\n br i1 false, label %bb142, label %bb85\nbb85: ; preds = %bb84\n br i1 false, label %bb146, label %bb86\nbb86: ; preds = %bb85\n %load87 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb88: ; No predecessors!\n br label %bb134\nbb89: ; No predecessors!\n br i1 false, label %bb138, label %bb90\nbb90: ; preds = %bb89\n br i1 false, label %bb142, label %bb91\nbb91: ; preds = %bb90\n %load92 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb93: ; No predecessors!\n br label %bb130\nbb94: ; No predecessors!\n br i1 false, label %bb134, label %bb95\nbb95: ; preds = %bb94\n br i1 false, label %bb138, label %bb96\nbb96: ; preds = %bb95\n %load97 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb98: ; No predecessors!\n br label %bb126\nbb99: ; No predecessors!\n br i1 false, label %bb130, label %bb100\nbb100: ; preds = %bb99\n br i1 false, label %bb134, label %bb101\nbb101: ; preds = %bb100\n %load102 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb103: ; No predecessors!\n br label %bb124\nbb104: ; No predecessors!\n br i1 false, label %bb126, label %bb105\nbb105: ; preds = %bb104\n br i1 false, label %bb130, label %bb106\nbb106: ; preds = %bb105\n %load107 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb108: ; No predecessors!\n br label %bb124\nbb109: ; No predecessors!\n br i1 false, label %bb126, label %bb110\nbb110: ; preds = %bb109\n %load111 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb112: ; No predecessors!\n %load113 = load i8, ptr addrspace(1) %getelementptr3, align 1\n br label %bb124\nbb114: ; No predecessors!\n %load115 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb116: ; No predecessors!\n %load117 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb118: ; No predecessors!\n %load119 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb120: ; No predecessors!\n %load121 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\nbb122: ; preds = %bb13\n %load123 = load i8, ptr addrspace(1) %getelementptr3, align 1\n ret i32 0\n\nbb124: ; preds = %bb112, %bb108, %bb103\n %phi = phi ptr addrspace(1) [ null, %bb112 ], [ %getelementptr3, %bb108 ], [ null, %bb103 ]\n %phi125 = phi ptr addrspace(1) [ null, %bb112 ], [ null, %bb108 ], [ %getelementptr3, %bb103 ]\n br label %bb126\n\nbb126: ; preds = %bb124, %bb109, %bb104, %bb98\n %phi127 = phi ptr addrspace(1) [ null, %bb124 ], [ null, %bb98 ], [ null, %bb104 ], [ %getelementptr3, %bb109 ]\n %phi128 = phi ptr addrspace(1) [ null, %bb124 ], [ null, %bb98 ], [ %getelementptr3, %bb104 ], [ null, %bb109 ]\n %phi129 = phi ptr addrspace(1) [ null, %bb124 ], [ %getelementptr3, %bb98 ], [ null, %bb104 ], [ null, %bb109 ]\n br label %bb130\n\nbb130: ; preds = %bb126, %bb105, %bb99, %bb93\n %phi131 = phi ptr addrspace(1) [ null, %bb126 ], [ null, %bb93 ], [ null, %bb99 ], [ %getelementptr3, %bb105 ]\n %phi132 = phi ptr addrspace(1) [ null, %bb126 ], [ null, %bb93 ], [ %getelementptr3, %bb99 ], [ null, %bb105 ]\n %phi133 = phi ptr addrspace(1) [ null, %bb126 ], [ %getelementptr3, %bb93 ], [ null, %bb99 ], [ null, %bb105 ]\n br label %bb134\n\nbb134: ; preds = %bb130, %bb100, %bb94, %bb88\n %phi135 = phi ptr addrspace(1) [ null, %bb130 ], [ null, %bb88 ], [ null, %bb94 ], [ %getelementptr3, %bb100 ]\n %phi136 = phi ptr addrspace(1) [ null, %bb130 ], [ null, %bb88 ], [ %getelementptr3, %bb94 ], [ null, %bb100 ]\n %phi137 = phi ptr addrspace(1) [ null, %bb130 ], [ %getelementptr3, %bb88 ], [ null, %bb94 ], [ null, %bb100 ]\n br label %bb138\n\nbb138: ; preds = %bb134, %bb95, %bb89, %bb83\n %phi139 = phi ptr addrspace(1) [ null, %bb134 ], [ null, %bb83 ], [ null, %bb89 ], [ %getelementptr3, %bb95 ]\n %phi140 = phi ptr addrspace(1) [ null, %bb134 ], [ null, %bb83 ], [ %getelementptr3, %bb89 ], [ null, %bb95 ]\n %phi141 = phi ptr addrspace(1) [ null, %bb134 ], [ %getelementptr3, %bb83 ], [ null, %bb89 ], [ null, %bb95 ]\n br label %bb142\n\nbb142: ; preds = %bb138, %bb90, %bb84, %bb72\n %phi143 = phi ptr addrspace(1) [ null, %bb138 ], [ null, %bb72 ], [ null, %bb84 ], [ %getelementptr3, %bb90 ]\n %phi144 = phi ptr addrspace(1) [ null, %bb138 ], [ null, %bb72 ], [ %getelementptr3, %bb84 ], [ null, %bb90 ]\n %phi145 = phi ptr addrspace(1) [ null, %bb138 ], [ %getelementptr3, %bb72 ], [ null, %bb84 ], [ null, %bb90 ]\n br label %bb146\n\nbb146: ; preds = %bb142, %bb85, %bb79, %bb73\n %phi147 = phi ptr addrspace(1) [ null, %bb142 ], [ null, %bb73 ], [ null, %bb79 ], [ %getelementptr3, %bb85 ]\n %phi148 = phi ptr addrspace(1) [ null, %bb142 ], [ null, %bb73 ], [ %getelementptr3, %bb79 ], [ null, %bb85 ]\n %phi149 = phi ptr addrspace(1) [ null, %bb142 ], [ %getelementptr3, %bb73 ], [ null, %bb79 ], [ null, %bb85 ]\n br label %bb150\n\nbb150: ; preds = %bb146, %bb80, %bb75, %bb1\n %phi151 = phi ptr addrspace(1) [ %getelementptr2, %bb75 ], [ %getelementptr3, %bb80 ], [ null, %bb146 ], [ %getelementptr, %bb1 ]\n %phi152 = phi ptr addrspace(1) [ %getelementptr3, %bb75 ], [ null, %bb80 ], [ null, %bb146 ], [ %getelementptr2, %bb1 ]\n br label %bb153\n\nbb153: ; preds = %bb150, %bb76\n %phi154 = phi ptr addrspace(1) [ null, %bb150 ], [ %getelementptr3, %bb76 ]\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses!.. LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with the test below using -passes=slp-vectorizer -slp-threshold=-99999:\n\n[reduced-stripped.ll.zip](https://github.com/user-attachments/files/20462672/reduced-stripped.ll.zip)\n\nReproducer: https://godbolt.org/z/sf4Kvsqxa\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 \"verify\" on module \"<source>\"\n #0 0x00000000055ff378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x55ff378)\n #1 0x00000000055fcd04 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007a8d0c442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007a8d0c4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007a8d0c442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007a8d0c4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x0000000000810401 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\n #7 0x000000000553a631 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x553a631)\n #8 0x0000000005435df8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5435df8)\n #9 0x000000000094557e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94557e)\n#10 0x00000000053f3af0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x53f3af0)\n#11 0x000000000094f9ca 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+0x94f9ca)\n#12 0x000000000094319c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94319c)\n#13 0x00007a8d0c429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#14 0x00007a8d0c429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#15 0x000000000093add5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93add5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
106641
https://github.com/llvm/llvm-project/issues/106641
crash
c8568f09577e9332d15edf98beb5376dc8d0672e
2024-08-29T23:08:58
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "f0e34f381866b82a26241f7e9aa5964f0dd11ebd", "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": [ [ 7147, 7153 ], [ 7250, 7259 ], [ 7284, 7299 ], [ 7364, 7371 ] ], "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::computeBestVF", "LoopVectorizationPlanner::precomputeCosts", "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 f0e34f381866b82a26241f7e9aa5964f0dd11ebd Author: Florian Hahn <[email protected]> Date: Fri Aug 30 11:29:29 2024 +0100 [VPlan] Don't skip optimizable truncs in planContainsAdditionalSimps. A optimizable cast can also be removed by VPlan simplifications. Remove the restriction from planContainsAdditionalSimplifications, as this causes it to miss relevant simplifications, triggering false positives for the cost decision verification. Also adds debug output for printing additional cost-precomputations. Fixes https://github.com/llvm/llvm-project/issues/106641. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6babfd1eee91..fa05b8dd2242 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7147,7 +7147,12 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, if (!OrigLoop->contains(CondI) || !CostCtx.SkipCostComputation.insert(CondI).second) continue; - Cost += CostCtx.getLegacyCost(CondI, VF); + InstructionCost CondICost = CostCtx.getLegacyCost(CondI, VF); + LLVM_DEBUG({ + dbgs() << "Cost of " << CondICost << " for VF " << VF + << ": exit condition instruction " << *CondI << "\n"; + }); + Cost += CondICost; for (Value *Op : CondI->operands()) { auto *OpI = dyn_cast<Instruction>(Op); if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) { @@ -7250,10 +7255,9 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, /// not have corresponding recipes in \p Plan and are not marked to be ignored /// in \p CostCtx. This means the VPlan contains simplification that the legacy /// cost-model did not account for. -static bool -planContainsAdditionalSimplifications(VPlan &Plan, ElementCount VF, - VPCostContext &CostCtx, Loop *TheLoop, - LoopVectorizationCostModel &CM) { +static bool planContainsAdditionalSimplifications(VPlan &Plan, + VPCostContext &CostCtx, + Loop *TheLoop) { // First collect all instructions for the recipes in Plan. auto GetInstructionForCost = [](const VPRecipeBase *R) -> Instruction * { if (auto *S = dyn_cast<VPSingleDefRecipe>(R)) @@ -7284,16 +7288,13 @@ planContainsAdditionalSimplifications(VPlan &Plan, ElementCount VF, // Return true if the loop contains any instructions that are not also part of // the VPlan or are skipped for VPlan-based cost computations. This indicates // that the VPlan contains extra simplifications. - return any_of( - TheLoop->blocks(), [&SeenInstrs, VF, &CostCtx, &CM](BasicBlock *BB) { - return any_of(*BB, [&SeenInstrs, VF, &CostCtx, &CM](Instruction &I) { - if (isa<PHINode>(&I)) - return false; - return !SeenInstrs.contains(&I) && - !CostCtx.skipCostComputation(&I, true) && - !CM.canTruncateToMinimalBitwidth(&I, VF); - }); - }); + return any_of(TheLoop->blocks(), [&SeenInstrs, &CostCtx](BasicBlock *BB) { + return any_of(*BB, [&SeenInstrs, &CostCtx](Instruction &I) { + if (isa<PHINode>(&I)) + return false; + return !SeenInstrs.contains(&I) && !CostCtx.skipCostComputation(&I, true); + }); + }); } #endif @@ -7364,8 +7365,7 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() { precomputeCosts(BestPlan, BestFactor.Width, CostCtx); assert((BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), - BestFactor.Width, CostCtx, - OrigLoop, CM)) && + CostCtx, OrigLoop)) && " VPlan cost model and legacy cost model disagreed"); assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) && "when vectorizing, the scalar cost must be computed.");
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll", "commands": [ "opt -p loop-vectorize -mattr=+v -S %s" ], "tests": [ { "test_name": "truncate_to_i1_used_by_branch", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @truncate_to_i1_used_by_branch(i8 %x, ptr %dst) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %f.039 = phi i8 [ 0, %entry ], [ %add, %loop.latch ]\n %0 = or i8 23, %x\n %extract.t = trunc i8 %0 to i1\n br i1 %extract.t, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n store i8 0, ptr %dst, align 1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %add = add i8 %f.039, 1\n %conv = sext i8 %f.039 to i32\n %cmp = icmp slt i32 %conv, 1\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl256b\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_pr98413_sext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_sext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = sext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_pr98413_zext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_zext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = zext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using c4906588ce47de33d59bcd95f3e82ce2c3e61c23\r\n\r\nTestcase:\r\n```c\r\n_Bool a;\r\nchar b;\r\nunsigned char c;\r\nvoid d(_Bool e[][6]) {\r\n for (signed char f = 0; f < c; f += 3)\r\n for (_Bool g = ({\r\n __typeof__(0) h = e[1][2];\r\n e[f][f] > h ?: h;\r\n });\r\n g; g = b)\r\n for (_Bool i = 0; i < (0 >= 0); i = 1)\r\n a = 0;\r\n}\r\n```\r\nhttps://godbolt.org/z/Eab8s5e1K\r\n\r\nReduced LLVM 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\ndefine void @d() #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup.loopexit: ; preds = %for.cond.cleanup14\r\n ret void\r\n\r\nfor.body: ; preds = %for.cond.cleanup14, %entry\r\n %f.039 = phi i8 [ %add, %for.cond.cleanup14 ], [ 0, %entry ]\r\n %0 = or i8 0, 0\r\n %extract.t = trunc i8 %0 to i1\r\n br i1 %extract.t, label %for.body22.lr.ph, label %for.cond.cleanup14\r\n\r\nfor.body22.lr.ph: ; preds = %for.body\r\n store i8 0, ptr null, align 1\r\n br label %for.cond.cleanup14\r\n\r\nfor.cond.cleanup14: ; preds = %for.body22.lr.ph, %for.body\r\n %add = add i8 %f.039, 1\r\n %conv = sext i8 %f.039 to i32\r\n %cmp = icmp slt i32 %conv, 1\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit\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,+zvl256b,+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,-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:7365: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && \" 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 \"d\"\r\n #0 0x000064cd5b412560 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301e560)\r\n #1 0x000064cd5b40f96f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301b96f)\r\n #2 0x000064cd5b40fac5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000072ec5a042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000072ec5a0969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000072ec5a0969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000072ec5a0969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000072ec5a042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000072ec5a0287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000072ec5a02871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000072ec5a039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000064cd5a3dd109 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe9109)\r\n#12 0x000064cd5a3f3ccb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fffccb)\r\n#13 0x000064cd5a3f6ce1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2002ce1)\r\n#14 0x000064cd5a3f7357 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2003357)\r\n#15 0x000064cd592541b6 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+0xe601b6)\r\n#16 0x000064cd5b21d41f 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+0x2e2941f)\r\n#17 0x000064cd59257346 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+0xe63346)\r\n#18 0x000064cd5b21c19b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2819b)\r\n#19 0x000064cd592535e6 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+0xe5f5e6)\r\n#20 0x000064cd5b21a1dd 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+0x2e261dd)\r\n#21 0x000064cd58a7c106 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+0x688106)\r\n#22 0x000064cd58a6de91 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679e91)\r\n#23 0x000072ec5a029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x000072ec5a029e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x000072ec5a029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x000064cd58a64245 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x670245)\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/EzdEYKW7c\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: #106417\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
113997
https://github.com/llvm/llvm-project/issues/113997
miscompilation
bef3b54ea10a564a2de72f658f2efd64f537c079
2024-10-29T04:11:49
[ "llvm/test/Transforms/GVN", "llvm/test/Transforms/NewGVN" ]
{ "fix_commit": "f16bff1261a92169992c6edf6bc6b38d1c815c8d", "components": [ "GVN", "NewGVN", "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": [ [ 3508, 3513 ] ], "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": [ [ 2189, 2194 ], [ 2734, 2740 ], [ 3000, 3006 ] ], "llvm/lib/Transforms/Scalar/NewGVN.cpp": [ [ 3854, 3859 ], [ 3963, 3968 ], [ 4069, 4076 ], [ 4112, 4128 ] ], "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::patchReplacementInstruction" ], "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": [ "GVNPass::performScalarPRE", "GVNPass::processAssumeIntrinsic", "GVNPass::processInstruction", "patchAndReplaceAllUsesWith" ], "llvm/lib/Transforms/Scalar/NewGVN.cpp": [ "NewGVN::eliminateInstructions", "NewGVN::findPHIOfOpsLeader" ], "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 f16bff1261a92169992c6edf6bc6b38d1c815c8d Author: Yingwei Zheng <[email protected]> Date: Fri Nov 1 12:44:33 2024 +0800 [GVN][NewGVN][Local] Handle attributes for function calls after CSE (#114011) This patch intersects attributes of two calls to avoid introducing UB. It also skips incompatible call pairs in GVN/NewGVN. However, I cannot provide negative tests for these changes. Fixes https://github.com/llvm/llvm-project/issues/113997. diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 2ba600497e00..ad9b1217089d 100644 --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -2189,6 +2189,16 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) { return Changed; } +// Return true iff V1 can be replaced with V2. +static bool canBeReplacedBy(Value *V1, Value *V2) { + if (auto *CB1 = dyn_cast<CallBase>(V1)) + if (auto *CB2 = dyn_cast<CallBase>(V2)) + return CB1->getAttributes() + .intersectWith(CB2->getContext(), CB2->getAttributes()) + .has_value(); + return true; +} + static void patchAndReplaceAllUsesWith(Instruction *I, Value *Repl) { patchReplacementInstruction(I, Repl); I->replaceAllUsesWith(Repl); @@ -2734,7 +2744,7 @@ bool GVNPass::processInstruction(Instruction *I) { // Perform fast-path value-number based elimination of values inherited from // dominators. Value *Repl = findLeader(I->getParent(), Num); - if (!Repl) { + if (!Repl || !canBeReplacedBy(I, Repl)) { // Failure, just remember this instance for future use. LeaderTable.insert(Num, I, I->getParent()); return false; @@ -3000,7 +3010,7 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) { uint32_t TValNo = VN.phiTranslate(P, CurrentBlock, ValNo, *this); Value *predV = findLeader(P, TValNo); - if (!predV) { + if (!predV || !canBeReplacedBy(CurInst, predV)) { predMap.push_back(std::make_pair(static_cast<Value *>(nullptr), P)); PREPred = P; ++NumWithout; diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 13d9e8f186b4..6800ad51cc0a 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -3854,6 +3854,16 @@ Value *NewGVN::findPHIOfOpsLeader(const Expression *E, return nullptr; } +// Return true iff V1 can be replaced with V2. +static bool canBeReplacedBy(Value *V1, Value *V2) { + if (auto *CB1 = dyn_cast<CallBase>(V1)) + if (auto *CB2 = dyn_cast<CallBase>(V2)) + return CB1->getAttributes() + .intersectWith(CB2->getContext(), CB2->getAttributes()) + .has_value(); + return true; +} + bool NewGVN::eliminateInstructions(Function &F) { // This is a non-standard eliminator. The normal way to eliminate is // to walk the dominator tree in order, keeping track of available @@ -3963,6 +3973,9 @@ bool NewGVN::eliminateInstructions(Function &F) { MembersLeft.insert(Member); continue; } + if (!canBeReplacedBy(Member, Leader)) + continue; + LLVM_DEBUG(dbgs() << "Found replacement " << *(Leader) << " for " << *Member << "\n"); auto *I = cast<Instruction>(Member); @@ -4069,8 +4082,11 @@ bool NewGVN::eliminateInstructions(Function &F) { if (DominatingLeader != Def) { // Even if the instruction is removed, we still need to update // flags/metadata due to downstreams users of the leader. - if (!match(DefI, m_Intrinsic<Intrinsic::ssa_copy>())) + if (!match(DefI, m_Intrinsic<Intrinsic::ssa_copy>())) { + if (!canBeReplacedBy(DefI, DominatingLeader)) + continue; patchReplacementInstruction(DefI, DominatingLeader); + } markInstructionForDeletion(DefI); } @@ -4112,17 +4128,21 @@ bool NewGVN::eliminateInstructions(Function &F) { // Don't replace our existing users with ourselves. if (U->get() == DominatingLeader) continue; - LLVM_DEBUG(dbgs() - << "Found replacement " << *DominatingLeader << " for " - << *U->get() << " in " << *(U->getUser()) << "\n"); // If we replaced something in an instruction, handle the patching of // metadata. Skip this if we are replacing predicateinfo with its // original operand, as we already know we can just drop it. auto *ReplacedInst = cast<Instruction>(U->get()); auto *PI = PredInfo->getPredicateInfoFor(ReplacedInst); - if (!PI || DominatingLeader != PI->OriginalOp) + if (!PI || DominatingLeader != PI->OriginalOp) { + if (!canBeReplacedBy(ReplacedInst, DominatingLeader)) + continue; patchReplacementInstruction(ReplacedInst, DominatingLeader); + } + + LLVM_DEBUG(dbgs() + << "Found replacement " << *DominatingLeader << " for " + << *U->get() << " in " << *(U->getUser()) << "\n"); U->set(DominatingLeader); // This is now a use of the dominating leader, which means if the // dominating leader was dead, it's now live! diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 65c1669f92b4..47a704925596 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -3508,6 +3508,17 @@ void llvm::patchReplacementInstruction(Instruction *I, Value *Repl) { else if (!isa<LoadInst>(I)) ReplInst->andIRFlags(I); + // Handle attributes. + if (auto *CB1 = dyn_cast<CallBase>(ReplInst)) { + if (auto *CB2 = dyn_cast<CallBase>(I)) { + bool Success = CB1->tryIntersectAttributes(CB2); + assert(Success && "We should not be trying to sink callbases " + "with non-intersectable attributes"); + // For NDEBUG Compile. + (void)Success; + } + } + // FIXME: If both the original and replacement value are part of the // same control-flow region (meaning that the execution of one // guarantees the execution of the other), then we can combine the
[ { "file": "llvm/test/Transforms/GVN/pr113997.ll", "commands": [ "opt -S -passes=gvn < %s" ], "tests": [ { "test_name": "bucket", "test_body": "define i1 @bucket(i32 noundef %x) {\n %cmp1 = icmp sgt i32 %x, 0\n %ctpop1 = tail call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 %x)\n %cmp2 = icmp samesign ult i32 %ctpop1, 2\n %cond = select i1 %cmp1, i1 %cmp2, i1 false\n br i1 %cond, label %if.then, label %if.else\n\nif.else: ; preds = %0\n %ctpop2 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %x)\n %res = icmp eq i32 %ctpop2, 1\n ret i1 %res\n\nif.then: ; preds = %0\n ret i1 false\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/NewGVN/pr113997.ll", "commands": [ "opt -S -passes=newgvn < %s" ], "tests": [ { "test_name": "bucket", "test_body": "define i1 @bucket(i32 noundef %x) {\n %cmp1 = icmp sgt i32 %x, 0\n %ctpop1 = tail call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 %x)\n %cmp2 = icmp samesign ult i32 %ctpop1, 2\n %cond = select i1 %cmp1, i1 %cmp2, i1 false\n br i1 %cond, label %if.then, label %if.else\n\nif.else: ; preds = %0\n %ctpop2 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %x)\n %res = icmp eq i32 %ctpop2, 1\n ret i1 %res\n\nif.then: ; preds = %0\n ret i1 false\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[GVNPass] Range attribute should be handled after CSE", "body": "Reproducer: https://alive2.llvm.org/ce/z/HAnoKn\r\n```\r\ndefine i1 @src(i32 noundef %x) {\r\n %cmp1 = icmp sgt i32 %x, 0\r\n %ctpop1 = tail call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 %x)\r\n %cmp2 = icmp samesign ult i32 %ctpop1, 2\r\n %cond = select i1 %cmp1, i1 %cmp2, i1 false\r\n br i1 %cond, label %if.then, label %if.else\r\n\r\nif.else:\r\n %ctpop2 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %x)\r\n %res = icmp eq i32 %ctpop2, 1\r\n ret i1 %res\r\n\r\nif.then:\r\n ret i1 false\r\n}\r\n\r\ndefine i1 @tgt(i32 noundef %x) {\r\n %cmp1 = icmp sgt i32 %x, 0\r\n %ctpop1 = tail call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 %x)\r\n %cmp2 = icmp samesign ult i32 %ctpop1, 2\r\n %cond = select i1 %cmp1, i1 %cmp2, i1 false\r\n br i1 %cond, label %if.then, label %if.else\r\n\r\nif.else:\r\n %res = icmp eq i32 %ctpop1, 1\r\n ret i1 %res\r\n\r\nif.then:\r\n ret i1 false\r\n}\r\n```\r\n```\r\n\r\n----------------------------------------\r\ndefine i1 @src(i32 noundef %x) {\r\n#0:\r\n %cmp1 = icmp sgt i32 noundef %x, 0\r\n %ctpop1 = ctpop i32 noundef %x\r\n %#range_0_%ctpop1 = !range i32 %ctpop1, i32 1, i32 32\r\n %cmp2 = icmp samesign ult i32 %#range_0_%ctpop1, 2\r\n %cond = select i1 %cmp1, i1 %cmp2, i1 0\r\n br i1 %cond, label %if.then, label %if.else\r\n\r\nif.else:\r\n %ctpop2 = ctpop i32 noundef %x\r\n %#range_1_%ctpop2 = !range i32 %ctpop2, i32 0, i32 33\r\n %res = icmp eq i32 %#range_1_%ctpop2, 1\r\n ret i1 %res\r\n\r\nif.then:\r\n ret i1 0\r\n}\r\n=>\r\ndefine i1 @tgt(i32 noundef %x) {\r\n#0:\r\n %cmp1 = icmp sgt i32 noundef %x, 0\r\n %ctpop1 = ctpop i32 noundef %x\r\n %#range_0_%ctpop1 = !range i32 %ctpop1, i32 1, i32 32\r\n %cmp2 = icmp samesign ult i32 %#range_0_%ctpop1, 2\r\n %cond = select i1 %cmp1, i1 %cmp2, i1 0\r\n br i1 %cond, label %if.then, label %if.else\r\n\r\nif.else:\r\n %res = icmp eq i32 %#range_0_%ctpop1, 1\r\n ret i1 %res\r\n\r\nif.then:\r\n ret i1 0\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 noundef %x = #x00000000 (0)\r\n\r\nSource:\r\ni1 %cmp1 = #x0 (0)\r\ni32 %ctpop1 = #x00000000 (0)\r\ni32 %#range_0_%ctpop1 = poison\r\ni1 %cmp2 = poison\r\ni1 %cond = #x0 (0)\r\n >> Jump to %if.else\r\ni32 %ctpop2 = #x00000000 (0)\r\ni32 %#range_1_%ctpop2 = #x00000000 (0)\r\ni1 %res = #x0 (0)\r\n\r\nTarget:\r\ni1 %cmp1 = #x0 (0)\r\ni32 %ctpop1 = #x00000000 (0)\r\ni32 %#range_0_%ctpop1 = poison\r\ni1 %cmp2 = poison\r\ni1 %cond = #x0 (0)\r\n >> Jump to %if.else\r\ni1 %res = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n```\r\n\r\nReported by @pranavk. See https://github.com/llvm/llvm-project/pull/100899#issuecomment-2442780517.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:GVN" ], "comments": [] }
true
null
89958
https://github.com/llvm/llvm-project/issues/89958
miscompilation
e913a33fcfbd667e4e3a35919b6bd9c5876a90a3
2024-04-24T17:36:34
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "b060661da8b3b53db55644e5e358bb2dca8b56d7", "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": [ [ 126, 131 ] ], "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [ [ 681, 687 ], [ 1376, 1386 ], [ 1395, 1400 ] ], "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": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [ "SCEVExpander::expandMinMaxExpr", "SCEVExpander::visitSMaxExpr", "SCEVExpander::visitUDivExpr" ], "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 b060661da8b3b53db55644e5e358bb2dca8b56d7 Author: Florian Hahn <[email protected]> Date: Thu Oct 17 13:55:20 2024 -0700 [SCEVExpander] Expand UDiv avoiding UB when in seq_min/max. (#92177) Update SCEVExpander to introduce an SafeUDivMode, which is set when expanding operands of SCEVSequentialMinMaxExpr. In this mode, the expander will make sure that the divisor of the expanded UDiv is neither 0 nor poison. Fixes https://github.com/llvm/llvm-project/issues/89958. PR https://github.com/llvm/llvm-project/pull/92177 diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h index 5697d983c9ad..7dd754a2bc0d 100644 --- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h +++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h @@ -126,6 +126,11 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> { /// "expanded" form. bool LSRMode; + /// When true, rewrite any divisors of UDiv expressions that may be 0 to + /// umax(Divisor, 1) to avoid introducing UB. If the divisor may be poison, + /// freeze it first. + bool SafeUDivMode = false; + typedef IRBuilder<InstSimplifyFolder, IRBuilderCallbackInserter> BuilderType; BuilderType Builder; diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index c412d0398b95..39da38e49181 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -681,7 +681,21 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) { SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true); } - Value *RHS = expand(S->getRHS()); + const SCEV *RHSExpr = S->getRHS(); + Value *RHS = expand(RHSExpr); + if (SafeUDivMode) { + bool GuaranteedNotPoison = + ScalarEvolution::isGuaranteedNotToBePoison(RHSExpr); + if (!GuaranteedNotPoison) + RHS = Builder.CreateFreeze(RHS); + + // We need an umax if either RHSExpr is not known to be zero, or if it is + // not guaranteed to be non-poison. In the later case, the frozen poison may + // be 0. + if (!SE.isKnownNonZero(RHSExpr) || !GuaranteedNotPoison) + RHS = Builder.CreateIntrinsic(RHS->getType(), Intrinsic::umax, + {RHS, ConstantInt::get(RHS->getType(), 1)}); + } return InsertBinop(Instruction::UDiv, LHS, RHS, SCEV::FlagAnyWrap, /*IsSafeToHoist*/ SE.isKnownNonZero(S->getRHS())); } @@ -1376,11 +1390,14 @@ Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) { Value *SCEVExpander::expandMinMaxExpr(const SCEVNAryExpr *S, Intrinsic::ID IntrinID, Twine Name, bool IsSequential) { + bool PrevSafeMode = SafeUDivMode; + SafeUDivMode |= IsSequential; Value *LHS = expand(S->getOperand(S->getNumOperands() - 1)); Type *Ty = LHS->getType(); if (IsSequential) LHS = Builder.CreateFreeze(LHS); for (int i = S->getNumOperands() - 2; i >= 0; --i) { + SafeUDivMode = (IsSequential && i != 0) || PrevSafeMode; Value *RHS = expand(S->getOperand(i)); if (IsSequential && i != 0) RHS = Builder.CreateFreeze(RHS); @@ -1395,6 +1412,7 @@ Value *SCEVExpander::expandMinMaxExpr(const SCEVNAryExpr *S, } LHS = Sel; } + SafeUDivMode = PrevSafeMode; return LHS; }
[ { "file": "<issue>", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "f", "test_body": "define i64 @f(i64 %0) {\n br label %2\n\n2: ; preds = %5, %1\n %3 = phi i64 [ 0, %1 ], [ %6, %5 ]\n %4 = icmp slt i64 %3, %0\n br i1 %4, label %5, label %9\n\n5: ; preds = %2\n %6 = add i64 %3, 1\n %7 = udiv i64 42, %0\n %8 = icmp slt i64 %3, %7\n br i1 %8, label %2, label %9\n\n9: ; preds = %5, %2\n %10 = phi i64 [ 1, %2 ], [ 0, %5 ]\n ret i64 %10\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "miscompilation due to LoopVectorize making a function vulnerable to integer divide-by-zero", "body": "https://alive2.llvm.org/ce/z/Kx2anL\r\n\r\nthis function:\r\n```llvm\r\ndefine i64 @f(i64 %0) {\r\n br label %2\r\n\r\n2: ; preds = %5, %1\r\n %3 = phi i64 [ 0, %1 ], [ %6, %5 ]\r\n %4 = icmp slt i64 %3, %0\r\n br i1 %4, label %5, label %9\r\n\r\n5: ; preds = %2\r\n %6 = add i64 %3, 1\r\n %7 = udiv i64 42, %0\r\n %8 = icmp slt i64 %3, %7\r\n br i1 %8, label %2, label %9\r\n\r\n9: ; preds = %5, %2\r\n %10 = phi i64 [ 1, %2 ], [ 0, %5 ]\r\n ret i64 %10\r\n}\r\n```\r\nis getting optimized to:\r\n```lllvm\r\ndefine noundef i64 @f(i64 %0) local_unnamed_addr #0 {\r\n %smax = tail call i64 @llvm.smax.i64(i64 %0, i64 0)\r\n %2 = udiv i64 42, %0\r\n %umin = tail call i64 @llvm.umin.i64(i64 %smax, i64 %2)\r\n %min.iters.check = icmp ult i64 %umin, 4\r\n br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph\r\n\r\nvector.ph: ; preds = %1\r\n %3 = add nuw nsw i64 %umin, 1\r\n %n.mod.vf = and i64 %3, 3\r\n %4 = icmp eq i64 %n.mod.vf, 0\r\n %5 = select i1 %4, i64 4, i64 %n.mod.vf\r\n %n.vec = sub nsw i64 %3, %5\r\n br label %vector.body\r\n\r\nvector.body: ; preds = %vector.body, %vector.ph\r\n %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]\r\n %index.next = add nuw i64 %index, 4\r\n %6 = icmp eq i64 %index.next, %n.vec\r\n br i1 %6, label %scalar.ph.preheader, label %vector.body, !llvm.loop !0\r\n\r\nscalar.ph.preheader: ; preds = %vector.body, %1\r\n %.ph = phi i64 [ 0, %1 ], [ %n.vec, %vector.body ]\r\n br label %scalar.ph\r\n\r\nscalar.ph: ; preds = %scalar.ph.preheader, %9\r\n %7 = phi i64 [ %10, %9 ], [ %.ph, %scalar.ph.preheader ]\r\n %8 = icmp slt i64 %7, %0\r\n br i1 %8, label %9, label %13\r\n\r\n9: ; preds = %scalar.ph\r\n %10 = add nuw nsw i64 %7, 1\r\n %11 = udiv i64 42, %0\r\n %12 = icmp ult i64 %7, %11\r\n br i1 %12, label %scalar.ph, label %13, !llvm.loop !3\r\n\r\n13: ; preds = %9, %scalar.ph\r\n %14 = phi i64 [ 1, %scalar.ph ], [ 0, %9 ]\r\n ret i64 %14\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.smax.i64(i64, i64) #1\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.umin.i64(i64, i64) #1\r\n\r\nattributes #0 = { nofree norecurse nosync nounwind memory(none) }\r\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n\r\n!0 = distinct !{!0, !1, !2}\r\n!1 = !{!\"llvm.loop.isvectorized\", i32 1}\r\n!2 = !{!\"llvm.loop.unroll.runtime.disable\"}\r\n!3 = distinct !{!3, !2, !1}\r\n```\r\n\r\nthe problem is that the optimized code can divide by zero even when the original code doesn't. to see this, pass 0 as an argument to `f`. I also independently verified on an x64-64 that the optimized code traps out with an FPE while the original code does not. it's LoopVectorize that's the culprit.\r\n\r\ncc @nunoplopes @hatsunespica\r\n", "author": "regehr", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "dtcxzyw", "body": "cc @fhahn " } ] }
true
null
105722
https://github.com/llvm/llvm-project/issues/105722
crash
84497c6f4f6c79b0d8c38da666724eed7e9e8db5
2024-08-22T19:30:39
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "533e6bbd0d344a710c491a9eb0ce0ba0852b08cb", "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": 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": [ [ 13, 18 ], [ 173, 178 ] ], "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": 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": [ "getVPValueOrAddLiveIn" ], "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 533e6bbd0d344a710c491a9eb0ce0ba0852b08cb Author: Florian Hahn <[email protected]> Date: Mon Aug 26 09:15:58 2024 +0100 [VPlan] Simplify live-ins if they are SCEVConstant. The legacy cost model in some parts checks if any of the operands are constants via SCEV. Update VPlan construction to replace live-ins that are constants via SCEV with such constants. This means VPlans (and codegen) reflects what we computing the cost of and removes another case where the legacy and VPlan cost model diverged. Fixes https://github.com/llvm/llvm-project/issues/105722. diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h index 0b27933925d8..0fbdeeddaf4a 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -13,6 +13,7 @@ #include "VPlan.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/IR/IRBuilder.h" namespace llvm { @@ -173,6 +174,11 @@ public: if (auto *R = Ingredient2Recipe.lookup(I)) return R->getVPSingleValue(); } + ScalarEvolution &SE = *PSE.getSE(); + if (!isa<Constant>(V) && SE.isSCEVable(V->getType())) + if (auto *C = dyn_cast<SCEVConstant>(PSE.getSE()->getSCEV(V))) + return Plan.getOrAddLiveIn(C->getValue()); + return Plan.getOrAddLiveIn(V); } };
[ { "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": "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": "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": "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": "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_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": "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": "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 }, { "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": "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 } ] } ]
{ "title": "[clang] Assertion failed in Vectorize", "body": "To reproduce, compile it with -O2: clang -O2 example.c\r\n\r\n```c\r\n#include <stdint.h>\r\nint a;\r\nlong b;\r\nstatic int32_t c;\r\nvoid d(int e, int h) {\r\n int f = a = 1;\r\n for (; a <= e; a++)\r\n f *= a;\r\n a = 0;\r\n for (; a < h; a++)\r\n b *= f;\r\n}\r\nlong g() {}\r\nint32_t i() {\r\n for (; g();)\r\n for (c = 3;;)\r\n ;\r\n}\r\nuint16_t j() { d(c + 1, c + 6); }\r\n```\r\n\r\nThe error message is as follows:\r\n\r\n```\r\nllvm/lib/Transforms/Vectorize/LoopVectorize.cpp:9985: bool llvm::LoopVectorizePass::processLoop(llvm::Loop *): Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\n```", "author": "cardigan1008", "labels": [ "vectorizers", "confirmed", "crash" ], "comments": [ { "author": "EugeneZelenko", "body": "See https://godbolt.org/z/jc8qqo8Ta" }, { "author": "shafik", "body": "Looks like a recent regression since it does not crash on trunk: https://godbolt.org/z/sKjdvMq54\r\n\r\nAssertion:\r\n\r\n```console\r\nclang++: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7288: \r\nllvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF():\r\nAssertion `BestFactor.Width == LegacyVF.Width && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n```\r\n\r\nBacktrace: \r\n\r\n```console\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.\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 -x c -O2 <source>\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\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-use-loop-info;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;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;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"j\"\r\n #0 0x0000000003b02648 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b02648)\r\n #1 0x0000000003b0033c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b0033c)\r\n #2 0x0000000003a492b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x000078485ee42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000078485ee969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #5 0x000078485ee42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #6 0x000078485ee287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #7 0x000078485ee2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #8 0x000078485ee39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #9 0x00000000054df418 llvm::LoopVectorizationPlanner::computeBestVF() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54df418)\r\n#10 0x00000000054fa07a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54fa07a)\r\n#11 0x00000000054fcd39 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54fcd39)\r\n#12 0x00000000054fd3c3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54fd3c3)\r\n#13 0x00000000050ac09e 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+++0x50ac09e)\r\n#14 0x00000000034cac68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34cac68)\r\n#15 0x00000000010bce6e 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+++0x10bce6e)\r\n#16 0x00000000034c966e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34c966e)\r\n#17 0x00000000010bc75e 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+++0x10bc75e)\r\n#18 0x00000000034c7800 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34c7800)\r\n#19 0x0000000003da8895 (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 0x0000000003dab9fd 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+++0x3dab9fd)\r\n#21 0x00000000044196ac clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44196ac)\r\n#22 0x000000000651f80c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x651f80c)\r\n#23 0x0000000004419b18 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4419b18)\r\n#24 0x00000000046a79f9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46a79f9)\r\n#25 0x000000000462b30e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x462b30e)\r\n#26 0x000000000479104e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x479104e)\r\n#27 0x0000000000ca5b0f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca5b0f)\r\n#28 0x0000000000c9ed5a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#29 0x000000000445d1d9 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#30 0x0000000003a49764 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a49764)\r\n#31 0x000000000445d7cf 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#32 0x0000000004423365 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4423365)\r\n#33 0x0000000004423dcd 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+++0x4423dcd)\r\n#34 0x000000000442b9e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b9e5)\r\n#35 0x0000000000ca2f05 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca2f05)\r\n#36 0x0000000000b776e4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb776e4)\r\n#37 0x000078485ee29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#38 0x000078485ee29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#39 0x0000000000c9e80e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9e80e)\r\nclang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nCompiler returned: 134\r\n```" }, { "author": "cardigan1008", "body": "The crash persists in the above cases even with the applied patches. " }, { "author": "fhahn", "body": "@cardigan1008 I can't reproduce the crash locally with latest main. If it still reproduces on current main for you, could you share the crashing IR, using `-mllvm -print-on-crash -mllvm -print-module-scope`?" }, { "author": "cardigan1008", "body": "@fhahn Apologies for the confusion. I pulled the latest version, and this case is now working. However, I encountered a similar crash with another case that I'm currently fuzzing. I'll open a separate issue as soon as I've finished reducing it." }, { "author": "cardigan1008", "body": "Hi @fhahn , I have submitted another issue with the same crash in #106248 . " } ] }
true
null
91957
https://github.com/llvm/llvm-project/issues/91957
miscompilation
c2a9a974ca85e4ac4509e368d4b9acae7e67bf71
2024-05-13T13:05:21
[ "llvm/test/Transforms/LICM" ]
{ "fix_commit": "70091dc943ade280d75cea1e5ea5e93d9a8f934a", "components": [ "LICM" ], "bug_location_lineno": { "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": [ [ 2751, 2757 ], [ 2759, 2766 ] ], "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": null, "llvm/lib/Transforms/Scalar/LICM.cpp": [ "hoistMulAddAssociation" ], "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 70091dc943ade280d75cea1e5ea5e93d9a8f934a Author: Antonio Frighetto <[email protected]> Date: Sat May 18 16:52:17 2024 +0200 [LICM] Invalidate cached SCEV results in `hoistMulAddAssociation` While reassociating expressions, LICM is required to invalidate SCEV results, as otherwise subsequent passes in the pipeline that leverage LICM foldings (e.g. IndVars), may reason on invalid expressions; thus miscompiling. This is achieved by rewriting the reassociable instruction from scratch. Fixes: https://github.com/llvm/llvm-project/issues/91957. diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 6aa4188d1cc4..5eccf7b4adb6 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -2751,7 +2751,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L, IRBuilder<> Builder(Preheader->getTerminator()); for (auto *U : Changes) { assert(L.isLoopInvariant(U->get())); - Instruction *Ins = cast<Instruction>(U->getUser()); + auto *Ins = cast<BinaryOperator>(U->getUser()); Value *Mul; if (I.getType()->isIntOrIntVectorTy()) { Mul = Builder.CreateMul(U->get(), Factor, "factor.op.mul"); @@ -2759,8 +2759,20 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L, Ins->dropPoisonGeneratingFlags(); } else Mul = Builder.CreateFMulFMF(U->get(), Factor, Ins, "factor.op.fmul"); - U->set(Mul); + + // Rewrite the reassociable instruction. + unsigned OpIdx = U->getOperandNo(); + auto *LHS = OpIdx == 0 ? Mul : Ins->getOperand(0); + auto *RHS = OpIdx == 1 ? Mul : Ins->getOperand(1); + auto *NewBO = BinaryOperator::Create(Ins->getOpcode(), LHS, RHS, + Ins->getName() + ".reass", Ins); + NewBO->copyIRFlags(Ins); + if (VariantOp == Ins) + VariantOp = NewBO; + Ins->replaceAllUsesWith(NewBO); + eraseInstruction(*Ins, SafetyInfo, MSSAU); } + I.replaceAllUsesWith(VariantOp); eraseInstruction(I, SafetyInfo, MSSAU); return true;
[ { "file": "llvm/test/Transforms/LICM/update-scev-after-hoist.ll", "commands": [ "opt -S -passes='loop-unroll,loop-mssa(licm,indvars)' -unroll-count=4 < %s 2>&1" ], "tests": [ { "test_name": "main", "test_body": "define i16 @main() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %mul = phi i16 [ 1, %entry ], [ %mul.n, %loop ]\n %div = phi i16 [ 32767, %entry ], [ %div.n, %loop ]\n %mul.n = mul i16 %mul, 2\n %div.n = sdiv i16 %div, 2\n %cmp = icmp sgt i16 %div, 0\n br i1 %cmp, label %loop, label %end\n\nend: ; preds = %loop\n ret i16 %mul\n}\n", "additional_args": "-src-unroll=16 -tgt-unroll=16", "lli_expected_out": null } ] } ]
{ "title": "Miscompile with opt -passes=\"loop-unroll,loop-mssa(licm,indvars)\" -unroll-count=4 ", "body": "llvm commit: e76b257483e6c\r\nReproduce with:\r\n```opt -passes=\"loop-unroll,loop-mssa(licm,indvars)\" -unroll-count=4 bbi-95405.ll -S -o -```\r\n\r\nThe input function returns 32768, but after running the passes as above we get\r\n```\r\ndefine i16 @foo() {\r\nentry:\r\n br label %loop\r\n\r\nloop: ; preds = %loop, %entry\r\n br i1 false, label %loop, label %end, !llvm.loop !0\r\n\r\nend: ; preds = %loop\r\n ret i16 8192\r\n}\r\n\r\n!0 = distinct !{!0, !1}\r\n!1 = !{!\"llvm.loop.unroll.disable\"}\r\n```\r\nSo now the function returns 8192 instead.\r\n\r\nIf I extract the IR after loop-unroll or licm and run the rest of the passes instead I get the correct result.\r\n\r\n[bbi-95405.ll.gz](https://github.com/llvm/llvm-project/files/15294896/bbi-95405.ll.gz)\r\n", "author": "mikaelholmen", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "mikaelholmen", "body": "This starts happening with https://github.com/llvm/llvm-project/pull/67736 , commit 2dd52046816\r\n```\r\nRecommit \"[LICM] Support integer mul/add in hoistFPAssociation. (#67736)\"\r\n\r\nWith a fix for build bot failure. I was accessing the type of a deleted\r\nInstruction.\r\n\r\nOriginal message:\r\n\r\nThe reassociation this is trying to repair can happen for integer types\r\ntoo.\r\n\r\nThis patch adds support for integer mul/add to hoistFPAssociation. The\r\nfunction has been renamed to hoistMulAddAssociation. I've used separate\r\nstatistics and limits for integer to allow tuning flexibility.\r\n```\r\n" }, { "author": "nikic", "body": "Without looking into this in detail, it's possible that the way the LICM code modifies instructions in place results incorrect cached SCEV results." }, { "author": "mikaelholmen", "body": "> Without looking into this in detail, it's possible that the way the LICM code modifies instructions in place results incorrect cached SCEV results.\r\n\r\nI added some printouts and see that when IndVarSimplify run rewriteLoopExitValues we do\r\n```\r\nconst SCEV *ExitValue = SE->getSCEVAtScope(Inst, L->getParentLoop());\r\n```\r\nfor Inst being\r\n```\r\n%mul.n = mul i16 %mul, 8\r\n```\r\nand then we get the SCEV\r\n```\r\n(2 * %mul)\r\n```\r\nwhich looks wrong.\r\n\r\nIf I split up the pipeline in several opt runs we instead get the SCEV\r\n```\r\n(8 * %mul)\r\n```\r\nwhich looks more reasonable (and then we also get the correct result).\r\nLICM changed\r\n```\r\n%mul.n = mul i16 %mul, 2\r\n```\r\nto\r\n```\r\n%mul.n = mul i16 %mul, 8\r\n```\r\nso yeah, it should perhaps do something (more) about SCEV." }, { "author": "mikaelholmen", "body": "@antoniofrighetto : nice that you work on this!\r\n\r\nBut oh it's annoying that I don't get any emails from github about that there was activity here with a linked PR with a fix etc even if I wrote this issue. :( I do get emails when there are comments but not when the issue was assigned or the PR was created. :(" }, { "author": "antoniofrighetto", "body": "@mikaelholmen This is a bit inconvenient indeed, GH doesn’t seem to send notifications wrt that :( Closed this, thanks for reporting!" }, { "author": "mikaelholmen", "body": "> @mikaelholmen This is a bit inconvenient indeed, GH doesn’t seem to send notifications wrt that :( Closed this, thanks for reporting!\r\n\r\nThank you!" } ] }
true
null
142405
https://github.com/llvm/llvm-project/issues/142405
hang
20d70196c9a4da344d0944f3c78447c3bd7079c7
2025-06-02T14:38:42
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "5e2dcfe42cd4af14d6e6155314aa5d4167710b65", "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": [ [ 1312, 1318 ] ], "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 5e2dcfe42cd4af14d6e6155314aa5d4167710b65 Author: Yingwei Zheng <[email protected]> Date: Wed Jun 4 19:42:56 2025 +0800 [InstCombine] Avoid infinite loop in `foldSelectValueEquivalence` (#142754) Before this patch, InstCombine hung because it replaced a value with a more complex one: ``` %sel = select i1 %cmp, i32 %smax, i32 0 -> %sel = select i1 %cmp, i32 %masked, i32 0 -> %sel = select i1 %cmp, i32 %smax, i32 0 -> ... ``` This patch makes this replacement more conservative. It only performs the replacement iff the new value is one of the operands of the original value. Closes https://github.com/llvm/llvm-project/issues/142405. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index d7d0431a5b8d..257dc943bd5c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1312,7 +1312,11 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel, // If NewOp is a constant and OldOp is not replace iff NewOp doesn't // contain and undef elements. - if (match(NewOp, m_ImmConstant()) || NewOp == V) { + // Make sure that V is always simpler than TrueVal, otherwise we might + // end up in an infinite loop. + if (match(NewOp, m_ImmConstant()) || + (isa<Instruction>(TrueVal) && + is_contained(cast<Instruction>(TrueVal)->operands(), V))) { if (isGuaranteedNotToBeUndef(NewOp, SQ.AC, &Sel, &DT)) return replaceOperand(Sel, Swapped ? 2 : 1, V); return nullptr;
[ { "file": "llvm/test/Transforms/InstCombine/select-cmp-eq-op-fold.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "replace_with_y_for_simple_binop_fail", "test_body": "define i8 @replace_with_y_for_simple_binop_fail(i8 %x, i8 noundef %y, i8 %z, i8 %q) {\n %cmp = icmp eq i8 %x, %y\n %mul = mul nsw i8 %x, %q\n %sel = select i1 %cmp, i8 %mul, i8 %z\n ret i8 %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr142405", "test_body": "define i32 @pr142405(i32 noundef %x) {\nentry:\n %smax = call i32 @llvm.smax.i32(i32 %x, i32 0)\n %masked = and i32 %smax, 65535\n %cmp = icmp eq i32 %x, %masked\n %sel = select i1 %cmp, i32 %smax, i32 0\n %and = and i32 %sel, 1\n ret i32 %and\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smax.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] Infinite loop at -O3", "body": "Reproducer: https://godbolt.org/z/aYWhfr6Y9\n```\n; bin/opt -passes=instcombine test.ll -S\ndefine i32 @test(i32 noundef %0) {\nentry:\n %cond.i = call i32 @llvm.smax.i32(i32 %0, i32 0)\n %conv.i = trunc i32 %cond.i to i16\n %conv21 = zext i16 %conv.i to i32\n %cmp22 = icmp eq i32 %0, %conv21\n %conv23 = zext i1 %cmp22 to i32\n %narrow.i = mul i32 %cond.i, %conv23\n %1 = and i32 %narrow.i, 1\n ret i32 %1\n}\n```\n", "author": "dtcxzyw", "labels": [ "llvm:instcombine", "hang", "generated by fuzzer" ], "comments": [] }
true
null
112356
https://github.com/llvm/llvm-project/issues/112356
miscompilation
a3a9ba80337ec1b276a7571049eda6ea03276ea3
2024-10-15T13:21:27
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "9b7491e8669126180253480821d5addde34874d0", "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": 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": [ [ 50, 55 ] ], "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": 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": [ "Operator::hasPoisonGeneratingFlags" ], "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 9b7491e8669126180253480821d5addde34874d0 Author: Yingwei Zheng <[email protected]> Date: Tue Oct 15 23:07:16 2024 +0800 [IR] Add support for `samesign` in `Operator::hasPoisonGeneratingFlags` (#112358) Fix https://github.com/llvm/llvm-project/issues/112356. diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp index f93ff8f6fc8a..199eb4d90f55 100644 --- a/llvm/lib/IR/Operator.cpp +++ b/llvm/lib/IR/Operator.cpp @@ -50,6 +50,8 @@ bool Operator::hasPoisonGeneratingFlags() const { if (auto *NNI = dyn_cast<PossiblyNonNegInst>(this)) return NNI->hasNonNeg(); return false; + case Instruction::ICmp: + return cast<ICmpInst>(this)->hasSameSign(); default: if (const auto *FP = dyn_cast<FPMathOperator>(this)) return FP->hasNoNaNs() || FP->hasNoInfs();
[ { "file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "icmp_samesign_logical_or", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3: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 i1 @icmp_samesign_logical_or(i32 %In) {\n %c1 = icmp samesign slt i32 %In, 0\n %c2 = icmp samesign ne i32 %In, 1\n %V = select i1 %c1, i1 true, i1 %c2\n ret i1 %V\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmp_and_inv_pow2_or_zero_ne_0", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3: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\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i1 @icmp_and_inv_pow2_or_zero_ne_0(i32 %A, i32 %B) {\n %popcnt = tail call i32 @llvm.ctpop.i32(i32 %A)\n %cond = icmp ult i32 %popcnt, 2\n call void @llvm.assume(i1 %cond)\n %inv = xor i32 %B, -1\n %and = and i32 %A, %inv\n %cmp = icmp ne i32 %and, 0\n ret i1 %cmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #1\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmp_samesign_logical_and", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3: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 i1 @icmp_samesign_logical_and(i32 %In) {\n %c1 = icmp samesign sgt i32 %In, -1\n %c2 = icmp samesign eq i32 %In, 1\n %V = select i1 %c1, i1 %c2, i1 false\n ret i1 %V\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped", "body": "Reproducer:\r\n```\r\ndefine i1 @src(i32 %In) {\r\n %c1 = icmp samesign sgt i32 %In, -1\r\n %c2 = icmp samesign eq i32 %In, 1\r\n %V = select i1 %c1, i1 %c2, i1 false\r\n ret i1 %V\r\n}\r\n\r\ndefine i1 @tgt(i32 %In) {\r\n %c2 = icmp samesign eq i32 %In, 1\r\n ret i1 %c2\r\n}\r\n```\r\n\r\nWe should check this flag in `Operator::hasPoisonGeneratingFlags`.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:ir" ], "comments": [] }
true
null
109528
https://github.com/llvm/llvm-project/issues/109528
crash
586736226e3a25b1fd647d3257270c1388f907bf
2024-09-21T14:20:16
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "6d6eea92e36c301e34a7ec11b2a40e3080f79f53", "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": [ [ 8420, 8440 ] ], "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": [ "VPRecipeBuilder::tryToWiden" ], "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 6d6eea92e36c301e34a7ec11b2a40e3080f79f53 Author: Florian Hahn <[email protected]> Date: Wed Oct 2 13:45:48 2024 +0100 [LV] Use SCEV to simplify wide binop operand to constant. The legacy cost model uses SCEV to determine if the second operand of a binary op is a constant. Update the VPlan construction logic to mirror the current legacy behavior, to fix a difference in the cost models. Fixes https://github.com/llvm/llvm-project/issues/109528. Fixes https://github.com/llvm/llvm-project/issues/110440. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index e1f9f29ac6d9..de3b981a4fe3 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8420,21 +8420,28 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, case Instruction::Sub: case Instruction::Xor: case Instruction::Freeze: - if (I->getOpcode() == Instruction::Mul) { - // Simplify operands of multiplications using SCEV. This is needed at the - // moment to match the behavior of the legacy cost-model. - // TODO: Generalize to any opcode and move to VPlan transformation. - SmallVector<VPValue *> NewOps(Operands); + SmallVector<VPValue *> NewOps(Operands); + if (Instruction::isBinaryOp(I->getOpcode())) { + // The legacy cost model uses SCEV to check if some of the operands are + // constants. To match the legacy cost model's behavior, use SCEV to try + // to replace operands with constants. ScalarEvolution &SE = *PSE.getSE(); - for (unsigned I = 0; I < Operands.size(); ++I) { - Value *V = NewOps[I]->getUnderlyingValue(); - if (!isa<Constant>(V) && SE.isSCEVable(V->getType())) - if (auto *C = dyn_cast<SCEVConstant>(PSE.getSE()->getSCEV(V))) - NewOps[I] = Plan.getOrAddLiveIn(C->getValue()); - } - return new VPWidenRecipe(*I, make_range(NewOps.begin(), NewOps.end())); + auto GetConstantViaSCEV = [this, &SE](VPValue *Op) { + Value *V = Op->getUnderlyingValue(); + if (isa<Constant>(V) || !SE.isSCEVable(V->getType())) + return Op; + auto *C = dyn_cast<SCEVConstant>(SE.getSCEV(V)); + if (!C) + return Op; + return Plan.getOrAddLiveIn(C->getValue()); + }; + // For Mul, the legacy cost model checks both operands. + if (I->getOpcode() == Instruction::Mul) + NewOps[0] = GetConstantViaSCEV(NewOps[0]); + // For other binops, the legacy cost model only checks the second operand. + NewOps[1] = GetConstantViaSCEV(NewOps[1]); } - return new VPWidenRecipe(*I, make_range(Operands.begin(), Operands.end())); + return new VPWidenRecipe(*I, make_range(NewOps.begin(), NewOps.end())); }; }
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "test_foldable_live_in_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 @test_foldable_live_in_via_scev() {\nentry:\n %conv = zext i16 -6 to i64\n %add = add nsw i64 %conv, -65528\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]\n %red = phi i64 [ 1, %entry ], [ %mul, %loop ]\n %mul = mul nsw i64 %red, %add\n %iv.next = add nsw i32 %iv, 1\n %ec = icmp eq i32 %iv.next, 100\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %ret = phi i64 [ %mul, %loop ]\n ret i64 %ret\n}\n", "additional_args": null, "lli_expected_out": null }, { "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, 0\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 } ] } ]
{ "title": "[clang] Assertion failed in Vectorize", "body": "When I compiled this code with O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\nstatic uint64_t\r\nsafe_sub_func_uint64_t_u_u(uint64_t ui1, uint64_t ui2)\r\n{\r\n return ui1 - ui2;\r\n}\r\nlong a;\r\nstatic int8_t c;\r\nvoid b(long d, int f) {\r\n int e = 0;\r\n for (; e < 64; e++)\r\n if (e - f)\r\n a |= e >> f;\r\n else\r\n a |= d & e;\r\n}\r\nuint32_t g() {\r\n b(6, c);\r\n for (;; c = safe_sub_func_uint64_t_u_u(c, 4))\r\n ;\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7383: 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\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/7733x1hvP", "author": "cardigan1008", "labels": [ "vectorizers", "confirmed", "crash" ], "comments": [ { "author": "shafik", "body": "This looks like a regression in trunk: https://godbolt.org/z/eo7WG1e66" }, { "author": "hiraditya", "body": "Probably a recent change caused this? cc: @ayalz @fhahn " } ] }
true
null
106239
https://github.com/llvm/llvm-project/issues/106239
crash
15405b32b1cdbefab9ce1b1f301a51ae25404037
2024-08-27T15:51:29
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "c9a5e1b665dbba898e9981fd7d48881947e6560e", "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": [ [ 1928, 1945 ] ], "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::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 c9a5e1b665dbba898e9981fd7d48881947e6560e Author: Nikita Popov <[email protected]> Date: Wed Aug 28 12:54:14 2024 +0200 [IndVars] Check if WideInc available before trying to use it WideInc/WideIncExpr can be null. Previously this worked out because the comparison with WideIncExpr would fail. Now we have accesses to WideInc prior to that. Avoid the issue with an explicit check. Fixes https://github.com/llvm/llvm-project/issues/106239. diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 8e3a14bb4f6d..a950a4f57ef4 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1928,18 +1928,24 @@ Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU, if (!WideAddRec.first) return nullptr; - // 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(); + auto CanUseWideInc = [&]() { + if (!WideInc) + return false; + // 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(); + return WideAddRec.first == WideIncExpr && + Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags); + }; + Instruction *WideUse = nullptr; - if (WideAddRec.first == WideIncExpr && - Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags)) + if (CanUseWideInc()) WideUse = WideInc; else { WideUse = cloneIVUser(DU, WideAddRec.first);
[ { "file": "llvm/test/Transforms/IndVarSimplify/pr106239.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "m", "test_body": "target datalayout = \"n8:16:32:64\"\n\ndefine i32 @m() {\nentry:\n %div.i4 = sdiv i32 1, 0\n br label %for.body.i6\n\nfor.body.i6: ; preds = %if.end.i, %entry\n %add57.i = phi i32 [ %add.i7, %if.end.i ], [ 0, %entry ]\n br i1 true, label %i.exit, label %if.end.i\n\nif.end.i: ; preds = %for.body.i6\n %add.i7 = add i32 %add57.i, %div.i4\n %conv.i = zext i32 %add57.i to i64\n store i64 %conv.i, ptr null, align 8\n br label %for.body.i6\n\ni.exit: ; preds = %for.body.i6\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Crash with O2 optimization flag", "body": "I compiled this code with -O2 flag and it crashed. The code is:\r\n\r\n```c\r\n#include <stdint.h>\r\nlong a, c;\r\nunsigned d;\r\nint32_t g;\r\nuint8_t h[];\r\nlong b(long p1, long k) {\r\n long e = k;\r\n int b = 0;\r\n while (e) {\r\n e /= 10;\r\n b++;\r\n }\r\n for (int f = 0; f < b; f++)\r\n p1 *= 10;\r\n a = p1 + k;\r\n return a;\r\n}\r\nlong i(int p1, int, int l) {\r\n int j = l / p1;\r\n for (int f = 0; f < p1; f++) {\r\n if (d > l)\r\n break;\r\n c = d += j;\r\n }\r\n}\r\nuint32_t m() {\r\n for (g = 8; b(35, 46) - 3546 + g >= 0; g--)\r\n ;\r\n h[i(g + 1, 0, -4294967221)];\r\n}\r\n```\r\n\r\nThe crash is: clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::BinaryOperator; From = llvm::Instruction]: Assertion `detail::isPresent(Val) && \"dyn_cast on a non-existent value\"' failed.\r\n\r\n\r\nThe details can be found here: https://godbolt.org/z/37WsGxMcv", "author": "cardigan1008", "labels": [ "regression", "release:backport", "confirmed", "crash", "llvm:transforms" ], "comments": [ { "author": "shafik", "body": "Looks like a regression, does not crash in clang-18: https://godbolt.org/z/1zYqs3sbz" }, { "author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/bbdhPxx5E\r\n\r\n```\r\n; bin/opt -passes=indvars 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\n\r\ndefine i32 @m() {\r\nentry:\r\n %div.i4 = sdiv i32 1, 0\r\n br label %for.body.i6\r\n\r\nfor.body.i6: ; preds = %if.end.i, %entry\r\n %add57.i = phi i32 [ %add.i7, %if.end.i ], [ 0, %entry ]\r\n br i1 true, label %i.exit, label %if.end.i\r\n\r\nif.end.i: ; preds = %for.body.i6\r\n %add.i7 = add i32 %add57.i, %div.i4\r\n %conv.i = zext i32 %add57.i to i64\r\n store i64 %conv.i, ptr null, align 8\r\n br label %for.body.i6\r\n\r\ni.exit: ; preds = %for.body.i6\r\n ret i32 0\r\n}\r\n```\r\ncc @nikic" }, { "author": "DimitryAndric", "body": "This regressed with `llvmorg-19-init-02822-g`4db93e5d564 (\"[IndVars] Recompute flags if needed in widenIVUse of IV increment. (#82352)\") by @fhahn." } ] }
true
null
100464
https://github.com/llvm/llvm-project/issues/100464
crash
ba461f8c6278a7b2fd7695454c1f184c38897ecd
2024-07-24T20:37:49
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "b72689a5cbd8645c183476cd87e32948308c5b64", "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": [ [ 6678, 6683 ], [ 6693, 6700 ], [ 6727, 6742 ] ], "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 b72689a5cbd8645c183476cd87e32948308c5b64 Author: Florian Hahn <[email protected]> Date: Thu Jul 25 11:16:09 2024 +0100 [LV] Ignore live-out users in cost model if scalar epilogue is required. Follow-up to ba8126b6fef79. If a scalar epilogue is required, users outside the loop won't use live-outs from the vector loop but from the scalar epilogue. Ignore them if that is the case. This fixes another case where the VPlan-based cost-model more accurately computes cost. Fixes https://github.com/llvm/llvm-project/issues/100464. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b709ccc3c35a..224d98d5c4f9 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6678,6 +6678,15 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { SmallVector<Value *, 4> DeadInterleavePointerOps; SmallVector<Value *, 4> DeadOps; + + // If a scalar epilogue is required, users outside the loop won't use + // live-outs from the vector loop but from the scalar epilogue. Ignore them if + // that is the case. + bool RequiresScalarEpilogue = requiresScalarEpilogue(true); + auto IsLiveOutDead = [this, RequiresScalarEpilogue](User *U) { + return RequiresScalarEpilogue && + !TheLoop->contains(cast<Instruction>(U)->getParent()); + }; for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { // Find all stores to invariant variables. Since they are going to sink @@ -6693,8 +6702,9 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { // Add instructions that would be trivially dead and are only used by // values already ignored to DeadOps to seed worklist. if (wouldInstructionBeTriviallyDead(&I, TLI) && - all_of(I.users(), [this](User *U) { - return VecValuesToIgnore.contains(U) || ValuesToIgnore.contains(U); + all_of(I.users(), [this, IsLiveOutDead](User *U) { + return VecValuesToIgnore.contains(U) || + ValuesToIgnore.contains(U) || IsLiveOutDead(U); })) DeadOps.push_back(&I); @@ -6727,16 +6737,22 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { // Mark ops that would be trivially dead and are only used by ignored // instructions as free. + BasicBlock *Header = TheLoop->getHeader(); for (unsigned I = 0; I != DeadOps.size(); ++I) { auto *Op = dyn_cast<Instruction>(DeadOps[I]); // Skip any op that shouldn't be considered dead. if (!Op || !TheLoop->contains(Op) || + (isa<PHINode>(Op) && Op->getParent() == Header) || !wouldInstructionBeTriviallyDead(Op, TLI) || - any_of(Op->users(), [this](User *U) { - return !VecValuesToIgnore.contains(U) && !ValuesToIgnore.contains(U); + any_of(Op->users(), [this, IsLiveOutDead](User *U) { + return !VecValuesToIgnore.contains(U) && ValuesToIgnore.contains(U) && + !IsLiveOutDead(U); })) continue; + if (!TheLoop->contains(Op->getParent())) + continue; + // If all of Op's users are in ValuesToIgnore, add it to ValuesToIgnore // which applies for both scalar and vector versions. Otherwise it is only // dead in vector versions, so only add it to VecValuesToIgnore.
[ { "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_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 }, { "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 } ] }, { "file": "llvm/test/Transforms/LoopVectorize/RISCV/riscv-vector-reverse.ll", "commands": [ "opt -passes=loop-vectorize,dce,instcombine -mtriple riscv64-linux-gnu -mattr=+v -debug-only=loop-vectorize -scalable-vectorization=on -riscv-v-vector-bits-min=128 -disable-output < %s 2>&1" ], "tests": [ { "test_name": "vector_reverse_i64", "test_body": "define void @vector_reverse_i64(ptr nocapture noundef writeonly %A, ptr nocapture noundef readonly %B, i32 noundef signext %n) {\nentry:\n %cmp7 = icmp sgt i32 %n, 0\n br i1 %cmp7, label %for.body.preheader, label %for.cond.cleanup\n\nfor.body.preheader: ; preds = %entry\n %0 = zext i32 %n to i64\n br label %for.body\n\nfor.cond.cleanup: ; preds = %for.body, %entry\n ret void\n\nfor.body: ; preds = %for.body, %for.body.preheader\n %indvars.iv = phi i64 [ %0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %i.0.in8 = phi i32 [ %n, %for.body.preheader ], [ %i.0, %for.body ]\n %i.0 = add nsw i32 %i.0.in8, -1\n %idxprom = zext i32 %i.0 to i64\n %arrayidx = getelementptr inbounds i32, ptr %B, i64 %idxprom\n %1 = load i32, ptr %arrayidx, align 4\n %add9 = add i32 %1, 1\n %arrayidx3 = getelementptr inbounds i32, ptr %A, i64 %idxprom\n store i32 %add9, ptr %arrayidx3, align 4\n %cmp = icmp ugt i64 %indvars.iv, 1\n %indvars.iv.next = add nsw i64 %indvars.iv, -1\n br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0\n}\n\n!0 = distinct !{!0, !1, !2, !3, !4}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.width\", i32 4}\n!3 = !{!\"llvm.loop.vectorize.scalable.enable\", i1 true}\n!4 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "vector_reverse_f32", "test_body": "define void @vector_reverse_f32(ptr nocapture noundef writeonly %A, ptr nocapture noundef readonly %B, i32 noundef signext %n) {\nentry:\n %cmp7 = icmp sgt i32 %n, 0\n br i1 %cmp7, label %for.body.preheader, label %for.cond.cleanup\n\nfor.body.preheader: ; preds = %entry\n %0 = zext i32 %n to i64\n br label %for.body\n\nfor.cond.cleanup: ; preds = %for.body, %entry\n ret void\n\nfor.body: ; preds = %for.body, %for.body.preheader\n %indvars.iv = phi i64 [ %0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %i.0.in8 = phi i32 [ %n, %for.body.preheader ], [ %i.0, %for.body ]\n %i.0 = add nsw i32 %i.0.in8, -1\n %idxprom = zext i32 %i.0 to i64\n %arrayidx = getelementptr inbounds float, ptr %B, i64 %idxprom\n %1 = load float, ptr %arrayidx, align 4\n %conv1 = fadd float %1, 1.000000e+00\n %arrayidx3 = getelementptr inbounds float, ptr %A, i64 %idxprom\n store float %conv1, ptr %arrayidx3, align 4\n %cmp = icmp ugt i64 %indvars.iv, 1\n %indvars.iv.next = add nsw i64 %indvars.iv, -1\n br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0\n}\n\n!0 = distinct !{!0, !1, !2, !3, !4}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.width\", i32 4}\n!3 = !{!\"llvm.loop.vectorize.scalable.enable\", i1 true}\n!4 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] VPlan cost model and legacy cost model disagreed", "body": "Related: #99701, #92555. @fhahn Please let me know if you'd prefer these assert triggering testcases to be all in the same issue or prefer a new issue when a new testcase is found.\r\n\r\nTested using llvm f719a339a89b\r\n\r\nTestcase:\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(ptr %0) #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %.lcssa = phi i8 [ %1, %for.body ]\r\n ret i32 0\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %l.011 = phi i32 [ 0, %entry ], [ %add, %for.body ]\r\n %idxprom = sext i32 %l.011 to i64\r\n %arrayidx1 = getelementptr [15 x i8], ptr %0, i64 0, i64 %idxprom\r\n %1 = load i8, ptr %arrayidx1, align 1\r\n %arrayidx3 = getelementptr [0 x i8], ptr null, i64 0, i64 %idxprom\r\n store i8 0, ptr %arrayidx3, align 1\r\n %add = add i32 %l.011, 4\r\n %cmp = icmp ult i32 %l.011, -9\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup\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-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-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:10098: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"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 0x0000647de5790dd0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f1ddd0)\r\n #1 0x0000647de578e1ef llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f1b1ef)\r\n #2 0x0000647de578e345 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007b2a02842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007b2a028969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007b2a028969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007b2a028969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007b2a02842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007b2a028287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007b2a0282871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007b2a02839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000647de47acc98 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f39c98)\r\n#12 0x0000647de47af851 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+0x1f3c851)\r\n#13 0x0000647de47affd0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f3cfd0)\r\n#14 0x0000647de3621ff6 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+0xdaeff6)\r\n#15 0x0000647de55a8e7e 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+0x2d35e7e)\r\n#16 0x0000647de3625186 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+0xdb2186)\r\n#17 0x0000647de55a7c0b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d34c0b)\r\n#18 0x0000647de36214d6 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+0xdae4d6)\r\n#19 0x0000647de55a5d5d 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+0x2d32d5d)\r\n#20 0x0000647de2e6b5d6 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+0x5f85d6)\r\n#21 0x0000647de2e5d211 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5ea211)\r\n#22 0x00007b2a02829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x00007b2a02829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x00007b2a02829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x0000647de2e530a5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e00a5)\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\nGodbolt: https://godbolt.org/z/z7ee8hWWP", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "@patrick-rivos thanks for the report. I think it would be best to keep filing separate issues, as the underlying issues usually are different. Although the fuzzers may generate many instances of the same issue as was the case for https://github.com/llvm/llvm-project/issues/99701. Not sure if there's an easy way to catch that other than waiting for a day or so after filing the first issue." } ] }
true
null
109333
https://github.com/llvm/llvm-project/issues/109333
crash
c498af71d73e96e95730f3b3caaea08d3edbe62c
2024-09-19T20:50:34
[ "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "5bcc82d43388bb0daa122d5fe7ecda5eca27fc16", "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": [ [ 859, 865 ] ], "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": [ "cloneLoopBlocks" ], "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 5bcc82d43388bb0daa122d5fe7ecda5eca27fc16 Author: Nikita Popov <[email protected]> Date: Fri Sep 20 16:57:46 2024 +0200 [LoopPeel] Fix LCSSA phi node invalidation In the test case, the BECount of the second loop uses %load, but we only have an LCSSA phi node for %add, so that is what gets invalidated. Use the forgetLcssaPhiWithNewPredecessor() API instead, which will invalidate the roots of the expression instead. Fixes https://github.com/llvm/llvm-project/issues/109333. diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp index 5d7c0d947fac..760f1619e030 100644 --- a/llvm/lib/Transforms/Utils/LoopPeel.cpp +++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp @@ -859,7 +859,7 @@ static void cloneLoopBlocks( if (LatchInst && L->contains(LatchInst)) LatchVal = VMap[LatchVal]; PHI.addIncoming(LatchVal, cast<BasicBlock>(VMap[Edge.first])); - SE.forgetValue(&PHI); + SE.forgetLcssaPhiWithNewPredecessor(L, &PHI); } // LastValueMap is updated with the values for the current loop
[ { "file": "llvm/test/Transforms/LoopUnroll/pr109333.ll", "commands": [ "opt -S -passes=\"print<scalar-evolution>,loop-unroll\" -unroll-runtime < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "define void @test(i1 %c, ptr %p) {\nentry:\n br label %loop.1\n\nloop.1: ; preds = %loop.1, %entry\n %phi = phi ptr [ null, %entry ], [ %p, %loop.1 ]\n %load = load i64, ptr %p, align 8\n %add = add i64 %load, 1\n br i1 %c, label %if, label %loop.1\n\nif: ; preds = %loop.1\n %add.lcssa = phi i64 [ %add, %loop.1 ]\n %gep = getelementptr i64, ptr %p, i64 %add.lcssa\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %if\n %iv = phi ptr [ %p, %if ], [ %iv.next, %loop.2 ]\n %iv.next = getelementptr i8, ptr %iv, i64 8\n %icmp = icmp eq ptr %iv, %gep\n br i1 %icmp, label %exit, label %loop.2\n\nexit: ; preds = %loop.2\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "LTO error: Instruction does not dominate all uses", "body": "clang crashes while linking\r\n```\r\nclang: error: unable to execute command: Aborted (core dumped)\r\nclang: error: linker command failed due to signal (use -v to see invocation)\r\n```\r\nI followed the instructions [here](https://llvm.org/docs/HowToSubmitABug.html) and narrowed it down to an LTO bug. File to reproduce is attached. [a.out.0.2.internalize-reduced.bc.tar.gz](https://github.com/user-attachments/files/17066318/a.out.0.2.internalize-reduced.bc.tar.gz)\r\n```\r\n$ opt \"-passes=lto<O3>\" a.out.0.2.internalize-reduced.bc\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\nInstruction does not dominate all uses!\r\n %.lcssa16 = phi i64 [ %12, %9 ]\r\n %27 = add i64 %.lcssa16, 2\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: opt -passes=lto<O3> reduced-redacted.bc #0 0x00007e899efc4d90 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Unix/Signals.inc:723:22\r\n #1 0x00007e899efc1d4d llvm::sys::RunSignalHandlers() /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Signals.cpp:105:20\r\n #2 0x00007e899efc1d4d SignalHandler /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Unix/Signals.inc:403:31\r\n #3 0x00007e899e24c1d0 (/usr/lib/libc.so.6+0x3d1d0)\r\n #4 0x00007e899e2a53f4 __pthread_kill_implementation /usr/src/debug/glibc/glibc/nptl/pthread_kill.c:44:76\r\n #5 0x00007e899e24c120 raise /usr/src/debug/glibc/glibc/signal/../sysdeps/posix/raise.c:27:6\r\n #6 0x00007e899e2334c3 abort /usr/src/debug/glibc/glibc/stdlib/abort.c:81:7\r\n #7 0x00007e899ecaba1b std::mutex::lock() /usr/include/c++/14.1.1/bits/std_mutex.h:117:22\r\n #8 0x00007e899ecaba1b std::lock_guard<std::mutex>::lock_guard(std::mutex&) /usr/include/c++/14.1.1/bits/std_mutex.h:250:23\r\n #9 0x00007e899ecaba1b llvm::install_bad_alloc_error_handler(void (*)(void*, char const*, bool), void*) /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/ErrorHandling.cpp:131:61\r\n#10 0x00007e899eec070e (/usr/lib/libLLVM.so.18.1+0x6c070e)\r\n#11 0x00007e899f21aa1b (/usr/lib/libLLVM.so.18.1+0xa1aa1b)\r\n#12 0x000055a86e4acf57 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm:\r\n:Module>&) /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/IR/PassManagerInternal.h:90:3\r\n#13 0x00007e899f1d767e llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /usr/src/debug/llvm/llvm-18.1.8.src/incl\r\nude/llvm/IR/PassManager.h:547:20\r\n#14 0x000055a86e4b7052 llvm::SmallPtrSetImplBase::isSmall() const /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:195:33\r\n#15 0x000055a86e4b7052 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:83:17\r\n#16 0x000055a86e4b7052 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:345:7\r\n#17 0x000055a86e4b7052 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:451:7\r\n#18 0x000055a86e4b7052 llvm::PreservedAnalyses::~PreservedAnalyses() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/IR/PassManager.h:172:7\r\n#19 0x000055a86e4b7052 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutpu\r\ntFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /usr/src/debug/llvm/llvm-18.1.8\r\n.src/tools/opt/NewPMDriver.cpp:527:10\r\n#20 0x000055a86e4ab1ed std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/14.1.1/bits/basic_string.h:809:19\r\n#21 0x000055a86e4ab1ed main /usr/src/debug/llvm/llvm-18.1.8.src/tools/opt/opt.cpp:747:3\r\n#22 0x00007e899e234e08 __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:74:3\r\n#23 0x00007e899e234ecc call_init /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:128:20\r\n#24 0x00007e899e234ecc __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:347:5\r\n#25 0x000055a86e4abfd5 _start (/usr/bin/opt+0x1cfd5)\r\nAborted (core dumped)\r\n```\r\nThis happened after adding `-fsplit-lto-unit` to some parts of my code base.\r\n", "author": "googlebleh", "labels": [ "loopoptim", "release:backport", "llvm:crash" ], "comments": [ { "author": "googlebleh", "body": "While bisecting using this reduced test case, I was able to reproduce this crash on several versions of LLVM between 15 and 18.1.8. I was also able to reproduce on the tip of `main` (e439fdf4ea0dbc6f001428f4d4956700bf26bb97). However, this crash did not reproduce on 15.0.7. The commit on 15.0.7 that \"fixed\" the issue is\r\n```\r\ncommit f3c5289e78462fb96015f79c954d95a0d527ba55 \r\nAuthor: Martin Storsjö <[email protected]> \r\nDate: Wed Oct 5 14:44:21 2022 +0300 \r\n \r\n Revert \"Recommit \"[SCEV] Look through single value PHIs.\" (take 3)\" \r\n \r\n This reverts commit 20d798bd47ec5191de1b2a8a031da06a04e612e1. \r\n \r\n This commit caused crashes in some cases, see github issue #58152. \r\n This is fixed on main, but backporting it requires multiple \r\n nontrivial cherrypicks. \r\n \r\n Updating llvm/test/Transforms/LoopVectorize/create-induction-resume.ll \r\n with update_test_checks.py, so this isn't an exact automatic revert, \r\n as that test case was added after the reverted commit. \r\n \r\n This fixes #58152 for the release branch. \r\n \r\n llvm/lib/Analysis/ScalarEvolution.cpp | 7 ++-\r\n llvm/test/Analysis/DependenceAnalysis/lcssa.ll | 2 +- \r\n llvm/test/Analysis/ScalarEvolution/cycled_phis.ll | 4 +- \r\n .../ScalarEvolution/incorrect-exit-count.ll | 2 +- \r\n .../Analysis/ScalarEvolution/solve-quadratic-i1.ll | 4 +- \r\n .../ScalarEvolution/solve-quadratic-overflow.ll | 6 +-- \r\n llvm/test/Analysis/ScalarEvolution/trivial-phis.ll | 2 +- \r\n llvm/test/Transforms/LoopStrengthReduce/funclet.ll | 40 +++++++++-------\r\n .../LoopVectorize/create-induction-resume.ll | 24 ++++------\r\n llvm/test/Transforms/LoopVectorize/pr45259.ll | 55 +++++++++++-----------\r\n 10 files changed, 75 insertions(+), 71 deletions(-)\r\n```\r\nspecifically, this (almost) 1-line diff\r\n```diff\r\ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\r\nindex 4b2db80bc1ec..3b73f9511eca 100644\r\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\r\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\r\n@@ -6023,8 +6023,13 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {\r\n if (const SCEV *S = createAddRecFromPHI(PN))\r\n return S;\r\n \r\n+ // If the PHI has a single incoming value, follow that value, unless the\r\n+ // PHI's incoming blocks are in a different loop, in which case doing so\r\n+ // risks breaking LCSSA form. Instcombine would normally zap these, but\r\n+ // it doesn't have DominatorTree information, so it may miss cases.\r\n if (Value *V = simplifyInstruction(PN, {getDataLayout(), &TLI, &DT, &AC}))\r\n- return getSCEV(V);\r\n+ if (LI.replacementPreservesLCSSAForm(PN, V))\r\n+ return getSCEV(V);\r\n \r\n if (const SCEV *S = createNodeFromSelectLikePHI(PN))\r\n return S;\r\n```\r\n" }, { "author": "nikic", "body": "Reduced:\r\n```llvm\r\n; RUN: opt -passes=\"print<scalar-evolution>,loop-unroll\" -unroll-runtime\r\ndefine void @test(i1 %c, ptr %p) {\r\nentry:\r\n br label %loop\r\n\r\nloop:\r\n %phi = phi ptr [ null, %entry ], [ %p, %loop ]\r\n %load = load i64, ptr %p, align 8\r\n %add = add i64 %load, 1\r\n br i1 %c, label %bb2, label %loop\r\n\r\nbb2:\r\n %add.lcssa = phi i64 [ %add, %loop ]\r\n %gep = getelementptr i64, ptr %p, i64 %add.lcssa\r\n br label %loop2\r\n\r\nloop2:\r\n %iv = phi ptr [ %p, %bb2 ], [ %iv.next, %loop2 ]\r\n %iv.next = getelementptr i8, ptr %iv, i64 8\r\n %icmp = icmp eq ptr %iv, %gep\r\n br i1 %icmp, label %exit, label %loop2\r\n\r\nexit:\r\n ret void\r\n}\r\n```" }, { "author": "nikic", "body": "From a cursory look, the problem here is that the BECount of `loop2` depends on `%load`, and after peeling it should instead depend on a phi node, but instead still depends on `%load`. As the BECount does not dominate the loop, SCEV is invalid.\r\n\r\nThis issue sounds very familiar, we've fixed variants of this in the past." } ] }
true
null
79175
https://github.com/llvm/llvm-project/issues/79175
miscompilation
e538486e90539096e7851d0deba4ea9ed94fced2
2024-01-23T17:34:28
[ "llvm/test/Transforms/JumpThreading" ]
{ "fix_commit": "4f32f5d5720fbef06672714a62376f236a36aef5", "components": [ "JumpThreading", "AliasAnalysis" ], "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": 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": [ [ 287, 292 ], [ 668, 673 ] ], "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": [ [ 43, 62 ] ], "llvm/lib/Analysis/BasicAliasAnalysis.cpp": [ [ 89, 95 ], [ 1063, 1068 ], [ 1556, 1561 ], [ 1735, 1741 ] ], "llvm/lib/Transforms/Scalar/JumpThreading.cpp": [ [ 1261, 1266 ] ], "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": 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": [ "AAQueryInfo", "enableCrossIterationMode" ], "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": [ "BasicAAResult" ], "llvm/lib/Analysis/BasicAliasAnalysis.cpp": [ "BasicAAResult::aliasCheck", "BasicAAResult::aliasGEP", "BasicAAResult::invalidate", "BasicAAResult::isValueEqualInPotentialCycles", "BasicAAResult::subtractDecomposedGEPs" ], "llvm/lib/Transforms/Scalar/JumpThreading.cpp": [ "JumpThreadingPass::simplifyPartiallyRedundantLoad" ], "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit 4f32f5d5720fbef06672714a62376f236a36aef5 Author: Nikita Popov <[email protected]> Date: Wed Jan 31 15:23:53 2024 +0100 [AA][JumpThreading] Don't use DomTree for AA in JumpThreading (#79294) JumpThreading may perform AA queries while the dominator tree is not up to date, which may result in miscompilations. Fix this by adding a new AAQI option to disable the use of the dominator tree in BasicAA. Fixes https://github.com/llvm/llvm-project/issues/79175. diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h index d6f732d35fd4..e8e4f491be5a 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -287,6 +287,10 @@ public: /// store %l, ... bool MayBeCrossIteration = false; + /// Whether alias analysis is allowed to use the dominator tree, for use by + /// passes that lazily update the DT while performing AA queries. + bool UseDominatorTree = true; + AAQueryInfo(AAResults &AAR, CaptureInfo *CI) : AAR(AAR), CI(CI) {} }; @@ -668,6 +672,9 @@ public: void enableCrossIterationMode() { AAQI.MayBeCrossIteration = true; } + + /// Disable the use of the dominator tree during alias analysis queries. + void disableDominatorTree() { AAQI.UseDominatorTree = false; } }; /// Temporary typedef for legacy code that uses a generic \c AliasAnalysis diff --git a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h index afc1811239f2..7eca82729430 100644 --- a/llvm/include/llvm/Analysis/BasicAliasAnalysis.h +++ b/llvm/include/llvm/Analysis/BasicAliasAnalysis.h @@ -43,20 +43,26 @@ class BasicAAResult : public AAResultBase { const Function &F; const TargetLibraryInfo &TLI; AssumptionCache &AC; - DominatorTree *DT; + /// Use getDT() instead of accessing this member directly, in order to + /// respect the AAQI.UseDominatorTree option. + DominatorTree *DT_; + + DominatorTree *getDT(const AAQueryInfo &AAQI) const { + return AAQI.UseDominatorTree ? DT_ : nullptr; + } public: BasicAAResult(const DataLayout &DL, const Function &F, const TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree *DT = nullptr) - : DL(DL), F(F), TLI(TLI), AC(AC), DT(DT) {} + : DL(DL), F(F), TLI(TLI), AC(AC), DT_(DT) {} BasicAAResult(const BasicAAResult &Arg) : AAResultBase(Arg), DL(Arg.DL), F(Arg.F), TLI(Arg.TLI), AC(Arg.AC), - DT(Arg.DT) {} + DT_(Arg.DT_) {} BasicAAResult(BasicAAResult &&Arg) : AAResultBase(std::move(Arg)), DL(Arg.DL), F(Arg.F), TLI(Arg.TLI), - AC(Arg.AC), DT(Arg.DT) {} + AC(Arg.AC), DT_(Arg.DT_) {} /// Handle invalidation events in the new pass manager. bool invalidate(Function &Fn, const PreservedAnalyses &PA, diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 3178e2d27816..1028b52a7912 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -89,7 +89,7 @@ bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA, // may be created without handles to some analyses and in that case don't // depend on them. if (Inv.invalidate<AssumptionAnalysis>(Fn, PA) || - (DT && Inv.invalidate<DominatorTreeAnalysis>(Fn, PA))) + (DT_ && Inv.invalidate<DominatorTreeAnalysis>(Fn, PA))) return true; // Otherwise this analysis result remains valid. @@ -1063,6 +1063,7 @@ AliasResult BasicAAResult::aliasGEP( : AliasResult::MayAlias; } + DominatorTree *DT = getDT(AAQI); DecomposedGEP DecompGEP1 = DecomposeGEPExpression(GEP1, DL, &AC, DT); DecomposedGEP DecompGEP2 = DecomposeGEPExpression(V2, DL, &AC, DT); @@ -1556,6 +1557,7 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size, const Value *HintO1 = getUnderlyingObject(Hint1); const Value *HintO2 = getUnderlyingObject(Hint2); + DominatorTree *DT = getDT(AAQI); auto ValidAssumeForPtrContext = [&](const Value *Ptr) { if (const Instruction *PtrI = dyn_cast<Instruction>(Ptr)) { return isValidAssumeForContext(Assume, PtrI, DT, @@ -1735,7 +1737,7 @@ bool BasicAAResult::isValueEqualInPotentialCycles(const Value *V, if (!Inst || Inst->getParent()->isEntryBlock()) return true; - return isNotInCycle(Inst, DT, /*LI*/ nullptr); + return isNotInCycle(Inst, getDT(AAQI), /*LI*/ nullptr); } /// Computes the symbolic difference between two de-composed GEPs. diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index b7cf02489631..bb33a5da288c 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1261,6 +1261,8 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) { BasicBlock::iterator BBIt(LoadI); bool IsLoadCSE; BatchAAResults BatchAA(*AA); + // The dominator tree is updated lazily and may not be valid at this point. + BatchAA.disableDominatorTree(); if (Value *AvailableVal = FindAvailableLoadedValue( LoadI, LoadBB, BBIt, DefMaxInstsToScan, &BatchAA, &IsLoadCSE)) { // If the value of the load is locally available within the block, just use
[ { "file": "llvm/test/Transforms/JumpThreading/pr79175.ll", "commands": [ "opt -S -passes=jump-threading < %s" ], "tests": [ { "test_name": "test", "test_body": "@f = external global i32\n\ndefine i32 @test(i64 %idx, i32 %val) {\nentry:\n %cmp = icmp slt i64 %idx, 1\n br i1 %cmp, label %for.body, label %return\n\nfor.body: ; preds = %entry\n %f = load i32, ptr @f, align 4\n %cmp1 = icmp eq i32 %f, 0\n br i1 %cmp1, label %cond.end, label %cond.false\n\ncond.false: ; preds = %for.body\n br label %cond.end\n\ncond.end: ; preds = %cond.false, %for.body\n %phi = phi i32 [ %val, %cond.false ], [ 1, %for.body ]\n %cmp.i = icmp sgt i32 %phi, 0\n %sel = select i1 %cmp.i, i32 0, i32 %phi\n %f.idx = getelementptr inbounds i32, ptr @f, i64 %idx\n store i32 %sel, ptr %f.idx, align 4\n %f.reload = load i32, ptr @f, align 4\n %cmp3 = icmp slt i32 %f.reload, 1\n br i1 %cmp3, label %return2, label %return\n\nreturn: ; preds = %cond.end, %entry\n ret i32 0\n\nreturn2: ; preds = %cond.end\n ret i32 1\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "WRONG code, likely JumpThreadingPass", "body": "[wrong0.tar.gz](https://github.com/llvm/llvm-project/files/14027750/wrong0.tar.gz)\r\n(reduced c test case, should print 0)\r\n\r\nrunline:\r\nclang -O3 -march=arch13 wrong0.i -o a.out -w -mllvm -available-load-scan-limit=12\r\n\r\nThe function n() below is called two times in the reduced test case. The first time f[0] has a value of 0 at the start of the function, and a value of 1 at the end. The second time n() is called, f[0] has a value of 1 at the top, while it is then set to 0 by k().\r\n```\r\nlong k(long l, int m); // returns 0 \r\n\r\nconst int *n() {\r\n for (; C <= 0;) {\r\n A = (f[0] == 0 ? 1 : A % f[0]);\r\n f[C] = k(A, 0);\r\n g = &f[0];\r\n f[C] = 1 > *g;\r\n if (f[C])\r\n return &e;\r\n break;\r\n }\r\n return 0;\r\n}\r\n```\r\nThis is the transformation of jump threading:\r\n\r\n```\r\n > *** IR Dump After JumpThreadingPass on n ***\r\n > ; Function Attrs: nounwind\r\ndefine dso_local ptr @n() local_unnamed_addr #1 { define dso_local ptr @n() local_unnamed_addr #1 {\r\nentry: entry:\r\n %0 = load i64, ptr @C, align 8, !tbaa !4 %0 = load i64, ptr @C, align 8, !tbaa !4\r\n %cmp = icmp slt i64 %0, 1 %cmp = icmp slt i64 %0, 1\r\n br i1 %cmp, label %for.body, label %for.end br i1 %cmp, label %for.body, label %for.end\r\n\r\nfor.body: ; preds = %entry for.body: ; preds = %entry\r\n %1 = load i32, ptr @f, align 4, !tbaa !8 %1 = load i32, ptr @f, align 4, !tbaa !8\r\n %cmp1 = icmp eq i32 %1, 0 %cmp1 = icmp eq i32 %1, 0\r\n br i1 %cmp1, label %cond.end, label %cond.false | br i1 %cmp1, label %cond.end.thread, label %cond.end\r\n\r\ncond.false: ; preds = %for.body | cond.end.thread: ; preds = %for.body\r\n > store i64 1, ptr @A, align 8, !tbaa !4\r\n > br label %3\r\n >\r\n > cond.end: ; preds = %for.body\r\n %2 = load i64, ptr @A, align 8, !tbaa !4 %2 = load i64, ptr @A, align 8, !tbaa !4\r\n %conv = sext i32 %1 to i64 %conv = sext i32 %1 to i64\r\n %rem = srem i64 %2, %conv %rem = srem i64 %2, %conv\r\n br label %cond.end | store i64 %rem, ptr @A, align 8, !tbaa !4\r\n > %cmp.i = icmp sgt i64 %rem, 0\r\n > %cond.fr = freeze i1 %cmp.i\r\n > br i1 %cond.fr, label %3, label %4\r\n >\r\n > 3: ; preds = %cond.end.\r\n > %.pr = load i32, ptr @f, align 4, !tbaa !8\r\n > br label %4\r\n\r\ncond.end: ; preds = %for.body, | 4: ; preds = %cond.end,\r\n %cond = phi i64 [ %rem, %cond.false ], [ 1, %for.body ] | %5 = phi i32 [ %1, %cond.end ], [ %.pr, %3 ]\r\n store i64 %cond, ptr @A, align 8, !tbaa !4 | %6 = phi i64 [ 0, %3 ], [ %rem, %cond.end ]\r\n %cmp.i = icmp sgt i64 %cond, 0 | %conv2 = trunc i64 %6 to i32\r\n %cond.i = select i1 %cmp.i, i64 0, i64 %cond <\r\n %conv2 = trunc i64 %cond.i to i32 <\r\n %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0 %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0\r\n store i32 %conv2, ptr %arrayidx, align 4, !tbaa !8 store i32 %conv2, ptr %arrayidx, align 4, !tbaa !8\r\n store ptr @f, ptr @g, align 8, !tbaa !10 store ptr @f, ptr @g, align 8, !tbaa !10\r\n %3 = load i32, ptr @f, align 4, !tbaa !8 | %cmp3 = icmp slt i32 %5, 1\r\n %cmp3 = icmp slt i32 %3, 1 <\r\n %conv4 = zext i1 %cmp3 to i32 %conv4 = zext i1 %cmp3 to i32\r\n store i32 %conv4, ptr %arrayidx, align 4, !tbaa !8 store i32 %conv4, ptr %arrayidx, align 4, !tbaa !8\r\n br i1 %cmp3, label %return, label %for.end br i1 %cmp3, label %return, label %for.end\r\n\r\nfor.end: ; preds = %cond.end, | for.end: ; preds = %4, %entry\r\n br label %return br label %return\r\n\r\nreturn: ; preds = %cond.end, | return: ; preds = %4, %for.e\r\n %retval.0 = phi ptr [ null, %for.end ], [ @e, %cond.end ] | %retval.0 = phi ptr [ null, %for.end ], [ @e, %4 ]\r\n ret ptr %retval.0 ret ptr %retval.0\r\n} }\r\n~\r\n\r\n```\r\n\r\nBefore (left), `@f `is reloaded for the final icmp in cond.end (%3), which is necessary as the store to %conv2 just above goes to the same address. However, to the right JumpThreading has changed the final icmp to use the %5 value, which does not reflect the stored value of %conv2. This seems wrong and maybe JT has missed the fact that %arrayidx aliases `@f`?\r\n\r\n@jmorse @MatzeB @nikic \r\n", "author": "JonPsson1", "labels": [ "miscompilation", "llvm:analysis", "llvm:transforms" ], "comments": [ { "author": "jmorse", "body": "Here's a godbolt link seemingly showing the same thing: https://godbolt.org/z/dMPaP7161 . I can't replicate this at 6a7abea47 with just `opt --passes=jump-threading`, but can if it's part of clang and inspected with `print-after-all`." }, { "author": "jmorse", "body": "Ah -- because it's sensitive to the `-available-load-scan-limit=12`, which defaults to six and needs to be at least ten for this problem to appear. Stepping through bits of opt, the AA trace believes something that's wrong:\r\n\r\n```\r\nStart %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0 @ LocationSize::precise(4), @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::precise(4)\r\n Start @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer, @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer\r\n End @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer, @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::beforeOrAfterPointer = MustAlias\r\nEnd %arrayidx = getelementptr inbounds [1 x i32], ptr @f, i64 0, i64 %0 @ LocationSize::precise(4), @f = dso_local global [1 x i32] zeroinitializer, align 4 @ LocationSize::precise(4) = NoAlias\r\n```\r\n\r\nWhich I think is saying that the GEP is believed to not-alias the \"f\" variable, wheras it might alias depending on the value of %0. Stepping through other things during the alias query, I see `isKnownNonNullFromDominatingCondition` returning true for %0, i.e. the load from \"C\". I would imagine this means there's something wrong with the dominator tree that makes this code think it's only executing on a path where %0 is always-zero. (EDIT: actually it means always-non-zero).\r\n\r\n(However this isn't my normal wheelhouse, so that might not be true!)." }, { "author": "nikic", "body": "That sounds about right to me. JumpThreading performs lazy DT updates, so it's not legal to use DT during the transform.\r\n\r\nBasicAA in principle already supports working without DT, but it may be a bit tricky to avoid the DT use just in JumpThreading, given how this is all wired up in the pass manager." }, { "author": "nikic", "body": "Somewhat reduced test case:\r\n```llvm\r\n; RUN: opt -S -passes=jump-threading < %s\r\n@f = external global i32\r\n\r\ndefine void @test(i64 %idx, i32 %val) {\r\nentry:\r\n %cmp = icmp slt i64 %idx, 1\r\n br i1 %cmp, label %for.body, label %return\r\n\r\nfor.body:\r\n %f = load i32, ptr @f, align 4\r\n %cmp1 = icmp eq i32 %f, 0\r\n br i1 %cmp1, label %cond.end, label %cond.false\r\n\r\ncond.false:\r\n br label %cond.end\r\n\r\ncond.end:\r\n %phi = phi i32 [ %val, %cond.false ], [ 1, %for.body ]\r\n %cmp.i = icmp sgt i32 %phi, 0\r\n %sel = select i1 %cmp.i, i32 0, i32 %phi\r\n %f.idx = getelementptr inbounds i32, ptr @f, i64 %idx\r\n store i32 %sel, ptr %f.idx, align 4\r\n %f.reload = load i32, ptr @f, align 4\r\n %cmp3 = icmp slt i32 %f.reload, 1\r\n br i1 %cmp3, label %return, label %return\r\n\r\nreturn:\r\n ret void\r\n}\r\n```" }, { "author": "EugeneZelenko", "body": "Not merged yet." }, { "author": "tstellar", "body": "PR has been created, we will track the status there." } ] }
true
null
112078
https://github.com/llvm/llvm-project/issues/112078
miscompilation
39aae575744de7ae77e755142e0746a5b473b3ed
2024-10-12T04:08:35
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "9edc454ee601e04500529c98b753d3bd8f427d01", "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": [ [ 935, 943 ], [ 945, 955 ], [ 3362, 3370 ] ], "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", "foldIsPowerOf2OrZero" ], "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 9edc454ee601e04500529c98b753d3bd8f427d01 Author: Yingwei Zheng <[email protected]> Date: Mon Oct 14 20:52:55 2024 +0800 [InstCombine] Drop range attributes in `foldIsPowerOf2OrZero` (#112178) Closes https://github.com/llvm/llvm-project/issues/112078. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 453071f3f982..64bee4ab974e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -935,9 +935,11 @@ static Value *foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1, /// Fold (icmp eq ctpop(X) 1) | (icmp eq X 0) into (icmp ult ctpop(X) 2) and /// fold (icmp ne ctpop(X) 1) & (icmp ne X 0) into (icmp ugt ctpop(X) 1). -/// Also used for logical and/or, must be poison safe. +/// Also used for logical and/or, must be poison safe if range attributes are +/// dropped. static Value *foldIsPowerOf2OrZero(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd, - InstCombiner::BuilderTy &Builder) { + InstCombiner::BuilderTy &Builder, + InstCombinerImpl &IC) { CmpInst::Predicate Pred0, Pred1; Value *X; if (!match(Cmp0, m_ICmp(Pred0, m_Intrinsic<Intrinsic::ctpop>(m_Value(X)), @@ -945,11 +947,19 @@ static Value *foldIsPowerOf2OrZero(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd, !match(Cmp1, m_ICmp(Pred1, m_Specific(X), m_ZeroInt()))) return nullptr; - Value *CtPop = Cmp0->getOperand(0); - if (IsAnd && Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_NE) + auto *CtPop = cast<Instruction>(Cmp0->getOperand(0)); + if (IsAnd && Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_NE) { + // Drop range attributes and re-infer them in the next iteration. + CtPop->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(CtPop); return Builder.CreateICmpUGT(CtPop, ConstantInt::get(CtPop->getType(), 1)); - if (!IsAnd && Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_EQ) + } + if (!IsAnd && Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_EQ) { + // Drop range attributes and re-infer them in the next iteration. + CtPop->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(CtPop); return Builder.CreateICmpULT(CtPop, ConstantInt::get(CtPop->getType(), 2)); + } return nullptr; } @@ -3362,9 +3372,9 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, /*IsLogical*/ false, Builder, Q)) return V; - if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder)) + if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder, *this)) return V; - if (Value *V = foldIsPowerOf2OrZero(RHS, LHS, IsAnd, Builder)) + if (Value *V = foldIsPowerOf2OrZero(RHS, LHS, IsAnd, Builder, *this)) return V; // TODO: One of these directions is fine with logical and/or, the other could
[ { "file": "llvm/test/Transforms/InstCombine/ispow2.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "is_pow2or0_decrement_op", "test_body": "define i1 @is_pow2or0_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp eq i8 %and, 0\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_negate_op_vec", "test_body": "define <2 x i1> @is_pow2_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp eq <2 x i32> %and, %x\n %notzero = icmp ne <2 x i32> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 3\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_negate_op", "test_body": "define i1 @is_pow2_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_pow2_nz_known_bits", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @not_pow2_nz_known_bits(i32 %xin) {\n %x = or i32 %xin, 1\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp ne i32 %cnt, 1\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_nz_known_bits", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_nz_known_bits(i32 %xin) {\n %x = or i32 %xin, 64\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp eq i32 %cnt, 1\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_power2_or_zero_with_range", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_power2_or_zero_with_range(i32 %x) {\n %ctpop = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %ctpop, 1\n %notzero = icmp eq i32 %x, 0\n %res = select i1 %notzero, i1 true, i1 %cmp\n ret i1 %res\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z", "test_body": "define i1 @blsmsk_is_p2_or_z(i32 %xx, i32 %yy) {\n %x = or i32 %xx, %yy\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp uge i32 %x, %y\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2nor0_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ne <2 x i8> %t0, splat (i8 1)\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %notzero, %cmp\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_wrong_pred1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_pred1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_non_zero_ne_1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_ne_1(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z_fail", "test_body": "define i1 @blsmsk_is_p2_or_z_fail(i32 %xx, i32 %yy) {\n %x = or i32 %xx, %yy\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp ugt i32 %x, %y\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z_uge_xy_fail", "test_body": "define i1 @blsmsk_is_p2_or_z_uge_xy_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp uge i8 %x, %y\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_logical_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2or0_ctpop_logical_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp eq i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ugt <2 x i8> %t0, splat (i8 1)\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_fail_wrong_add", "test_body": "define i1 @blsmsk_isnt_p2_or_z_fail_wrong_add(i32 %x, i32 %z) {\n %xm1 = add i32 %z, -1\n %y = xor i32 %x, %xm1\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %cmp2 = icmp sgt i32 %x, 0\n %r = and i1 %cmp2, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_swap_cmp", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_swap_cmp(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %cmp, %iszero\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_commute_vec_wrong_pred3", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2or0_ctpop_commute_vec_wrong_pred3(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp eq <2 x i8> %t0, splat (i8 1)\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_decrement_op_logical", "test_body": "define i1 @is_pow2_decrement_op_logical(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp eq i8 %and, 0\n %notzero = icmp ne i8 %x, 0\n %r = select i1 %cmp, i1 %notzero, i1 false\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2or0_negate_op_vec", "test_body": "define <2 x i1> @isnot_pow2or0_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp ne <2 x i32> %and, %x\n ret <2 x i1> %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2or0_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp eq <2 x i8> %t0, splat (i8 1)\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %iszero, %cmp\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_negate_op_logical", "test_body": "define i1 @is_pow2_negate_op_logical(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_ult_xy_fail", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ult_xy_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ult i8 %x, %y\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_wrong_pred3_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2nor0_wrong_pred3_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ne <2 x i8> %t0, splat (i8 1)\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_negate_op_vec", "test_body": "define <2 x i1> @is_pow2or0_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp eq <2 x i32> %and, %x\n ret <2 x i1> %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2or0_negate_op", "test_body": "define i1 @isnot_pow2or0_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %and, %x\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_pow2_or_z_known_bits_fail_wrong_cmp", "test_body": "define <2 x i1> @not_pow2_or_z_known_bits_fail_wrong_cmp(<2 x i32> %xin) {\n %x = or <2 x i32> %xin, splat (i32 64)\n %cnt = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x)\n %r = icmp ugt <2 x i32> %cnt, splat (i32 2)\n ret <2 x i1> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_cmp_op2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 1\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_decrement_op_logical", "test_body": "define i1 @isnot_pow2_decrement_op_logical(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp ne i8 %and, 0\n %iszero = icmp eq i8 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_negate_op_logical", "test_body": "define i1 @isnot_pow2_negate_op_logical(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %and, %x\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %cmp, i1 true, i1 %iszero\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z_uge_yx", "test_body": "define i1 @blsmsk_is_p2_or_z_uge_yx(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp uge i8 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "has_single_bit_inv", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @has_single_bit_inv(i32 %x) {\nentry:\n %cmp1 = icmp eq i32 %x, 0\n %popcnt = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp2 = icmp ugt i32 %popcnt, 1\n %sel = select i1 %cmp1, i1 true, i1 %cmp2\n ret i1 %sel\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_negate_op", "test_body": "define i1 @is_pow2or0_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_ugt_yx_fail", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ugt_yx_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ugt i8 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_fail", "test_body": "define i1 @blsmsk_isnt_p2_or_z_fail(i32 %x) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp ule i32 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_decrement_op_vec", "test_body": "define <2 x i1> @is_pow2_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp eq <2 x i8> %and, zeroinitializer\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %notzero, %cmp\n ret <2 x i1> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2nor0_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp ne i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_wrong_pred1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_pred1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_fail_multiuse", "test_body": "declare void @use.i32(i32)\n\ndefine i1 @blsmsk_isnt_p2_or_z_fail_multiuse(i32 %x) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n call void @use.i32(i32 %y)\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %iszero = icmp ne i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_extra_uses", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_ult_yx", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ult_yx(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ult i8 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 3\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_fail_bad_xor", "test_body": "define i1 @blsmsk_isnt_p2_or_z_fail_bad_xor(i32 %x, i32 %z) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %z, %xm1\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_negate_op_extra_use2", "test_body": "declare void @use(i32)\n\ndefine i1 @is_pow2or0_negate_op_extra_use2(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n call void @use(i32 %and)\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_negate_op", "test_body": "define i1 @isnot_pow2_negate_op(i32 %x) {\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %and, %x\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %cmp, %iszero\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_negate_op_extra_use1", "test_body": "declare void @use(i32)\n\ndefine i1 @is_pow2or0_negate_op_extra_use1(i32 %x) {\n %neg = sub i32 0, %x\n call void @use(i32 %neg)\n %and = and i32 %neg, %x\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_wrong_cmp_op2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 1\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 3\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_commute_vec_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2or0_ctpop_commute_vec_wrong_cmp_op1(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp eq <2 x i8> %t0, <i8 -1, i8 1>\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %cmp2 = icmp slt i32 %x, 0\n %r = select i1 %cmp2, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_extra_uses_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2_ctpop_extra_uses_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2or0_negate_op_commute3", "test_body": "define i1 @isnot_pow2or0_negate_op_commute3(i32 %p) {\n %x = urem i32 42, %p\n %neg = sub i32 0, %x\n %and = and i32 %x, %neg\n %cmp = icmp ne i32 %x, %and\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_cmp_op2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_cmp_op2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 1\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_non_zero_eq_1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_eq_1(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_logical_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2nor0_ctpop_logical_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp ne i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %notzero = icmp ne i32 %x, 0\n call void @use_i1(i1 %notzero)\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %iszero = icmp ne i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_wrong_cmp_op2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 1\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_pred1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_extra_uses_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2_ctpop_extra_uses_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_extra_uses", "test_body": "declare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @is_pow2or0_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n call void @use(i32 %t0)\n %cmp = icmp eq i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_non_zero_ult_2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_ult_2(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_commute_vec", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @is_pow2_ctpop_commute_vec(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ult <2 x i8> %t0, splat (i8 2)\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_decrement_op", "test_body": "define i1 @isnot_pow2_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp ne i8 %and, 0\n %iszero = icmp eq i8 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_wrong_cmp_op1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_cmp_op1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 5\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_pred1_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred1_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2or0_decrement_op_vec", "test_body": "define <2 x i1> @isnot_pow2or0_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp ne <2 x i8> %and, zeroinitializer\n ret <2 x i1> %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %cmp2 = icmp sgt i32 %x, 0\n %r = select i1 %cmp2, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z_ugt_xy", "test_body": "define i1 @blsmsk_isnt_p2_or_z_ugt_xy(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ugt i8 %x, %y\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_commute_vec_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i8> @llvm.ctpop.v2i8(<2 x i8>) #0\n\ndefine <2 x i1> @isnot_pow2nor0_ctpop_commute_vec_wrong_cmp_op1(<2 x i8> %x) {\n %t0 = tail call <2 x i8> @llvm.ctpop.v2i8(<2 x i8> %x)\n %cmp = icmp ne <2 x i8> %t0, <i8 0, i8 -1>\n %notzero = icmp ne <2 x i8> %x, zeroinitializer\n %r = and <2 x i1> %cmp, %notzero\n ret <2 x i1> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_wrong_pred2_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_pred2_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %notzero = icmp eq i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_negate_op_commute1", "test_body": "define i1 @is_pow2or0_negate_op_commute1(i32 %p) {\n %x = srem i32 42, %p\n %neg = sub i32 0, %x\n %and = and i32 %x, %neg\n %cmp = icmp eq i32 %and, %x\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_or_z_known_bits", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_or_z_known_bits(i32 %xin) {\n %x = or i32 %xin, -2147483648\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp ult i32 %cnt, 2\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_decrement_op_vec", "test_body": "define <2 x i1> @is_pow2or0_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp eq <2 x i8> %and, zeroinitializer\n ret <2 x i1> %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_decrement_op", "test_body": "define i1 @is_pow2_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp eq i8 %and, 0\n %notzero = icmp ne i8 %x, 0\n %r = and i1 %cmp, %notzero\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %cmp2 = icmp slt i32 %x, 0\n %r = or i1 %cmp2, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2or0_negate_op_commute2", "test_body": "define i1 @isnot_pow2or0_negate_op_commute2(i32 %p) {\n %x = urem i32 42, %p\n %neg = sub i32 0, %x\n %and = and i32 %neg, %x\n %cmp = icmp ne i32 %x, %and\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z_fail_bad_cmp", "test_body": "define i1 @blsmsk_is_p2_or_z_fail_bad_cmp(i32 %x, i32 %z) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp uge i32 %y, %z\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_decrement_op_vec", "test_body": "define <2 x i1> @isnot_pow2_decrement_op_vec(<2 x i8> %x) {\n %dec = add <2 x i8> %x, splat (i8 -1)\n %and = and <2 x i8> %dec, %x\n %cmp = icmp ne <2 x i8> %and, zeroinitializer\n %iszero = icmp eq <2 x i8> %x, zeroinitializer\n %r = or <2 x i1> %cmp, %iszero\n ret <2 x i1> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 2\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z_ule_yx_fail", "test_body": "define i1 @blsmsk_is_p2_or_z_ule_yx_fail(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ule i8 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_pow2_or_z_known_bits", "test_body": "define <2 x i1> @not_pow2_or_z_known_bits(<2 x i32> %xin) {\n %x = or <2 x i32> %xin, splat (i32 64)\n %cnt = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x)\n %r = icmp ugt <2 x i32> %cnt, splat (i32 1)\n ret <2 x i1> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_negate_op_vec", "test_body": "define <2 x i1> @isnot_pow2_negate_op_vec(<2 x i32> %x) {\n %neg = sub <2 x i32> zeroinitializer, %x\n %and = and <2 x i32> %neg, %x\n %cmp = icmp ne <2 x i32> %and, %x\n %iszero = icmp eq <2 x i32> %x, zeroinitializer\n %r = or <2 x i1> %iszero, %cmp\n ret <2 x i1> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2or0_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2or0_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %iszero = icmp eq i32 %x, 0\n %r = select i1 %iszero, i1 true, i1 %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_extra_uses", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use_i1(i1)\n\ndefine i1 @isnot_pow2_ctpop_extra_uses(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n call void @use_i1(i1 %cmp)\n %iszero = icmp eq i32 %x, 0\n call void @use_i1(i1 %iszero)\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_power2_or_zero_inv_with_range", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_power2_or_zero_inv_with_range(i32 %x) {\n %ctpop = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %ctpop, 1\n %notzero = icmp ne i32 %x, 0\n %res = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %res\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_wrong_pred2", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_pred2(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp eq i32 %t0, 1\n %notzero = icmp eq i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "has_single_bit", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @has_single_bit(i32 %x) {\nentry:\n %cmp1 = icmp ne i32 %x, 0\n %popcnt = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\n %cmp2 = icmp ult i32 %popcnt, 2\n %sel = select i1 %cmp1, i1 %cmp2, i1 false\n ret i1 %sel\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_fail_pr63327", "test_body": "define i1 @is_pow2_fail_pr63327(i32 %x) {\n %nx = sub i32 0, %x\n %x_and_nx = and i32 %x, %nx\n %r = icmp sge i32 %x_and_nx, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_ctpop", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @is_pow2_ctpop(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ult i32 %t0, 2\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_nz_known_bits_fail_multiuse", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndeclare void @use.i32(i32)\n\ndefine i1 @is_pow2_nz_known_bits_fail_multiuse(i32 %xin) {\n %x = or i32 %xin, 64\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n call void @use.i32(i32 %cnt)\n %r = icmp eq i32 %cnt, 1\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_isnt_p2_or_z", "test_body": "define i1 @blsmsk_isnt_p2_or_z(i32 %x) {\n %xm1 = add i32 %x, -1\n %y = xor i32 %x, %xm1\n %r = icmp ult i32 %y, %x\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2or0_decrement_op", "test_body": "define i1 @isnot_pow2or0_decrement_op(i8 %x) {\n %dec = add i8 %x, -1\n %and = and i8 %dec, %x\n %cmp = icmp ne i8 %and, 0\n ret i1 %cmp\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_pow2_nz_known_bits_fail_not_p2_test", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @not_pow2_nz_known_bits_fail_not_p2_test(i32 %xin) {\n %x = or i32 %xin, 1\n %cnt = call i32 @llvm.ctpop.i32(i32 %x)\n %r = icmp ne i32 %cnt, 2\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 2\n %iszero = icmp eq i32 %x, 0\n %r = or i1 %iszero, %cmp\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blsmsk_is_p2_or_z_ule_xy", "test_body": "define i1 @blsmsk_is_p2_or_z_ule_xy(i8 %xx, i8 %yy) {\n %x = or i8 %xx, %yy\n %xm1 = add i8 %x, -1\n %y = xor i8 %x, %xm1\n %r = icmp ule i8 %x, %y\n ret i1 %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "is_pow2_non_zero_ugt_1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\ndefine i1 @is_pow2_non_zero_ugt_1(i32 %x) {\n %notzero = icmp ne i32 %x, 0\n call void @llvm.assume(i1 %notzero)\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ugt i32 %t0, 1\n ret i1 %cmp\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_swap_cmp", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_swap_cmp(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %cmp, %notzero\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_logical", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_logical(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 1\n %notzero = icmp ne i32 %x, 0\n %r = select i1 %notzero, i1 %cmp, i1 false\n ret i1 %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnot_pow2nor0_ctpop_wrong_cmp_op1", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #0\n\ndefine i1 @isnot_pow2nor0_ctpop_wrong_cmp_op1(i32 %x) {\n %t0 = tail call i32 @llvm.ctpop.i32(i32 %x)\n %cmp = icmp ne i32 %t0, 4\n %notzero = icmp ne i32 %x, 0\n %r = and i1 %notzero, %cmp\n ret i1 %r\n}\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 `foldIsPowerOf2OrZero`", "body": "Reproducer: https://alive2.llvm.org/ce/z/u62KKP (Please use latest alive2 with https://github.com/AliveToolkit/alive2/pull/1097)\r\n```\r\ndefine i1 @src(i32 %x) {\r\n %t0 = tail call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\r\n %cmp = icmp ne i32 %t0, 1\r\n %notzero = icmp ne i32 %x, 0\r\n %r = select i1 %notzero, i1 %cmp, i1 false\r\n ret i1 %r\r\n}\r\n\r\ndefine i1 @tgt(i32 %x) {\r\n %t0 = tail call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %x)\r\n %r = icmp ugt i32 %t0, 1\r\n ret i1 %r\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i1 @src(i32 %x) {\r\n#0:\r\n %t0 = ctpop i32 %x\r\n %#range_0_%t0 = !range i32 %t0, i32 1, i32 33\r\n %cmp = icmp ne i32 %#range_0_%t0, 1\r\n %notzero = icmp ne i32 %x, 0\r\n %r = select i1 %notzero, i1 %cmp, i1 0\r\n ret i1 %r\r\n}\r\n=>\r\ndefine i1 @tgt(i32 %x) {\r\n#0:\r\n %t0 = ctpop i32 %x\r\n %#range_0_%t0 = !range i32 %t0, i32 1, i32 33\r\n %r = icmp ugt i32 %#range_0_%t0, 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\ni32 %x = #x00000000 (0)\r\n\r\nSource:\r\ni32 %t0 = #x00000000 (0)\r\ni32 %#range_0_%t0 = poison\r\ni1 %cmp = poison\r\ni1 %notzero = #x0 (0)\r\ni1 %r = #x0 (0)\r\n\r\nTarget:\r\ni32 %t0 = #x00000000 (0)\r\ni32 %#range_0_%t0 = poison\r\ni1 %r = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
134115
https://github.com/llvm/llvm-project/issues/134115
crash
6388a7acf7e31fdc7b9c168bd6ce0f4d25c98cd0
2025-04-02T17:01:09
[ "llvm/test/Transforms/FunctionAttrs" ]
{ "fix_commit": "0547e84181ff10b24d6363bbfc97f168fe245397", "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": [ [ 661, 668 ] ], "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 0547e84181ff10b24d6363bbfc97f168fe245397 Author: Arthur Eubanks <[email protected]> Date: Wed Apr 23 15:56:24 2025 -0700 [FunctionAttrs] Bail if initializes range overflows 64-bit signed int (#137053) Otherwise the range doesn't make sense since we interpret it as signed. Fixes #134115 diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index bbfed2ac2c09..74e8a849803d 100644 --- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp +++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp @@ -661,8 +661,13 @@ ArgumentAccessInfo getArgumentAccessInfo(const Instruction *I, auto TypeSize = DL.getTypeStoreSize(Ty); if (!TypeSize.isScalable() && Offset) { int64_t Size = TypeSize.getFixedValue(); - return ConstantRange(APInt(64, *Offset, true), - APInt(64, *Offset + Size, true)); + APInt Low(64, *Offset, true); + bool Overflow; + APInt High = Low.sadd_ov(APInt(64, Size, true), Overflow); + // Bail if the range overflows signed 64-bit int. + if (Overflow) + return std::nullopt; + return ConstantRange(Low, High); } return std::nullopt; };
[ { "file": "llvm/test/Transforms/FunctionAttrs/initializes.ll", "commands": [ "opt -passes=function-attrs -S < %s" ], "tests": [ { "test_name": "memset_offset_1_size_0", "test_body": "define void @memset_offset_1_size_0(ptr %dst, ptr %src) {\n %dst.1 = getelementptr inbounds i8, ptr %dst, i64 1\n call void @llvm.memmove.p0.p0.i64(ptr %dst.1, ptr %src, i64 0, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memmove.p0.p0.i64(ptr writeonly captures(none), ptr readonly captures(none), i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "additional_args": null, "lli_expected_out": null }, { "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 } ] } ]
{ "title": "FunctionAttrs: Assertion `isOrder edRanges(RangesRef)' failed.", "body": "```\n$ cat /tmp/f.ll\ndefine i32 @f(ptr %arg, ptr %arg2) {\n store ptr %arg, ptr %arg2\n %getelementptr = getelementptr float, ptr %arg, i64 2305843009213693951\n %load = load i32, ptr %getelementptr, align 4\n ret i32 %load\n}\n$ opt -p function-attrs /tmp/f.ll -disable-output\nopt: ../../llvm/include/llvm/IR/ConstantRangeList.h:36: llvm::ConstantRangeList::ConstantRangeList(ArrayRef<ConstantRange>): Assertion `isOrder\nedRanges(RangesRef)' failed.\n```", "author": "aeubanks", "labels": [ "ipo", "crash" ], "comments": [] }
true
null
114082
https://github.com/llvm/llvm-project/issues/114082
crash
0f040433d325aa68ec6840aa179f3f314c26153a
2024-10-29T16:26:31
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "77bec78878762e34150fe23734fa43df796c873c", "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": [ [ 13398, 13404 ] ], "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::getLastInstructionInBundle" ], "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 77bec78878762e34150fe23734fa43df796c873c Author: Alexey Bataev <[email protected]> Date: Fri Nov 8 04:16:01 2024 -0800 [SLP]Do not look for last instruction in schedule block for buildvectors If looking for the insertion point for the node and the node is a buildvector node, the compiler should not use scheduling info for such nodes, they may contain only partial info, which is not fully correct and may cause compiler crash. Fixes #114082 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index b2f677fb84f9..c5b3537bc57b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13398,7 +13398,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { // scheduled, and the last instruction is VL.back(). So we start with // VL.back() and iterate over schedule data until we reach the end of the // bundle. The end of the bundle is marked by null ScheduleData. - if (BlocksSchedules.count(BB)) { + if (BlocksSchedules.count(BB) && !E->isGather()) { Value *V = E->isOneOf(E->Scalars.back()); if (doesNotNeedToBeScheduled(V)) V = *find_if_not(E->Scalars, doesNotNeedToBeScheduled);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n %icmp = icmp samesign ult i32 0, 0\n %select = select i1 %icmp, i32 0, i32 0\n %zext = zext i32 %select to i64\n %getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext\n store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8\n %icmp1 = icmp eq i32 0, 0\n %icmp2 = icmp eq i32 0, 0\n %icmp3 = icmp samesign ult i32 0, 0\n %icmp4 = icmp eq i32 0, 0\n %add = add i32 1, 0\n %icmp5 = icmp samesign ult i32 %add, 0\n store volatile i32 0, ptr addrspace(1) null, align 4\n %call = call i32 null(<2 x double> zeroinitializer)\n %icmp6 = icmp eq i32 %call, 0\n %icmp7 = icmp samesign ult i32 0, 0\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with the test below with -passes=slp-vectorizer -slp-threshold=-99999\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 %icmp = icmp samesign ult i32 0, 0\r\n %select = select i1 %icmp, i32 0, i32 0\r\n %zext = zext i32 %select to i64\r\n %getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext\r\n store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8\r\n %icmp1 = icmp eq i32 0, 0\r\n %icmp2 = icmp eq i32 0, 0\r\n %icmp3 = icmp samesign ult i32 0, 0\r\n %icmp4 = icmp eq i32 0, 0\r\n %add = add i32 1, 0\r\n %icmp5 = icmp samesign ult i32 %add, 0\r\n store volatile i32 0, ptr addrspace(1) null, align 4\r\n %call = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> zeroinitializer)\r\n %icmp6 = icmp eq i32 %call, 0\r\n %icmp7 = icmp samesign ult i32 0, 0\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\r\ndeclare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) #1\r\n\r\nattributes #0 = { \"target-features\"=\"+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,-avx10.2-256,-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,-avx10.2-512,-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\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) \"target-features\"=\"+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,-avx10.2-256,-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,-avx10.2-512,-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\nReproducer: https://godbolt.org/z/nTE84xq7n\r\n\r\nStack dump\r\n```\r\nInstruction does not dominate all uses!\r\n %5 = icmp eq <4 x i32> %4, zeroinitializer\r\n %2 = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> poison, <4 x i1> %5, i64 0)\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.\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 \"verify\" on module \"<source>\"\r\n #0 0x00000000050e7a98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50e7a98)\r\n #1 0x00000000050e548c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000078c8a0042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000078c8a00969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000078c8a0042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000078c8a00287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007d7d7b llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x00000000050265b8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50265b8)\r\n #8 0x0000000004f24790 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f24790)\r\n #9 0x00000000009015ce llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9015ce)\r\n#10 0x0000000004ee5440 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ee5440)\r\n#11 0x000000000090c1ea 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+0x90c1ea)\r\n#12 0x00000000008ff258 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff258)\r\n#13 0x000078c8a0029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x000078c8a0029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008f6d2e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d2e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
106626
https://github.com/llvm/llvm-project/issues/106626
crash
e51fc36c385d756ccbc2be8c47c52af207c3aead
2024-08-29T20:51:42
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "cc943a67d114e28c28f561c3b1a48ff2003264ce", "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": [ [ 3237, 3251 ] ], "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": [ "findLaneForValue" ], "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 cc943a67d114e28c28f561c3b1a48ff2003264ce Author: Alexey Bataev <[email protected]> Date: Thu Aug 29 15:05:09 2024 -0700 [SLP]Fix PR106626: trye several attempts for lookup values, if not found. If the value is used in Scalar several times, the first attempt to find its position in the node (if ReuseShuffleIndices and ReorderIndices not empty) may fail. In this case need to find another copy of the same value and try again. Fixes https://github.com/llvm/llvm-project/issues/106626 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 775fa9ba75cf..edb2567fa057 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3237,15 +3237,25 @@ private: /// When ReuseReorderShuffleIndices is empty it just returns position of \p /// V within vector of Scalars. Otherwise, try to remap on its reuse index. int findLaneForValue(Value *V) const { - unsigned FoundLane = std::distance(Scalars.begin(), find(Scalars, V)); - assert(FoundLane < Scalars.size() && "Couldn't find extract lane"); - if (!ReorderIndices.empty()) - FoundLane = ReorderIndices[FoundLane]; - assert(FoundLane < Scalars.size() && "Couldn't find extract lane"); - if (!ReuseShuffleIndices.empty()) { - FoundLane = std::distance(ReuseShuffleIndices.begin(), - find(ReuseShuffleIndices, FoundLane)); + unsigned FoundLane = getVectorFactor(); + for (auto *It = find(Scalars, V), *End = Scalars.end(); It != End; + std::advance(It, 1)) { + if (*It != V) + continue; + FoundLane = std::distance(Scalars.begin(), It); + assert(FoundLane < Scalars.size() && "Couldn't find extract lane"); + if (!ReorderIndices.empty()) + FoundLane = ReorderIndices[FoundLane]; + assert(FoundLane < Scalars.size() && "Couldn't find extract lane"); + if (ReuseShuffleIndices.empty()) + break; + if (auto *RIt = find(ReuseShuffleIndices, FoundLane); + RIt != ReuseShuffleIndices.end()) { + FoundLane = std::distance(ReuseShuffleIndices.begin(), RIt); + break; + } } + assert(FoundLane < getVectorFactor() && "Unable to find given value."); return FoundLane; }
[ { "file": "llvm/test/Transforms/SLPVectorizer/AArch64/reused-scalar-repeated-in-node.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=aarch64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nentry:\n br label %bb61\n\nbb61: ; preds = %entry\n br label %bb64\n\nbb62: ; No predecessors!\n br i1 poison, label %bb63, label %bb64\n\nbb63: ; preds = %bb62\n br label %bb64\n\nbb64: ; preds = %bb63, %bb62, %bb61\n %i = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\n %i65 = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\n %i66 = load float, ptr poison, align 16\n %i67 = load float, ptr poison, align 4\n %i68 = load float, ptr poison, align 8\n %i69 = load float, ptr poison, align 4\n %i70 = load float, ptr poison, align 4\n %i71 = load float, ptr poison, align 16\n %i72 = load float, ptr poison, align 4\n %i73 = load float, ptr poison, align 8\n %i74 = load float, ptr poison, align 4\n %i75 = load float, ptr poison, align 16\n %i76 = load float, ptr poison, align 4\n br i1 poison, label %bb167, label %bb77\n\nbb77: ; preds = %bb64\n br label %bb78\n\nbb78: ; preds = %bb78, %bb77\n %i79 = phi nsz float [ %i66, %bb77 ], [ %i103, %bb78 ]\n %i80 = phi nsz float [ %i67, %bb77 ], [ %i104, %bb78 ]\n %i81 = phi nsz float [ %i68, %bb77 ], [ %i105, %bb78 ]\n %i82 = phi nsz float [ poison, %bb77 ], [ %i106, %bb78 ]\n %i83 = phi nsz float [ poison, %bb77 ], [ %i123, %bb78 ]\n %i84 = phi nsz float [ %i69, %bb77 ], [ %i124, %bb78 ]\n %i85 = phi nsz float [ poison, %bb77 ], [ %i125, %bb78 ]\n %i86 = phi nsz float [ %i70, %bb77 ], [ %i126, %bb78 ]\n %i87 = fmul fast float %i79, poison\n %i88 = fmul fast float %i80, poison\n %i89 = fmul fast float %i81, poison\n %i90 = fmul fast float %i82, poison\n %i91 = fmul fast float %i83, poison\n %i92 = fadd fast float %i91, %i87\n %i93 = fmul fast float %i84, poison\n %i94 = fadd fast float %i93, %i88\n %i95 = fmul fast float %i85, poison\n %i96 = fadd fast float %i95, %i89\n %i97 = fmul fast float %i86, poison\n %i98 = fadd fast float %i97, %i90\n %i99 = fadd fast float %i92, poison\n %i100 = fadd fast float %i94, poison\n %i101 = fadd fast float %i96, poison\n %i102 = fadd fast float %i98, poison\n %i103 = fadd fast float %i99, poison\n %i104 = fadd fast float %i100, poison\n %i105 = fadd fast float %i101, poison\n %i106 = fadd fast float %i102, poison\n %i107 = fmul fast float %i79, poison\n %i108 = fmul fast float %i80, poison\n %i109 = fmul fast float %i81, poison\n %i110 = fmul fast float %i82, poison\n %i111 = fmul fast float %i83, poison\n %i112 = fadd fast float %i111, %i107\n %i113 = fmul fast float %i84, poison\n %i114 = fadd fast float %i113, %i108\n %i115 = fmul fast float %i85, poison\n %i116 = fadd fast float %i115, %i109\n %i117 = fmul fast float %i86, poison\n %i118 = fadd fast float %i117, %i110\n %i119 = fadd fast float %i112, poison\n %i120 = fadd fast float %i114, poison\n %i121 = fadd fast float %i116, poison\n %i122 = fadd fast float %i118, poison\n %i123 = fadd fast float %i119, poison\n %i124 = fadd fast float %i120, poison\n %i125 = fadd fast float %i121, poison\n %i126 = fadd fast float %i122, poison\n %i127 = fmul fast float %i79, %i\n %i128 = fmul fast float %i80, %i\n %i129 = fmul fast float %i81, %i\n %i130 = fmul fast float %i82, %i\n %i131 = fmul fast float %i83, %i65\n %i132 = fadd fast float %i131, %i127\n %i133 = fmul fast float %i84, %i65\n %i134 = fadd fast float %i133, %i128\n %i135 = fmul fast float %i85, %i65\n %i136 = fadd fast float %i135, %i129\n %i137 = fmul fast float %i86, %i65\n %i138 = fadd fast float %i137, %i130\n %i139 = fadd fast float %i132, poison\n %i140 = fadd fast float %i134, poison\n %i141 = fadd fast float %i136, poison\n %i142 = fadd fast float %i138, poison\n %i143 = fadd fast float %i139, poison\n %i144 = fadd fast float %i140, poison\n %i145 = fadd fast float %i141, poison\n %i146 = fadd fast float %i142, poison\n %i147 = fmul fast float %i79, poison\n %i148 = fmul fast float %i80, poison\n %i149 = fmul fast float %i81, poison\n %i150 = fmul fast float %i82, poison\n %i151 = fmul fast float %i83, poison\n %i152 = fadd fast float %i151, %i147\n %i153 = fmul fast float %i84, poison\n %i154 = fadd fast float %i153, %i148\n %i155 = fmul fast float %i85, poison\n %i156 = fadd fast float %i155, %i149\n %i157 = fmul fast float %i86, poison\n %i158 = fadd fast float %i157, %i150\n %i159 = fadd fast float %i152, poison\n %i160 = fadd fast float %i154, poison\n %i161 = fadd fast float %i156, poison\n %i162 = fadd fast float %i158, poison\n %i163 = fadd fast float %i159, poison\n %i164 = fadd fast float %i160, poison\n %i165 = fadd fast float %i161, poison\n %i166 = fadd fast float %i162, poison\n br i1 poison, label %bb78, label %bb167\n\nbb167: ; preds = %bb78, %bb64\n %i168 = phi nsz float [ %i76, %bb64 ], [ %i166, %bb78 ]\n %i169 = phi nsz float [ poison, %bb64 ], [ %i165, %bb78 ]\n %i170 = phi nsz float [ poison, %bb64 ], [ %i164, %bb78 ]\n %i171 = phi nsz float [ %i75, %bb64 ], [ %i163, %bb78 ]\n %i172 = phi nsz float [ %i74, %bb64 ], [ %i146, %bb78 ]\n %i173 = phi nsz float [ %i73, %bb64 ], [ %i145, %bb78 ]\n %i174 = phi nsz float [ %i72, %bb64 ], [ %i144, %bb78 ]\n %i175 = phi nsz float [ %i71, %bb64 ], [ %i143, %bb78 ]\n %i176 = phi nsz float [ %i70, %bb64 ], [ %i126, %bb78 ]\n %i177 = phi nsz float [ poison, %bb64 ], [ %i125, %bb78 ]\n %i178 = phi nsz float [ %i69, %bb64 ], [ %i124, %bb78 ]\n %i179 = phi nsz float [ poison, %bb64 ], [ %i123, %bb78 ]\n %i180 = phi nsz float [ poison, %bb64 ], [ %i106, %bb78 ]\n %i181 = phi nsz float [ %i68, %bb64 ], [ %i105, %bb78 ]\n %i182 = phi nsz float [ %i67, %bb64 ], [ %i104, %bb78 ]\n %i183 = phi nsz float [ %i66, %bb64 ], [ %i103, %bb78 ]\n store float %i182, ptr poison, align 1\n store float %i174, ptr poison, align 1\n br i1 poison, label %bb186, label %bb184\n\nbb184: ; preds = %bb167\n br label %bb185\n\nbb185: ; preds = %bb185, %bb184\n br i1 poison, label %bb185, label %bb186\n\nbb186: ; preds = %bb185, %bb167\n %i187 = phi nsz float [ %i178, %bb167 ], [ poison, %bb185 ]\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP] Assertion \"All elements in mask must be less than CommonVF.\" failed", "body": "[PR77529](https://github.com/llvm/llvm-project/pull/77529) trigger assertion on \"All elements in mask must be less than CommonVF.\" failed.\r\n\r\n@alexey-bataev \r\n\r\nTo reproduce, run with: opt -S -passes=slp-vectorizer t.ll -o o.ll\r\nUsing reduced t.ll below\r\n```\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32\"\r\ntarget triple = \"aarch64-unknown-linux-gnu\"\r\n\r\ndefine void @test() {\r\nentry:\r\n br label %bb61\r\n\r\nbb61:\r\n br label %bb64\r\n\r\nbb62:\r\n br i1 poison, label %bb63, label %bb64\r\n\r\nbb63:\r\n br label %bb64\r\n\r\nbb64:\r\n %i = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\r\n %i65 = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\r\n %i66 = load float, ptr poison, align 16\r\n %i67 = load float, ptr poison, align 4\r\n %i68 = load float, ptr poison, align 8\r\n %i69 = load float, ptr poison, align 4\r\n %i70 = load float, ptr poison, align 4\r\n %i71 = load float, ptr poison, align 16\r\n %i72 = load float, ptr poison, align 4\r\n %i73 = load float, ptr poison, align 8\r\n %i74 = load float, ptr poison, align 4\r\n %i75 = load float, ptr poison, align 16\r\n %i76 = load float, ptr poison, align 4\r\n br i1 poison, label %bb167, label %bb77\r\n\r\nbb77: ; preds = %bb64\r\n br label %bb78\r\n\r\nbb78: ; preds = %bb78, %bb77\r\n %i79 = phi nsz float [ %i66, %bb77 ], [ %i103, %bb78 ]\r\n %i80 = phi nsz float [ %i67, %bb77 ], [ %i104, %bb78 ]\r\n %i81 = phi nsz float [ %i68, %bb77 ], [ %i105, %bb78 ]\r\n %i82 = phi nsz float [ poison, %bb77 ], [ %i106, %bb78 ]\r\n %i83 = phi nsz float [ poison, %bb77 ], [ %i123, %bb78 ]\r\n %i84 = phi nsz float [ %i69, %bb77 ], [ %i124, %bb78 ]\r\n %i85 = phi nsz float [ poison, %bb77 ], [ %i125, %bb78 ]\r\n %i86 = phi nsz float [ %i70, %bb77 ], [ %i126, %bb78 ]\r\n %i87 = fmul fast float %i79, poison\r\n %i88 = fmul fast float %i80, poison\r\n %i89 = fmul fast float %i81, poison\r\n %i90 = fmul fast float %i82, poison\r\n %i91 = fmul fast float %i83, poison\r\n %i92 = fadd fast float %i91, %i87\r\n %i93 = fmul fast float %i84, poison\r\n %i94 = fadd fast float %i93, %i88\r\n %i95 = fmul fast float %i85, poison\r\n %i96 = fadd fast float %i95, %i89\r\n %i97 = fmul fast float %i86, poison\r\n %i98 = fadd fast float %i97, %i90\r\n %i99 = fadd fast float %i92, poison\r\n %i100 = fadd fast float %i94, poison\r\n %i101 = fadd fast float %i96, poison\r\n %i102 = fadd fast float %i98, poison\r\n %i103 = fadd fast float %i99, poison\r\n %i104 = fadd fast float %i100, poison\r\n %i105 = fadd fast float %i101, poison\r\n %i106 = fadd fast float %i102, poison\r\n %i107 = fmul fast float %i79, poison\r\n %i108 = fmul fast float %i80, poison\r\n %i109 = fmul fast float %i81, poison\r\n %i110 = fmul fast float %i82, poison\r\n %i111 = fmul fast float %i83, poison\r\n %i112 = fadd fast float %i111, %i107\r\n %i113 = fmul fast float %i84, poison\r\n %i114 = fadd fast float %i113, %i108\r\n %i115 = fmul fast float %i85, poison\r\n %i116 = fadd fast float %i115, %i109\r\n %i117 = fmul fast float %i86, poison\r\n %i118 = fadd fast float %i117, %i110\r\n %i119 = fadd fast float %i112, poison\r\n %i120 = fadd fast float %i114, poison\r\n %i121 = fadd fast float %i116, poison\r\n %i122 = fadd fast float %i118, poison\r\n %i123 = fadd fast float %i119, poison\r\n %i124 = fadd fast float %i120, poison\r\n %i125 = fadd fast float %i121, poison\r\n %i126 = fadd fast float %i122, poison\r\n %i127 = fmul fast float %i79, %i\r\n %i128 = fmul fast float %i80, %i\r\n %i129 = fmul fast float %i81, %i\r\n %i130 = fmul fast float %i82, %i\r\n %i131 = fmul fast float %i83, %i65\r\n %i132 = fadd fast float %i131, %i127\r\n %i133 = fmul fast float %i84, %i65\r\n %i134 = fadd fast float %i133, %i128\r\n %i135 = fmul fast float %i85, %i65\r\n %i136 = fadd fast float %i135, %i129\r\n %i137 = fmul fast float %i86, %i65\r\n %i138 = fadd fast float %i137, %i130\r\n %i139 = fadd fast float %i132, poison\r\n %i140 = fadd fast float %i134, poison\r\n %i141 = fadd fast float %i136, poison\r\n %i142 = fadd fast float %i138, poison\r\n %i143 = fadd fast float %i139, poison\r\n %i144 = fadd fast float %i140, poison\r\n %i145 = fadd fast float %i141, poison\r\n %i146 = fadd fast float %i142, poison\r\n %i147 = fmul fast float %i79, poison\r\n %i148 = fmul fast float %i80, poison\r\n %i149 = fmul fast float %i81, poison\r\n %i150 = fmul fast float %i82, poison\r\n %i151 = fmul fast float %i83, poison\r\n %i152 = fadd fast float %i151, %i147\r\n %i153 = fmul fast float %i84, poison\r\n %i154 = fadd fast float %i153, %i148\r\n %i155 = fmul fast float %i85, poison\r\n %i156 = fadd fast float %i155, %i149\r\n %i157 = fmul fast float %i86, poison\r\n %i158 = fadd fast float %i157, %i150\r\n %i159 = fadd fast float %i152, poison\r\n %i160 = fadd fast float %i154, poison\r\n %i161 = fadd fast float %i156, poison\r\n %i162 = fadd fast float %i158, poison\r\n %i163 = fadd fast float %i159, poison\r\n %i164 = fadd fast float %i160, poison\r\n %i165 = fadd fast float %i161, poison\r\n %i166 = fadd fast float %i162, poison\r\n br i1 poison, label %bb78, label %bb167\r\n\r\nbb167: ; preds = %bb78, %bb64\r\n %i168 = phi nsz float [ %i76, %bb64 ], [ %i166, %bb78 ]\r\n %i169 = phi nsz float [ poison, %bb64 ], [ %i165, %bb78 ]\r\n %i170 = phi nsz float [ poison, %bb64 ], [ %i164, %bb78 ]\r\n %i171 = phi nsz float [ %i75, %bb64 ], [ %i163, %bb78 ]\r\n %i172 = phi nsz float [ %i74, %bb64 ], [ %i146, %bb78 ]\r\n %i173 = phi nsz float [ %i73, %bb64 ], [ %i145, %bb78 ]\r\n %i174 = phi nsz float [ %i72, %bb64 ], [ %i144, %bb78 ]\r\n %i175 = phi nsz float [ %i71, %bb64 ], [ %i143, %bb78 ]\r\n %i176 = phi nsz float [ %i70, %bb64 ], [ %i126, %bb78 ]\r\n %i177 = phi nsz float [ poison, %bb64 ], [ %i125, %bb78 ]\r\n %i178 = phi nsz float [ %i69, %bb64 ], [ %i124, %bb78 ]\r\n %i179 = phi nsz float [ poison, %bb64 ], [ %i123, %bb78 ]\r\n %i180 = phi nsz float [ poison, %bb64 ], [ %i106, %bb78 ]\r\n %i181 = phi nsz float [ %i68, %bb64 ], [ %i105, %bb78 ]\r\n %i182 = phi nsz float [ %i67, %bb64 ], [ %i104, %bb78 ]\r\n %i183 = phi nsz float [ %i66, %bb64 ], [ %i103, %bb78 ]\r\n store float %i182, ptr poison, align 1\r\n store float %i174, ptr poison, align 1\r\n br i1 poison, label %bb186, label %bb184\r\n\r\nbb184: ; preds = %bb167\r\n br label %bb185\r\n\r\nbb185: ; preds = %bb185, %bb184\r\n br i1 poison, label %bb185, label %bb186\r\n\r\nbb186: ; preds = %bb185, %bb167\r\n %i187 = phi nsz float [ %i178, %bb167 ], [ poison, %bb185 ]\r\n ret void\r\n}\r\n```", "author": "huihzhang", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
96294
https://github.com/llvm/llvm-project/issues/96294
crash
5262865aac683b72f3e66de7a122e0c455ab6b9b
2024-06-21T10:15:21
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "fdb9f96fa2a926425bdf8315048db7623d63547d", "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": [ [ 6723, 6736 ], [ 6771, 6776 ], [ 6781, 6788 ] ], "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 fdb9f96fa2a926425bdf8315048db7623d63547d Author: Florian Hahn <[email protected]> Date: Sun Aug 4 20:54:25 2024 +0100 [LV] Consider earlier stores to invariant reduction address as dead. For invariant stores to an address of a reduction, only the latest store will be generated outside the loop. Consider earlier stores as dead. This fixes a difference between the legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/96294. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 40d10395de17..1eca9b10fad5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6723,14 +6723,18 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { return RequiresScalarEpilogue && !TheLoop->contains(cast<Instruction>(U)->getParent()); }; + MapVector<Value *, SmallVector<Value *>> DeadInvariantStoreOps; for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { // Find all stores to invariant variables. Since they are going to sink // outside the loop we do not need calculate cost for them. StoreInst *SI; if ((SI = dyn_cast<StoreInst>(&I)) && - Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) + Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) { ValuesToIgnore.insert(&I); + auto I = DeadInvariantStoreOps.insert({SI->getPointerOperand(), {}}); + I.first->second.push_back(SI->getValueOperand()); + } if (VecValuesToIgnore.contains(&I) || ValuesToIgnore.contains(&I)) continue; @@ -6771,6 +6775,10 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { DeadInterleavePointerOps.append(Op->op_begin(), Op->op_end()); } + for (const auto &[_, Ops] : DeadInvariantStoreOps) { + for (Value *Op : ArrayRef(Ops).drop_back()) + DeadOps.push_back(Op); + } // Mark ops that would be trivially dead and are only used by ignored // instructions as free. BasicBlock *Header = TheLoop->getHeader(); @@ -6781,8 +6789,8 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { (isa<PHINode>(Op) && Op->getParent() == Header) || !wouldInstructionBeTriviallyDead(Op, TLI) || any_of(Op->users(), [this, IsLiveOutDead](User *U) { - return !VecValuesToIgnore.contains(U) && ValuesToIgnore.contains(U) && - !IsLiveOutDead(U); + return !VecValuesToIgnore.contains(U) && + !ValuesToIgnore.contains(U) && !IsLiveOutDead(U); })) continue;
[ { "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": "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 } ] } ]
{ "title": "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10353: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "[calcc-0ebd65.c.gz](https://github.com/user-attachments/files/15926158/calcc-0ebd65.c.gz)\r\n[calcc-0ebd65.sh.gz](https://github.com/user-attachments/files/15926159/calcc-0ebd65.sh.gz)\r\n\r\nStack backtrace is \r\n\r\n#11 0x0000000003adfddd llvm::LoopVectorizePass::processLoop(llvm::Loop*) /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10353:9\r\n#12 0x0000000003ae347f 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*) /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10446:27\r\n#13 0x0000000003ae4382 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10486:5\r\n#14 0x00000000034fbd6d llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb40b/llvm/trunk/llvm/include/llvm/IR/PassManagerInternal.h:91:3\r\n#15 0x0000000001ae5b21 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb40b/llvm/trunk/llvm/include/llvm/IR/PassManagerImpl.h:53:18\r\n", "author": "dcb314", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "dcb314", "body": "The crash first seems to occur sometime between git hash fd88089151e66a4cb1d90aaa224e4cb4e7a748f4 from yesterday 20240620\r\nand 225d8fc8eb24fb797154c1ef6dcbe5ba033142da from today,\r\nwhich is 134 commits.\r\n" }, { "author": "fhahn", "body": "Thanks for the report, caused by https://github.com/llvm/llvm-project/pull/92555 which has been reverted for now. I'll add a reduced test based on the reproducer." }, { "author": "fhahn", "body": "https://github.com/llvm/llvm-project/pull/92555 has been recommitted with a fix. Please let me know if you see any other issues!" }, { "author": "dcb314", "body": "It has come back:\r\n\r\nclang: /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10377: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\n\r\n[in-4e39b8.sh.gz](https://github.com/user-attachments/files/16445872/in-4e39b8.sh.gz)\r\n[Uploading in-4e39b8.c.gz…]()\r\n" }, { "author": "dcb314", "body": "Seems to have come back sometime between d99efd53f5103df4db517f499fcdd26cd3b080a3\r\n(dated 20240710) and 4710e0f498cb661ca17c99cb174616102fcad923, dated 20240711.\r\n\r\n" }, { "author": "fhahn", "body": "@dcb314 it looks like there has been an issue with uploading the `.c` file. Could you re-upload it again?" }, { "author": "dcb314", "body": "My apologies for the failed upload.\r\nHere is another try:\r\n\r\n[in-4e39b8.c.gz](https://github.com/user-attachments/files/16455342/in-4e39b8.c.gz)\r\n" } ] }
true
null
119393
https://github.com/llvm/llvm-project/issues/119393
crash
13539c219c49c581d6ba5270d09b19da9b1e3975
2024-12-10T15:25:03
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "a42aa8f265372a15d31a2af10b548fc239ed4b51", "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": [ [ 13222, 13230 ] ], "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 a42aa8f265372a15d31a2af10b548fc239ed4b51 Author: Alexey Bataev <[email protected]> Date: Tue Dec 10 09:19:48 2024 -0800 [SLP]Fix adjusting of the mask for the fully matched nodes. When checking for the poison elements in the matches node, need to consider the register number, when clearing the corresponding mask element. Fixes #119393 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c729c6cc9195..d90d7cc8f29e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13222,9 +13222,9 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( copy(CommonMask, Mask.begin()); } // Clear undef scalars. - for (int I = 0, Sz = VL.size(); I < Sz; ++I) + for (unsigned I : seq<unsigned>(VL.size())) if (isa<PoisonValue>(VL[I])) - Mask[I] = PoisonMaskElem; + Mask[Part * VL.size() + I] = PoisonMaskElem; return TargetTransformInfo::SK_PermuteSingleSrc; } // No perfect match, just shuffle, so choose the first tree node from the
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/full-match-with-poison-scalar.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-200 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test() {\nentry:\n br label %func_135.exit.i\n\nfunc_135.exit.i: ; preds = %entry\n %g_228.promoted166.i1105.i = phi i32 [ 0, %entry ]\n %cmp55.i.i1199.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.1.i.i1200.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.2.i.i1201.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.3.i.i1202.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %0 = xor i1 %cmp55.2.i.i1201.i, %cmp55.3.i.i1202.i\n %1 = xor i1 %cmp55.1.i.i1200.i, %0\n %2 = xor i1 %cmp55.i.i1199.i, %1\n %dec.i.i1204.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.1.i.i1200.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.2.i.i1201.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.3.i.i1202.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %3 = xor i1 %cmp55.2.i.i1201.1.i, %cmp55.3.i.i1202.1.i\n %4 = xor i1 %cmp55.1.i.i1200.1.i, %3\n %5 = xor i1 %cmp55.i.i1199.1.i, %4\n %6 = xor i1 %2, %5\n %dec.i.i1204.1.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.1.i.i1200.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.2.i.i1201.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.3.i.i1202.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %7 = add i32 0, 0\n %8 = icmp ult i32 %7, 0\n %9 = xor i1 %cmp55.3.i.i1202.2.i, %8\n %10 = xor i1 %cmp55.2.i.i1201.2.i, %9\n %11 = xor i1 %cmp55.1.i.i1200.2.i, %10\n %12 = xor i1 %cmp55.i.i1199.2.i, %11\n %13 = xor i1 %12, %6\n %dec.i.i1204.2.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.1.i.i1200.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.2.i.i1201.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %14 = xor i1 %cmp55.1.i.i1200.3.i, %cmp55.2.i.i1201.3.i\n %15 = xor i1 %cmp55.i.i1199.3.i, %14\n %16 = xor i1 %15, %13\n %17 = zext i1 %16 to i16\n br label %if.then.sink.split.i\n\nfor.cond7.preheader.i1132.1.i: ; No predecessors!\n br label %if.then.sink.split.i\n\nif.then.sink.split.i: ; preds = %for.cond7.preheader.i1132.1.i, %func_135.exit.i\n %xor58.5.i.i1203.3.3.sink.i = phi i16 [ 0, %for.cond7.preheader.i1132.1.i ], [ %17, %func_135.exit.i ]\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed.", "body": "Reproducer: https://godbolt.org/z/3dahr6Mb4\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() {\nentry:\n br label %func_135.exit.i\n\nfunc_135.exit.i:\n %g_228.promoted166.i1105.i = phi i32 [ 0, %entry ]\n %cmp55.i.i1199.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.1.i.i1200.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.2.i.i1201.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.3.i.i1202.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %0 = xor i1 %cmp55.2.i.i1201.i, %cmp55.3.i.i1202.i\n %1 = xor i1 %cmp55.1.i.i1200.i, %0\n %2 = xor i1 %cmp55.i.i1199.i, %1\n %dec.i.i1204.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.1.i.i1200.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.2.i.i1201.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.3.i.i1202.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %3 = xor i1 %cmp55.2.i.i1201.1.i, %cmp55.3.i.i1202.1.i\n %4 = xor i1 %cmp55.1.i.i1200.1.i, %3\n %5 = xor i1 %cmp55.i.i1199.1.i, %4\n %6 = xor i1 %2, %5\n %dec.i.i1204.1.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.1.i.i1200.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.2.i.i1201.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.3.i.i1202.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %7 = add i32 0, 0\n %8 = icmp ult i32 %7, 0\n %9 = xor i1 %cmp55.3.i.i1202.2.i, %8\n %10 = xor i1 %cmp55.2.i.i1201.2.i, %9\n %11 = xor i1 %cmp55.1.i.i1200.2.i, %10\n %12 = xor i1 %cmp55.i.i1199.2.i, %11\n %13 = xor i1 %12, %6\n %dec.i.i1204.2.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.1.i.i1200.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.2.i.i1201.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %14 = xor i1 %cmp55.1.i.i1200.3.i, %cmp55.2.i.i1201.3.i\n %15 = xor i1 %cmp55.i.i1199.3.i, %14\n %16 = xor i1 %15, %13\n %17 = zext i1 %16 to i16\n br label %if.then.sink.split.i\n\nfor.cond7.preheader.i1132.1.i: ; No predecessors!\n br label %if.then.sink.split.i\n\nif.then.sink.split.i: ; preds = %for.cond7.preheader.i1132.1.i, %func_135.exit.i\n %xor58.5.i.i1203.3.3.sink.i = phi i16 [ 0, %for.cond7.preheader.i1132.1.i ], [ %17, %func_135.exit.i ]\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10913: 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.\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 0x00000000051c9e58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51c9e58)\n #1 0x00000000051c785c SignalHandler(int) Signals.cpp:0:0\n #2 0x000078cea7e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000078cea7e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000078cea7e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000078cea7e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000078cea7e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000078cea7e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000041fda54 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+0x41fda54)\n #9 0x00000000042390b0 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+0x42390b0)\n#10 0x0000000004243fa7 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+0x4243fa7)\n#11 0x0000000004277f91 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4277f91)\n#12 0x000000000427da60 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\n#13 0x0000000004280ea9 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4280ea9)\n#14 0x000000000428563b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#15 0x0000000004289c9f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4289c9f)\n#16 0x0000000004290786 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 0x00000000042912cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42912cb)\n#18 0x0000000002fdbfee 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+0x2fdbfee)\n#19 0x0000000004fc8d00 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fc8d00)\n#20 0x0000000000e3b51e 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+0xe3b51e)\n#21 0x0000000004fc761b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fc761b)\n#22 0x0000000000e3abae 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+0xe3abae)\n#23 0x0000000004fc7020 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fc7020)\n#24 0x00000000009177ca 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+0x9177ca)\n#25 0x0000000000909e49 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x909e49)\n#26 0x000078cea7e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000078cea7e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x0000000000901705 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x901705)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
121432
https://github.com/llvm/llvm-project/issues/121432
miscompilation
b51a082e1afd707f8cf1473e4c49374e7e951d2d
2025-01-01T11:07:27
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "c05599966cd594c15834378f57669719d221c4d4", "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": [ [ 2673, 2680 ] ], "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": [ "InstCombinerImpl::visitCallInst" ], "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 c05599966cd594c15834378f57669719d221c4d4 Author: Yingwei Zheng <[email protected]> Date: Mon Jan 6 16:23:46 2025 +0800 [InstCombine] Fix FMF propagation in `copysign Mag, (copysign ?, X) -> copysign Mag, X` (#121574) Closes https://github.com/llvm/llvm-project/issues/121432. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index cdb2c11ef046..5494c70b34b1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2673,8 +2673,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { // Propagate sign argument through nested calls: // copysign Mag, (copysign ?, X) --> copysign Mag, X Value *X; - if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) - return replaceOperand(*II, 1, X); + if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) { + Value *CopySign = Builder.CreateCopySign( + Mag, X, + II->getFastMathFlags() & cast<Instruction>(Sign)->getFastMathFlags()); + return replaceInstUsesWith(*II, CopySign); + } // Clear sign-bit of constant magnitude: // copysign -MagC, X --> copysign MagC, X
[ { "file": "llvm/test/Transforms/InstCombine/copysign.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "copysign_sign_arg_mixed", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "copysign_sign_arg", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @copysign_sign_arg(float %x, float %y, float %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call ninf float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fneg_mag", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @fneg_mag(float %x, float %y) {\n %n = fneg float %x\n %r = call float @llvm.copysign.f32(float %n, float %y)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "copysign_sign_arg_nnan", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @copysign_sign_arg_nnan(float %x, float %y, float %z) {\n %s = call nnan float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "not_known_positive_sign_arg", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.maxnum.f32(float, float) #0\n\ndefine float @not_known_positive_sign_arg(float %x, float %y) {\n %max = call float @llvm.maxnum.f32(float %x, float 0.000000e+00)\n %r = call ninf float @llvm.copysign.f32(float %y, float %max)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] FMF flags should not be propagated", "body": "Alive2: https://alive2.llvm.org/ce/z/ajCxTh\n```\ndefine float @src1(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt1(float noundef %x, float noundef %y, float noundef %z) {\n %r = call nnan float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n\ndefine float @src2(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call ninf float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt2(float noundef %x, float noundef %y, float noundef %z) {\n %r = call ninf float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n\ndefine float @src3(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call nsz float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt3(float noundef %x, float noundef %y, float noundef %z) {\n %r = call nsz float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [] }
true
null
98838
https://github.com/llvm/llvm-project/issues/98838
miscompilation
9ba9e480fa4ef1f37a2b6b51603ac8e446cca5ff
2024-07-14T21:26:59
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "beccecaacde405a3b50891c67594eccbcd1c8b08", "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": [ [ 14201, 14209 ] ], "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" ], "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 beccecaacde405a3b50891c67594eccbcd1c8b08 Author: Alexey Bataev <[email protected]> Date: Mon Jul 15 07:03:22 2024 -0700 [SLP]Fix PR98838: do no replace condition of select-based logical op by poison. If the reduction operation is a select-based logical op, the condition should be replaced by the poison, better to replace by the non-poisoning constant to prevent poison propagation in the vector code. Fixes https://github.com/llvm/llvm-project/issues/98838 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 5c2fc0b9320e..74a16d3fbcad 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14201,9 +14201,23 @@ Value *BoUpSLP::vectorizeTree( for (Instruction *I : RemovedInsts) { if (getTreeEntry(I)->Idx != 0) continue; + SmallVector<SelectInst *> LogicalOpSelects; I->replaceUsesWithIf(PoisonValue::get(I->getType()), [&](Use &U) { + // Do not replace condition of the logical op in form select <cond>. + bool IsPoisoningLogicalOp = isa<SelectInst>(U.getUser()) && + (match(U.getUser(), m_LogicalAnd()) || + match(U.getUser(), m_LogicalOr())) && + U.getOperandNo() == 0; + if (IsPoisoningLogicalOp) { + LogicalOpSelects.push_back(cast<SelectInst>(U.getUser())); + return false; + } return UserIgnoreList->contains(U.getUser()); }); + // Replace conditions of the poisoning logical ops with the non-poison + // constant value. + for (SelectInst *SI : LogicalOpSelects) + SI->setCondition(Constant::getNullValue(SI->getCondition()->getType())); } } // Retain to-be-deleted instructions for some debug-info bookkeeping and alias
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/select-reduction-op.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "src", "test_body": "define i1 @src(i1 %cmp4.118.i) {\n %cmp4.118.i.not = xor i1 %cmp4.118.i, true\n %brmerge = select i1 %cmp4.118.i.not, i1 true, i1 poison\n %.not = xor i1 poison, true\n %brmerge2 = select i1 %brmerge, i1 true, i1 %.not\n %.not3 = xor i1 poison, true\n %brmerge4 = select i1 %brmerge2, i1 true, i1 %.not3\n %.not5 = xor i1 poison, true\n %brmerge6 = select i1 %brmerge4, i1 true, i1 %.not5\n %.not7 = xor i1 poison, true\n %brmerge8 = select i1 %brmerge6, i1 true, i1 %.not7\n ret i1 %brmerge8\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "wrong code at -O3 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/fzsqjEPWW\r\n\r\n```\r\n[562] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 52139d8f9a4e3f595ca552393d62ba06b0bc082c)\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[563] % \r\n[563] % clangtk -O2 -w small.c\r\n[564] % ./a.out\r\n0\r\n[565] % clangtk -O3 -w small.c\r\n[566] % ./a.out\r\n[567] % \r\n[567] % cat small.c\r\nint printf(const char *, ...);\r\nint a, b, e, g;\r\nvolatile int c;\r\nstatic int d[1] = {1}, f;\r\nint h() {\r\n for (b = 0; b < 4; b++) {\r\n for (e = 0; e < 4; e++)\r\n while (b) {\r\n if (c > 0 && d[1])\r\n break;\r\n return f;\r\n }\r\n }\r\n return 0;\r\n}\r\nvoid i() {\r\n int *j[1];\r\n j[g] = &d[0];\r\n}\r\nint main() {\r\n h();\r\n printf(\"%d\\n\", a);\r\n return 0;\r\n}\r\n```\r\n\r\n", "author": "zhendongsu", "labels": [ "miscompilation", "llvm:SLPVectorizer", "confirmed" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/Whfr_a\r\n```\r\n; bin/opt -passes=slp-vectorizer -S test.ll\r\ndefine i1 @src(i1 %cmp4.118.i) {\r\n %cmp4.118.i.not = xor i1 %cmp4.118.i, true\r\n %brmerge = select i1 %cmp4.118.i.not, i1 true, i1 poison\r\n %.not = xor i1 poison, true\r\n %brmerge2 = select i1 %brmerge, i1 true, i1 %.not\r\n %.not3 = xor i1 poison, true\r\n %brmerge4 = select i1 %brmerge2, i1 true, i1 %.not3\r\n %.not5 = xor i1 poison, true\r\n %brmerge6 = select i1 %brmerge4, i1 true, i1 %.not5\r\n %.not7 = xor i1 poison, true\r\n %brmerge8 = select i1 %brmerge6, i1 true, i1 %.not7\r\n ret i1 %brmerge8\r\n}\r\n```\r\n```\r\ndefine i1 @tgt(i1 %cmp4.118.i) {\r\n %1 = insertelement <4 x i1> <i1 poison, i1 true, i1 true, i1 true>, i1 %cmp4.118.i, i32 0\r\n %2 = xor <4 x i1> %1, <i1 true, i1 poison, i1 poison, i1 poison>\r\n %.not7 = xor i1 poison, true\r\n %3 = freeze <4 x i1> %2\r\n %4 = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> %3)\r\n %op.rdx = select i1 %4, i1 true, i1 %.not7\r\n %op.rdx1 = select i1 poison, i1 true, i1 %op.rdx\r\n ret i1 %op.rdx1\r\n}\r\n```\r\ncc @alexey-bataev " } ] }
true
null
98660
https://github.com/llvm/llvm-project/issues/98660
crash
efde640cdfede834fa79e0eea69f82fb769d6beb
2024-07-12T16:45:01
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "fc9cd3272b50f4ee9f18c4ab82c278bbb014d99f", "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": [ [ 8693, 8698 ] ], "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 fc9cd3272b50f4ee9f18c4ab82c278bbb014d99f Author: Florian Hahn <[email protected]> Date: Sun Jul 14 20:49:03 2024 +0100 [VPlan] Don't add live-outs for IV phis. Resume and exit values for inductions are currently still created outside of VPlan and independent of the induction recipes. Don't add live-outs for now, as the additional unneeded users can pessimize other anlysis. Fixes https://github.com/llvm/llvm-project/issues/98660. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 7d37d67cde29..5520baef7152 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8693,6 +8693,14 @@ static void addUsersInExitBlock(VPBasicBlock *HeaderVPBB, Loop *OrigLoop, Value *IncomingValue = ExitPhi.getIncomingValueForBlock(ExitingBB); VPValue *V = Builder.getVPValueOrAddLiveIn(IncomingValue, Plan); + // Exit values for inductions are computed and updated outside of VPlan and + // independent of induction recipes. + // TODO: Compute induction exit values in VPlan, use VPLiveOuts to update + // live-outs. + if ((isa<VPWidenIntOrFpInductionRecipe>(V) && + !cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst()) || + isa<VPWidenPointerInductionRecipe>(V)) + continue; Plan.addLiveOut(&ExitPhi, V); } }
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/sve-live-out-pointer-induction.ll", "commands": [ "opt -passes=loop-vectorize -mtriple=aarch64-unknown -mattr=+sve -S %s" ], "tests": [ { "test_name": "test", "test_body": "define ptr @test(ptr %start.1, ptr %start.2, ptr %end) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi ptr [ %start.1, %entry ], [ %iv.1.next, %loop ]\n %iv.2 = phi ptr [ %start.2, %entry ], [ %iv.2.next, %loop ]\n store i64 0, ptr %iv.2, align 4\n %iv.2.next = getelementptr inbounds ptr, ptr %iv.2, i64 1\n %iv.1.next = getelementptr inbounds ptr, ptr %iv.1, i64 1\n %cmp.i.i.not.i = icmp eq ptr %iv.2.next, %end\n br i1 %cmp.i.i.not.i, label %exit, label %loop\n\nexit: ; preds = %loop\n %res.lcssa = phi ptr [ %iv.1, %loop ]\n ret ptr %res.lcssa\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/ephemeral-recipes.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "ephemeral_load_and_compare_iv_used_outside", "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-macosx\"\n\ndefine i32 @ephemeral_load_and_compare_iv_used_outside(ptr %start, ptr %end) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi ptr [ %start, %entry ], [ %iv.next, %loop ]\n %iv.next = getelementptr nusw i8, ptr %iv, i64 -8\n %l1 = load i32, ptr %iv, align 4\n %cmp = icmp ne i32 %l1, 0\n call void @llvm.assume(i1 %cmp)\n %cmp.not = icmp eq ptr %iv, %end\n br i1 %cmp.not, label %exit, label %loop\n\nexit: ; preds = %loop\n %final.load = load i32, ptr %iv, align 4\n ret i32 %final.load\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/iv-live-outs.ll", "commands": [ "opt -p loop-vectorize -mcpu=skylake-avx512 -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @test_pr98660(ptr %dst, i64 %N) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %or = or disjoint i64 %iv, 1\n %gep = getelementptr i32, ptr %dst, i64 %or\n %l = load i32, ptr %gep\n %c = icmp eq i32 %l, 0\n br i1 %c, label %then, label %loop.latch\n\nthen:\n store i32 0, ptr %gep, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add i64 %iv, 1\n %ec = icmp ult i64 %iv, %N\n br i1 %ec, label %loop.header, label %exit\n\nexit:\n %ret = phi i64 [ %iv, %loop.latch ]\n ret i64 %ret\n}\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/iv_outside_user.ll", "commands": [ "opt -S -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s", "opt -S -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 < %s" ], "tests": [ { "test_name": "iv_2_dead_in_loop_only_used_outside", "test_body": "define i32 @iv_2_dead_in_loop_only_used_outside(ptr %ptr) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]\n %iv.next = add nuw i64 %iv, 1\n %iv.2.next = add nuw i32 %iv.2, 2\n %gep.ptr = getelementptr inbounds i64, ptr %ptr, i64 %iv\n store i64 %iv, ptr %gep.ptr, align 4\n %exitcond = icmp ugt i64 %iv, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n %iv.2.lcssa = phi i32 [ %iv.2, %loop ]\n ret i32 %iv.2.lcssa\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/no-fold-tail-by-masking-iv-external-uses.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(ptr %arr, i64 %n) {\nentry:\n %cmp1 = icmp ugt i64 %n, 1\n br i1 %cmp1, label %preheader, label %done\n\npreheader: ; preds = %entry\n br label %loop\n\nloop: ; preds = %loop, %preheader\n %conv = phi i64 [ %conv2, %loop ], [ 1, %preheader ]\n %i = phi i8 [ %inc, %loop ], [ 1, %preheader ]\n %sub = add nsw i64 %conv, -1\n %ptr = getelementptr inbounds i32, ptr %arr, i64 %sub\n store i32 65, ptr %ptr, align 4\n %inc = add i8 %i, 1\n %conv2 = zext i8 %inc to i64\n %cmp2 = icmp ult i64 %conv2, %n\n br i1 %cmp2, label %loop, label %load_val, !llvm.loop !0\n\nload_val: ; preds = %loop\n %final = phi i64 [ %conv, %loop ]\n %ptr2 = getelementptr inbounds i32, ptr %arr, i64 %final\n %val = load i32, ptr %ptr2, align 4\n br label %done\n\ndone: ; preds = %load_val, %entry\n %value = phi i32 [ %val, %load_val ], [ 0, %entry ]\n ret i32 %value\n}\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.unroll.disable\"}\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 } ] }, { "file": "llvm/test/Transforms/LoopVectorize/pr58811-scev-expansion.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test1_pr58811", "test_body": "define void @test1_pr58811() {\nentry:\n br label %loop.1.preheader\n\nloop.1.preheader: ; preds = %unreachable.bb, %entry\n %iv.1.ph = phi i32 [ %sub93.2, %unreachable.bb ], [ 0, %entry ]\n br label %loop.1\n\nloop.1: ; preds = %loop.1, %loop.1.preheader\n %iv.1 = phi i32 [ %iv.1.next, %loop.1 ], [ %iv.1.ph, %loop.1.preheader ]\n %iv.2 = phi i32 [ %iv.2.next, %loop.1 ], [ 0, %loop.1.preheader ]\n %iv.2.next = add i32 %iv.2, 1\n %iv.1.next = add i32 %iv.2, %iv.1\n br i1 false, label %loop.1, label %loop.2.preheader\n\nloop.2.preheader: ; preds = %loop.1\n %iv.1.lcssa = phi i32 [ %iv.1, %loop.1 ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %loop.2.preheader\n %iv.3 = phi i16 [ %iv.3.next, %loop.2 ], [ 0, %loop.2.preheader ]\n %iv.4 = phi i32 [ %iv.4.next, %loop.2 ], [ 0, %loop.2.preheader ]\n %iv.4.next = sub i32 %iv.4, %iv.1.lcssa\n %iv.3.next = add i16 %iv.3, 1\n %cmp88.1 = icmp ult i16 %iv.3, 198\n br i1 %cmp88.1, label %loop.2, label %loop.3.preheader\n\nloop.3.preheader: ; preds = %loop.2\n %iv.4.lcssa = phi i32 [ %iv.4, %loop.2 ]\n br label %loop.3\n\nloop.3: ; preds = %loop.3, %loop.3.preheader\n %iv.5 = phi i32 [ %sub93.2, %loop.3 ], [ 0, %loop.3.preheader ]\n %sub93.2 = sub i32 %iv.5, %iv.4.lcssa\n br label %loop.3\n\nunreachable.bb: ; No predecessors!\n br label %loop.1.preheader\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test2_pr58811", "test_body": "define void @test2_pr58811() {\nentry:\n br label %loop.1.header\n\nloop.1.header: ; preds = %loop.4, %entry\n %p.1 = phi i32 [ 0, %entry ], [ %sub93.2, %loop.4 ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %loop.1.header\n %iv.2 = phi i32 [ %p.1, %loop.1.header ], [ %add101, %loop.2 ]\n %iv.3 = phi i32 [ 0, %loop.1.header ], [ %sub93, %loop.2 ]\n %sub93 = add i32 %iv.3, 1\n %add101 = add i32 %iv.3, %iv.2\n br i1 false, label %loop.2, label %loop.3\n\nloop.3: ; preds = %loop.3, %loop.2\n %iv.4 = phi i16 [ 0, %loop.2 ], [ %inc.1, %loop.3 ]\n %iv.5 = phi i32 [ 0, %loop.2 ], [ %sub93.1, %loop.3 ]\n %sub93.1 = sub i32 %iv.5, %iv.2\n %inc.1 = add i16 %iv.4, 1\n %cmp88.1 = icmp ult i16 %iv.4, 198\n br i1 %cmp88.1, label %loop.3, label %loop.4\n\nloop.4: ; preds = %loop.4, %loop.3\n %iv.6 = phi i32 [ 0, %loop.3 ], [ %sub93.2, %loop.4 ]\n %sub93.2 = sub i32 %iv.6, %iv.5\n br i1 false, label %loop.4, label %loop.1.header\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test3_pr58811", "test_body": "define void @test3_pr58811() {\nentry:\n br label %loop.1.header\n\nloop.1.header: ; preds = %loop.1.latch, %entry\n %p.1 = phi i32 [ 0, %entry ], [ %sub93.2, %loop.1.latch ]\n %rem85 = urem i32 1, %p.1\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %loop.1.header\n %p.2 = phi i32 [ 1, %loop.1.header ], [ 0, %loop.2 ]\n %add101 = add i32 %rem85, %p.2\n br i1 false, label %loop.2, label %loop.3\n\nloop.3: ; preds = %loop.3, %loop.2\n %iv.3 = phi i16 [ 0, %loop.2 ], [ %inc.1, %loop.3 ]\n %iv.4 = phi i32 [ 0, %loop.2 ], [ %sub93.1, %loop.3 ]\n %sub93.1 = sub i32 %iv.4, %add101\n %inc.1 = add i16 %iv.3, 1\n %cmp88.1 = icmp ult i16 %iv.3, 198\n br i1 %cmp88.1, label %loop.3, label %loop.4\n\nloop.4: ; preds = %loop.4, %loop.3\n %iv.5 = phi i32 [ 0, %loop.3 ], [ %sub93.2, %loop.4 ]\n %sub93.2 = sub i32 %iv.5, %iv.4\n br label %loop.4\n\nloop.1.latch: ; No predecessors!\n br label %loop.1.header\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `(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 \" \"per part.\"' failed.", "body": "To reproduce run opt opt with -passes loop-vectorize with 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(i64 %arg) #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb3, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb3 ]\r\n br i1 false, label %bb2, label %bb3\r\n\r\nbb2: ; preds = %bb1\r\n %or = or disjoint i64 %phi, 0\r\n %getelementptr = getelementptr i32, ptr addrspace(1) null, i64 %or\r\n store i32 0, ptr addrspace(1) %getelementptr, align 4\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb2, %bb1\r\n %add = add i64 %phi, 1\r\n %icmp = icmp ult i64 %phi, %arg\r\n br i1 %icmp, label %bb1, label %bb4\r\n\r\nbb4: ; preds = %bb3\r\n %phi5 = phi i64 [ %phi, %bb3 ]\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+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,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,+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\nReproducer:\r\nhttps://godbolt.org/z/Ghz3147nj\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 <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 0x0000000004e9b948 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e9b948)\r\n #1 0x0000000004e990bc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000070edf8442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000070edf84969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000070edf8442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000070edf84287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000070edf842871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000070edf8439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000040395f7 llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40395f7)\r\n #9 0x0000000004056ece llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4056ece)\r\n#10 0x00000000040595ee llvm::VPInstruction::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40595ee)\r\n#11 0x0000000004030a1f llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4030a1f)\r\n#12 0x00000000040320e8 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40320e8)\r\n#13 0x0000000004030612 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4030612)\r\n#14 0x0000000004039946 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4039946)\r\n#15 0x0000000003f1d475 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+0x3f1d475)\r\n#16 0x0000000003f332ea llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f332ea)\r\n#17 0x0000000003f35a29 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+0x3f35a29)\r\n#18 0x0000000003f3614b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f3614b)\r\n#19 0x0000000002e212be 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+0x2e212be)\r\n#20 0x0000000004c9f2d8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9f2d8)\r\n#21 0x0000000000dc9bee 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+0xdc9bee)\r\n#22 0x0000000004c9dd46 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9dd46)\r\n#23 0x0000000000dca1fe 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+0xdca1fe)\r\n#24 0x0000000004c9bf10 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9bf10)\r\n#25 0x00000000008db1d2 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+0x8db1d2)\r\n#26 0x00000000008ce0fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce0fc)\r\n#27 0x000070edf8429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#28 0x000070edf8429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#29 0x00000000008c556e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c556e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Interesting, let me take a look" } ] }
true
null
77118
https://github.com/llvm/llvm-project/issues/77118
crash
40fae67a50e08e6b5b5300210021218e404d63a7
2024-01-05T16:53:32
[ "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "e209178d6402348414b69941c77d621919b3b7ab", "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": [ [ 25, 30 ], [ 643, 652 ] ], "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": [ "SimplifyIndvar::replaceIVUserWithLoopInvariant" ], "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 e209178d6402348414b69941c77d621919b3b7ab Author: Vedant Paranjape <[email protected]> Date: Wed Feb 21 17:51:56 2024 +0530 [SimplifyIndVar] LCSSA form is destroyed by simplifyLoopIVs, preserve it (#78696) In LoopUnroll, peelLoop is called on the loop. After the loop is peeled it calls simplifyLoopAfterUnroll on the loop. This call to simplifyLoopAfterUnroll doesn't preserve the LCSSA form of the parent loop and thus during the next call to peelLoop the LCSSA form is already broken. LoopPeel util takes in the PreserveLCSSA argument and it passes on the same argument to simplifyLoop which checks if the loop is in a valid LCSSA form, when (PreserveLCSSA = true). This causes an assert in simplifyLoop when (PreserveLCSSA = true), as during the last call LCSSA for the loop wasn't preserved, and thus crashes at the following assert. assert(L->isRecursivelyLCSSAForm(*DT, *LI) && "Requested to preserve LCSSA, but it's already broken."); Upon debugging, it is evident that simplifyLoopIVs call inside simplifyLoopAfterUnroll breaks the LCSSA form. This patch fixes llvm#77118, it checks if the replacement of IV Users with Loop Invariant preserves the LCSSA form. If it does not, it emits the required LCSSA Phi instructions. diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 66bba1ca2f1d..297cfe5124d8 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -25,6 +25,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/Local.h" +#include "llvm/Transforms/Utils/LoopUtils.h" #include "llvm/Transforms/Utils/ScalarEvolutionExpander.h" using namespace llvm; @@ -643,10 +644,21 @@ bool SimplifyIndvar::replaceIVUserWithLoopInvariant(Instruction *I) { } auto *Invariant = Rewriter.expandCodeFor(S, I->getType(), IP); + bool NeedToEmitLCSSAPhis = false; + if (!LI->replacementPreservesLCSSAForm(I, Invariant)) + NeedToEmitLCSSAPhis = true; I->replaceAllUsesWith(Invariant); LLVM_DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I << " with loop invariant: " << *S << '\n'); + + if (NeedToEmitLCSSAPhis) { + SmallVector<Instruction *, 1> NeedsLCSSAPhis; + NeedsLCSSAPhis.push_back(cast<Instruction>(Invariant)); + formLCSSAForInstructions(NeedsLCSSAPhis, *DT, *LI, SE); + LLVM_DEBUG(dbgs() << " INDVARS: Replacement breaks LCSSA form" + << " inserting LCSSA Phis" << '\n'); + } ++NumFoldedUser; Changed = true; DeadInsts.emplace_back(I);
[ { "file": "llvm/test/Transforms/LoopUnroll/gh-issue77118-broken-lcssa-form.ll", "commands": [ "opt -passes=loop-unroll -unroll-peel-count=2 -S -disable-output -debug-only=loop-unroll < %s 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": "; REQUIRES: asserts\n\ndefine void @test() {\nentry:\n br label %loop1\n\nloop1:\n %phi = phi i32 [ 1, %entry ], [ 0, %loop1.latch ]\n br label %loop2\n\nloop2:\n %phi3 = phi i64 [ 0, %loop1 ], [ %sext, %loop2.latch ]\n br label %loop3\n\nloop3:\n %phi5 = phi i64 [ %phi3, %loop2 ], [ %sext, %loop3.latch ]\n %phi6 = phi i32 [ 1, %loop2 ], [ %add10, %loop3.latch ]\n %trunc = trunc i64 %phi5 to i32\n br i1 true, label %loop3.latch, label %exit\n\nloop3.latch:\n %add = add i32 1, %phi\n %sext = sext i32 %add to i64\n %add10 = add i32 %phi6, 1\n %icmp = icmp ugt i32 %add10, 2\n br i1 %icmp, label %loop2.latch, label %loop3\n\nloop2.latch:\n br i1 false, label %loop4.preheader, label %loop2\n\nloop4.preheader:\n br label %loop4\n\nloop4:\n br i1 false, label %loop1.latch, label %loop4\n\nloop1.latch:\n br label %loop1\n\nexit:\n %phi8 = phi i32 [ %trunc, %loop3 ]\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `L->isRecursivelyLCSSAForm(*DT, *LI) && \"Requested to preserve LCSSA, but it's already broken.\"' failed.", "body": "Run opt with -passes=loop-unroll\r\n\r\nhttps://godbolt.org/z/GcEW4dhMh\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\" !prof !0 {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb12, %bb\r\n %phi = phi i32 [ 1, %bb ], [ 0, %bb12 ]\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb11, %bb1\r\n %phi3 = phi i64 [ 0, %bb1 ], [ %sext, %bb11 ]\r\n br label %bb4\r\n\r\nbb4: ; preds = %bb9, %bb2\r\n %phi5 = phi i64 [ %phi3, %bb2 ], [ %sext, %bb9 ]\r\n %phi6 = phi i32 [ 1, %bb2 ], [ %add10, %bb9 ]\r\n %trunc = trunc i64 %phi5 to i32\r\n br i1 true, label %bb9, label %bb7\r\n\r\nbb7: ; preds = %bb4\r\n %phi8 = phi i32 [ %trunc, %bb4 ]\r\n ret void\r\n\r\nbb9: ; preds = %bb4\r\n %add = add i32 1, %phi\r\n %sext = sext i32 %add to i64\r\n %add10 = add i32 %phi6, 1\r\n %icmp = icmp ugt i32 %add10, 2\r\n br i1 %icmp, label %bb11, label %bb4\r\n\r\nbb11: ; preds = %bb9\r\n br i1 false, label %bb12, label %bb2\r\n\r\nbb12: ; preds = %bb12, %bb11\r\n br i1 false, label %bb1, label %bb12, !prof !1\r\n}\r\n\r\n!0 = !{!\"function_entry_count\", i64 32768}\r\n!1 = !{!\"branch_weights\", i32 11, i32 1}\r\n```\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -S -passes=loop-unroll <source>\r\n #0 0x000000000359f928 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x359f928)\r\n #1 0x000000000359d07c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fe5f8e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007fe5f8e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007fe5f8e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007fe5f8e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007fe5f8e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007fe5f8e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000036a9544 llvm::simplifyLoop(llvm::Loop*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::ScalarEvolution*, llvm::AssumptionCache*, llvm::MemorySSAUpdater*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x36a9544)\r\n #9 0x000000000369b9d6 llvm::peelLoop(llvm::Loop*, unsigned int, 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+0x369b9d6)\r\n#10 0x00000000033f771b 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>) LoopUnrollPass.cpp:0:0\r\n#11 0x00000000033fa420 llvm::LoopUnrollPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x33fa420)\r\n#12 0x00000000037a6b8e llvm::detail::PassModel<llvm::Function, llvm::LoopUnrollPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x37a6b8e)\r\n#13 0x0000000000d8693d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xd8693d)\r\n#14 0x0000000002f3dfee llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f3dfee)\r\n#15 0x0000000000d6ac7e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xd6ac7e)\r\n#16 0x0000000002f3bf9c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f3bf9c)\r\n#17 0x0000000000895e8a 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+0x895e8a)\r\n#18 0x000000000079c6d3 main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x79c6d3)\r\n#19 0x00007fe5f8e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x00007fe5f8e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x000000000088b0de _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x88b0de)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "loopoptim", "crash" ], "comments": [ { "author": "vedantparanjape-amd", "body": "I looked at this, it seems peelLoop call destroys the LCSSA form, and after that calls simplifyLoop with PreserveLCSSA = true. I did the following change to confirm it.\r\n\r\n```c\r\ndiff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp\r\nindex 7cfeb019af97..be73d58796be 100644\r\n--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp\r\n+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp\r\n@@ -1270,6 +1270,7 @@ tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,\r\n });\r\n\r\n ValueToValueMapTy VMap;\r\n+ dbgs() << \"is lcssa form (before peel): \" << L->isRecursivelyLCSSAForm(DT, *LI) << \"\\n\";\r\n if (peelLoop(L, PP.PeelCount, LI, &SE, DT, &AC, PreserveLCSSA, VMap)) {\r\n simplifyLoopAfterUnroll(L, true, LI, &SE, &DT, &AC, &TTI);\r\n // If the loop was peeled, we already \"used up\" the profile information\r\ndiff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp\r\nindex f76fa3bb6c61..47775ef70dc0 100644\r\n--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp\r\n+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp\r\n@@ -1054,6 +1054,7 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,\r\n assert(DT.verify(DominatorTree::VerificationLevel::Fast));\r\n #endif\r\n\r\n+ dbgs() << \"is lcssa form (after peel): \" << L->isRecursivelyLCSSAForm(DT, *LI) << \"\\n\";\r\n // FIXME: Incrementally update loop-simplify\r\n simplifyLoop(L, &DT, LI, SE, AC, nullptr, PreserveLCSSA);\r\n```\r\nThe output from it was as follows:\r\n```bash\r\nis lcssa form (before peel): 1\r\nis lcssa form (after peel): 0\r\n```\r\nAs for the fix, adding a simple check for LCSSA and if it's not in form, forming it helped solve this bug. Does this look like a correct fix ?\r\n\r\n```c\r\ndiff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp\r\nindex f76fa3bb6c61..3e0545656d49 100644\r\n--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp\r\n+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp\r\n@@ -1054,6 +1054,8 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,\r\n assert(DT.verify(DominatorTree::VerificationLevel::Fast));\r\n #endif\r\n\r\n+ if (PreserveLCSSA && !L->isRecursivelyLCSSAForm(DT, *LI))\r\n+ formLCSSARecursively(*L, DT, LI, SE);\r\n // FIXME: Incrementally update loop-simplify\r\n simplifyLoop(L, &DT, LI, SE, AC, nullptr, PreserveLCSSA);\r\n```\r\nCC: @fhahn / @nikic " }, { "author": "vedantparanjape-amd", "body": "@TatyanaDoubts thanks for the report, it is now fixed." } ] }
true
null
115465
https://github.com/llvm/llvm-project/issues/115465
miscompilation
d822c099eeacc69f6bf834a6373a41d0c9f84a3e
2024-11-08T11:25:34
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "27bf45aa36386136db179c494358670a994a98a5", "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": [ [ 2904, 2910 ] ], "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 27bf45aa36386136db179c494358670a994a98a5 Author: Yingwei Zheng <[email protected]> Date: Sun Nov 10 17:07:25 2024 +0800 [InstCombine] Fix poison safety of folding shufflevector into select (#115483) We are allowed to fold shufflevector into select iff the condition is guaranteed not to be poison or the RHS is a poison. Alive2: https://alive2.llvm.org/ce/z/28zEWR Closes https://github.com/llvm/llvm-project/issues/115465. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 454fe5a91d37..ede89b099e8d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -2904,7 +2904,9 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) { if (auto *SI = dyn_cast<SelectInst>(LHS)) { // We cannot do this fold for elementwise select since ShuffleVector is // not elementwise. - if (SI->getCondition()->getType()->isIntegerTy()) { + if (SI->getCondition()->getType()->isIntegerTy() && + (isa<PoisonValue>(RHS) || + isGuaranteedNotToBePoison(SI->getCondition()))) { if (Instruction *I = FoldOpIntoSelect(SVI, SI)) return I; }
[ { "file": "llvm/test/Transforms/InstCombine/vec_shuffle.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "shuf_cmp_may_be_poison", "test_body": "define <4 x i8> @shuf_cmp_may_be_poison(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {\n %sel = select i1 %cmp, <4 x i8> %y, <4 x i8> <i8 0, i8 poison, i8 0, i8 poison>\n %shuf = shufflevector <4 x i8> %sel, <4 x i8> <i8 poison, i8 1, i8 poison, i8 3>, <4 x i32> <i32 0, i32 5, i32 2, i32 7>\n ret <4 x i8> %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] folded select produces different result on a blended vector", "body": "Alive2 report: https://alive2.llvm.org/ce/z/73v-ug\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <4 x i8> @sel_shuf_commute3.2(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {\r\n#0:\r\n %blend = shufflevector <4 x i8> { 0, 0, 0, 0 }, <4 x i8> %y, 0, 5, 2, 3\r\n %r = select i1 %cmp, <4 x i8> %y, <4 x i8> %blend\r\n %#1 = select <4 x i1> { 0, 1, 0, 1 }, <4 x i8> { 0, 1, 2, 3 }, <4 x i8> %r\r\n ret <4 x i8> %#1\r\n}\r\n=>\r\ndefine <4 x i8> @sel_shuf_commute3.2(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {\r\n#0:\r\n %#1 = shufflevector <4 x i8> %y, <4 x i8> { poison, 1, poison, 3 }, 0, 5, 2, 7\r\n %#2 = select i1 %cmp, <4 x i8> %#1, <4 x i8> { 0, 1, 0, 3 }\r\n ret <4 x i8> %#2\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<4 x i8> %x = < poison, poison, poison, poison >\r\n<4 x i8> %y = < poison, poison, poison, poison >\r\ni1 %cmp = poison\r\n\r\nSource:\r\n<4 x i8> %blend = < #x00 (0), poison, #x00 (0), #x00 (0) >\r\n<4 x i8> %r = < poison, poison, poison, poison >\r\n<4 x i8> %#1 = < poison, #x01 (1), poison, #x03 (3) >\r\n\r\nTarget:\r\n<4 x i8> %#1 = < poison, #x01 (1), poison, #x03 (3) >\r\n<4 x i8> %#2 = < poison, poison, poison, poison >\r\nSource value: < poison, #x01 (1), poison, #x03 (3) >\r\nTarget value: < poison, poison, 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", "author": "bongjunj", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
110295
https://github.com/llvm/llvm-project/issues/110295
crash
51e0a997ca607f64beafb838ba1325f0465eecd4
2024-09-27T16:39:37
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2c8836c899015cce49a399a6bc47b260a24a22e7", "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": [ [ 6539, 6546 ] ], "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 2c8836c899015cce49a399a6bc47b260a24a22e7 Author: Florian Hahn <[email protected]> Date: Sun Sep 29 20:31:23 2024 +0100 [LV] Don't consider predicated insts as invariant unconditionally in CM. Predicated instructions cannot hoisted trivially, so don't treat them as uniform value in the cost model. This fixes a difference between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/110295. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index cb346be8ffe5..792e0e17dd87 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6539,8 +6539,16 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, Op2 = cast<SCEVConstant>(PSE.getSCEV(Op2))->getValue(); } auto Op2Info = TTI.getOperandInfo(Op2); - if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue && - Legal->isInvariant(Op2)) + auto IsInvariant = [this](Value *Op) { + if (!Legal->isInvariant(Op)) + return false; + // Consider Op2 invariant, if it is not a predicated instruction in the + // loop. In that case, it is not trivially hoistable. + return !isa<Instruction>(Op) || + !TheLoop->contains(cast<Instruction>(Op)) || + !isPredicatedInst(cast<Instruction>(Op)); + }; + if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue && IsInvariant(Op2)) Op2Info.Kind = TargetTransformInfo::OK_UniformValue; SmallVector<const Value *, 4> Operands(I->operand_values());
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/predicated-instruction-cost.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "predicated_urem_shl_cost", "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 @predicated_urem_shl_cost(ptr %A, i32 %x, i1 %c) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]\n %gep = getelementptr inbounds i32, ptr %A, i32 %iv\n %l = load i32, ptr %gep, align 4\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %rem = urem i32 2, %x\n %shl = shl i32 %l, %rem\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i32 [ 0, %loop.header ], [ %shl, %then ]\n store i32 %p, ptr %gep, align 4\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 0\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes at -O{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": "Compiler Explorer: https://godbolt.org/z/YhKsza3dx\r\n\r\nRelated to https://github.com/llvm/llvm-project/issues/108697, but it doesn't seem to trigger anymore with the latest build.\r\n\r\n```\r\n[519] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 631bcbe9de13e160d427ad7452a7ef2ca67911ab)\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[520] % \r\n[520] % clangtk -O2 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7380: 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.\tProgram arguments: /local/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/20240927-clangtk-m64-O3-build-064435/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240927-clangtk-m64-O3-build-064435/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/20/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 -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-c6819e.o -x c small.c\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\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\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x0000560d31f97bef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x43b3bef)\r\n #1 0x0000560d31f953c4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f3f4386e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f3f432a500b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f3f43284859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f3f43284729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f3f43284729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f3f43295fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000560d3393ac39 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d56c39)\r\n #9 0x0000560d3395443b llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d7043b)\r\n#10 0x0000560d33957301 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d73301)\r\n#11 0x0000560d33957973 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5d73973)\r\n#12 0x0000560d334c3406 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x58df406)\r\n#13 0x0000560d31924a81 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d40a81)\r\n#14 0x0000560d2f43df76 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-20+0x1859f76)\r\n#15 0x0000560d319233ed llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d3f3ed)\r\n#16 0x0000560d2f43cb56 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-20+0x1858b56)\r\n#17 0x0000560d31922e21 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d3ee21)\r\n#18 0x0000560d322504b3 (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 0x0000560d32253a88 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/suz-local/software/local/clang-trunk/bin/clang-20+0x466fa88)\r\n#20 0x0000560d3293154c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4d4d54c)\r\n#21 0x0000560d347d56cc clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6bf16cc)\r\n#22 0x0000560d32931968 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4d4d968)\r\n#23 0x0000560d32bf9249 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5015249)\r\n#24 0x0000560d32b752fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4f912fe)\r\n#25 0x0000560d32ce5926 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5101926)\r\n#26 0x0000560d2f004695 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1420695)\r\n#27 0x0000560d2effc1aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x0000560d2f000bde clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x141cbde)\r\n#29 0x0000560d2eeed47b main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x130947b)\r\n#30 0x00007f3f43286083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x0000560d2effbc3e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1417c3e)\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 631bcbe9de13e160d427ad7452a7ef2ca67911ab)\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\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-49ab95.c\r\nclangtk: note: diagnostic msg: /tmp/small-49ab95.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[521] % \r\n[521] % cat small.c\r\nint a, b, c, e, f, i, g, h, k, l, m;\r\nunsigned d;\r\nvolatile int j;\r\nint n(short o) { return o ? a % o : 0; }\r\nint main() {\r\n short q;\r\n if (h)\r\n while (1)\r\n ;\r\nr:\r\n e && j;\r\n if (a && j)\r\n goto r;\r\ns:\r\n while (g)\r\n if (l)\r\n goto s;\r\n for (; i; i++) {\r\n f = !d ? : 2 % d;\r\n q = f > 1 ? 0 : c << f;\r\n m = q;\r\n b = n(k ^ q);\r\n }\r\n return 0;\r\n}\r\n```\r\n", "author": "zhendongsu", "labels": [ "regression", "vectorizers", "confirmed", "crash" ], "comments": [ { "author": "shafik", "body": "This looks like a regression in trunk: https://godbolt.org/z/c5Wxf5Teh\r\n\r\nI know godbolt does not have clang assertions build beyond trunk but you can use clang++ and just use `-x c` to check out if the assert exists in previous versions.\r\n\r\nCC @fhahn " }, { "author": "zhendongsu", "body": "> I know godbolt does not have clang assertions build beyond trunk but you can use clang++ and just use `-x c` to check out if the assert exists in previous versions.\r\n\r\n@shafik: Thanks for the tip!\r\n\r\n" } ] }
true
null
118467
https://github.com/llvm/llvm-project/issues/118467
miscompilation
73731d6873b6fb0757c3065aaf2452eaccd0eebc
2024-12-03T10:44:21
[ "llvm/test/Transforms/AggressiveInstCombine" ]
{ "fix_commit": "f68b0e36997322eeda8fd199ea80deb1b49c5410", "components": [ "AggressiveInstCombine" ], "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": 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": [ [ 803, 810 ] ], "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": 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": [ "foldConsecutiveLoads" ], "llvm/lib/Analysis/VectorUtils.cpp": null } }
commit f68b0e36997322eeda8fd199ea80deb1b49c5410 Author: Antonio Frighetto <[email protected]> Date: Wed Dec 4 10:15:11 2024 +0100 [AggressiveInstCombine] Use APInt and avoid truncation when folding loads A miscompilation issue has been addressed with improved handling. Fixes: https://github.com/llvm/llvm-project/issues/118467. diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp index b5b561797f75..45ee2d472a11 100644 --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -803,8 +803,7 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL, APInt Offset1(DL.getIndexTypeSizeInBits(Load1Ptr->getType()), 0); Load1Ptr = Load1Ptr->stripAndAccumulateConstantOffsets( DL, Offset1, /* AllowNonInbounds */ true); - Load1Ptr = Builder.CreatePtrAdd(Load1Ptr, - Builder.getInt32(Offset1.getZExtValue())); + Load1Ptr = Builder.CreatePtrAdd(Load1Ptr, Builder.getInt(Offset1)); } // Generate wider load. NewLoad = Builder.CreateAlignedLoad(WiderType, Load1Ptr, LI1->getAlign(),
[ { "file": "llvm/test/Transforms/AggressiveInstCombine/X86/or-load.ll", "commands": [ "opt < %s -passes=aggressive-instcombine -mtriple x86_64-none-eabi -mattr=avx2 -data-layout=\"e-n64\" -S", "opt < %s -passes=aggressive-instcombine -mtriple x86_64-none-eabi -mattr=avx2 -data-layout=\"E-n64\" -S" ], "tests": [ { "test_name": "loadcombine_consecutive_idx_64", "test_body": "define i32 @loadcombine_consecutive_idx_64(ptr %data) {\nentry:\n %arrayidx = getelementptr inbounds nuw i8, ptr %data, i64 2149675577\n %val = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %val to i32\n %arrayidx.2 = getelementptr inbounds nuw i8, ptr %data, i64 2149675576\n %val.2 = load i8, ptr %arrayidx.2, align 1\n %conv.2 = zext i8 %val.2 to i32\n %shl = shl nuw nsw i32 %conv, 8\n %or = or disjoint i32 %shl, %conv.2\n ret i32 %or\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Invalid LLVM IR code generated on x86-64 with a very simple sample (crash the generated executable code)", "body": "Below is a very simple program that's loading 16 bits table value into a 32 bits variable from a 8 bits table.\nOn **x86-64** with **-O2** or **-O3** flags, this program works fine with LLVM 16.0.0 and below, but since LLVM 17.0.0, the LLVM IR and the generated assembly code are using a wrong calculated offset on the table (doesn't occurs on LLVM armv8 whatever the version).\nAs you can see below, the offset in the table which is supposed to be **2149675576** (**0x80217238**) has its 32 upper bits inverted for **-2145291720** (**0xFFFFFFFF80217238**).\n\n```c\n\n#include <stdint.h>\n\n// Load 16 bits into 32 bits value from data offset 0x80217238\n\nuint32_t Test(const uint8_t* data)\n{ \n uint32_t a, b, c; \n\tb = 0xFFFF8022 << 16;\n b += 0xFFFFE808; \n a = data[b + 0xFFFF8A31];\n c = data[b + 0xFFFF8A30];\n c &= ~0x0000FF00;\n c |= ((a << 8) | (a >> 24)) & 0x0000FF00;\n\treturn c;\n}\n\n```\n\nLLVM IR with LLVM 16.0.0 (from Compiler Explorer)\n```ll\ndefine dso_local noundef i32 @Test(unsigned char const*)(ptr nocapture noundef readonly %data) local_unnamed_addr {\nentry:\n %arrayidx4 = getelementptr inbounds i8, ptr %data, i64 2149675576\n %0 = load i16, ptr %arrayidx4, align 1\n %1 = zext i16 %0 to i32\n ret i32 %1\n}\n\ndeclare void @llvm.dbg.value(metadata, metadata, metadata) #1\n```\nLLVM IR with LLVM 19.1.0 and trunk (from Compiler Explorer)\n```ll\ndefine dso_local noundef range(i32 0, 65536) i32 @Test(unsigned char const*)(ptr nocapture noundef readonly %data) local_unnamed_addr {\nentry:\n %0 = getelementptr i8, ptr %data, i64 -2145291720\n %1 = load i16, ptr %0, align 1\n %2 = zext i16 %1 to i32\n ret i32 %2\n}\n```\n\n\n\n\n\n", "author": "dje64240", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "topperc", "body": "opt-bisect suggests AggressiveInstCominer. There were two separate loads that got merged. The resulting GEP had an index of `i32 -2145291720` with trunk and `i64 2149675576` with clang 16. Those would be the same number if GEP zero extended indices instead of sign extending." }, { "author": "antoniofrighetto", "body": "Alive2: https://alive2.llvm.org/ce/z/G5CgkD." }, { "author": "AZero13", "body": "> opt-bisect suggests AggressiveInstCominer. There were two separate loads that got merged. The resulting GEP had an index of `i32 -2145291720` with trunk and `i64 2149675576` with clang 16. Those would be the same number if GEP zero extended indices instead of sign extending.\n\nSee my PR for 19.x " } ] }
true
null
131359
https://github.com/llvm/llvm-project/issues/131359
crash
e2c43ba981620cf71ce3ccf004db7c0db4caf8a7
2025-03-14T16:56:53
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "eef5ea0c42fc07ef2c948be59b57d0df8ec801ca", "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": [ [ 7467, 7472 ] ], "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": [ "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 eef5ea0c42fc07ef2c948be59b57d0df8ec801ca Author: Luke Lau <[email protected]> Date: Tue Mar 18 01:00:54 2025 +0900 [VPlan] Account for dead FOR splice simplification in cost model (#131486) Fixes #131359 After #129645, a first-order recurrence will no longer have it's splice costed if the VPInstruction::FirstOrderRecurrenceSplice has no users and is dead. The legacy cost model didn't account for this, so this accounts for it in planContainsAdditionalSimplifications to avoid the "VPlan cost model and legacy cost model disagreed" assertion. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b26b36f91a39..0e38ccc565ea 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7467,6 +7467,16 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan, } continue; } + // Unused FOR splices are removed by VPlan transforms, so the VPlan-based + // cost model won't cost it whilst the legacy will. + if (auto *FOR = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(&R)) { + if (none_of(FOR->users(), [](VPUser *U) { + auto *VPI = dyn_cast<VPInstruction>(U); + return VPI && VPI->getOpcode() == + VPInstruction::FirstOrderRecurrenceSplice; + })) + return true; + } // The VPlan-based cost model is more accurate for partial reduction and // comparing against the legacy cost isn't desirable. if (isa<VPPartialReductionRecipe>(&R))
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/pr131359-dead-for-splice.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; If a FOR isn't used the VPInstruction::FirstOrderRecurrenceSplice will be dead\n; and won't be costed in the VPlan cost model. Make sure we account for this\n; simplifcation in comparison to the legacy cost model.\n\ntarget triple = \"x86_64\"\n\ndefine void @no_use() {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i32 [ 0, %entry ], [ %iv, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i32 %iv, 1\n %exitcond.not.i = icmp eq i32 %iv, 43\n br i1 %exitcond.not.i, label %exit, label %loop\n\nexit:\n ret void\n}\n\ndefine void @dead_use() {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i32 [ 0, %entry ], [ %iv, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %dead = add i32 %for, 1\n %iv.next = add i32 %iv, 1\n %exitcond.not.i = icmp eq i32 %iv, 43\n br i1 %exitcond.not.i, label %exit, label %loop\n\nexit:\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes at -Os on x86_64-linux-gnu: Assertion `... \" VPlan cost model and legacy cost model disagreed\"' failed", "body": "It appears to be a regression from 19.1.0 and affects 20.1.0 and later. \n\nCompiler Explorer: https://godbolt.org/z/K3Y3zn4hP\n\n```\n[515] % 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[516] % \n[516] % clangtk -Os small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7574: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || PlanForEarlyExitLoop || 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, 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/20250313-clangtk-m64-Os-build-082148/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250313-clangtk-m64-Os-build-082148/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-d02bf4.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 \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\n #0 0x0000563ced471fcf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4577fcf)\n #1 0x0000563ced46f7a4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007f1c5b61c420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007f1c5b05300b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007f1c5b032859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007f1c5b032729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007f1c5b032729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007f1c5b043fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x0000563ceeecce93 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5fd2e93)\n #9 0x0000563ceeee48a6 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5fea8a6)\n#10 0x0000563ceeee72a1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5fed2a1)\n#11 0x0000563ceeee7943 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5fed943)\n#12 0x0000563ceea5a6d6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5b606d6)\n#13 0x0000563cecde27c9 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#14 0x0000563cea6cc7a6 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#15 0x0000563cecde1032 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ee7032)\n#16 0x0000563cea6ca3b6 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#17 0x0000563cecde0a51 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#18 0x0000563ced72fe4a (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#19 0x0000563ced7338a1 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#20 0x0000563cede73d91 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f79d91)\n#21 0x0000563cef8016dc clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x69076dc)\n#22 0x0000563cede741b8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f7a1b8)\n#23 0x0000563cee14abc9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5250bc9)\n#24 0x0000563cee0cbece clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51d1ece)\n#25 0x0000563cee23f996 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5345996)\n#26 0x0000563cea25f9ed cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x13659ed)\n#27 0x0000563cea25715a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#28 0x0000563cea25b3c7 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x13613c7)\n#29 0x0000563cea1400db main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x12460db)\n#30 0x00007f1c5b034083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#31 0x0000563cea256bee _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-7bdf6a.c\nclangtk: note: diagnostic msg: /tmp/small-7bdf6a.sh\nclangtk: note: diagnostic msg: \n\n********************\n[517] % \n[517] % cat small.c\nint printf(const char *, ...);\nint a, c, d, e;\nstatic int b = 2;\nstatic void f() {\n printf(\"0\\n\");\n for (c = 0; c < 3; c++)\n if (d && c >= b && e)\n a = 0;\n}\nint main() {\n b = 0;\n f();\n return 0;\n}\n```\n\n", "author": "zhendongsu", "labels": [ "vectorizers", "crash", "regression:20" ], "comments": [ { "author": "cardigan1008", "body": "Here is another case that triggers the same crash at `-O2`:\n\n```c\nint a, b;\nchar c;\nvoid f(int g) {\n int d;\n for (int e = 0; e < g; e++)\n d = e;\n a = d;\n}\nvoid h() {\n if (c)\n b = 0;\n else\n b = 1;\n f(b + 42);\n}\nvoid main() {}\n```\n\nCompiler Explorer: https://godbolt.org/z/zY6GT5eox\n\nBisected to https://github.com/llvm/llvm-project/commit/26324bc1bf397453ce966f56a88245263f7beec5, which was committed by @lukel97 " }, { "author": "lukel97", "body": "Hi @zhendongsu @cardigan1008, thanks for reporting/reducing/bisecting this. Can you confirm that this is fixed now after [eef5ea0](https://github.com/llvm/llvm-project/commit/eef5ea0c42fc07ef2c948be59b57d0df8ec801ca)?" }, { "author": "cardigan1008", "body": "Hi @lukel97 my case has been fixed. But the first case seems to still trigger the same crash at `-Os`.\n\nMy clang version: clang version 21.0.0git (https://github.com/llvm/llvm-project.git b3c5031b07396959c5d4e7f62d516d63de015358)" }, { "author": "lukel97", "body": "@cardigan1008 Looks like that's a separate vplan-legacy cost model mismatch, it seems to be reproducible before 26324bc1bf397453ce966f56a88245263f7beec5. I'll leave this issue open" } ] }
true
null
109510
https://github.com/llvm/llvm-project/issues/109510
crash
eb6e7e8f89a3d5c1cbc9856774ca00208753fb12
2024-09-21T04:01:16
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "bd8fe9972e3f17776e4e05e69e13ab8271d34132", "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": [ [ 1158, 1164 ], [ 1166, 1171 ] ], "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": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::optimize" ], "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 bd8fe9972e3f17776e4e05e69e13ab8271d34132 Author: Florian Hahn <[email protected]> Date: Sat Sep 21 12:45:36 2024 +0100 [VPlan] Mov licm to end of VPlan optimizations. This moves licm after expanding replicate regions. This fixes a crash when trying to hoist a predicated VPReplicateRecipes which later get expanded to replicate regions. Hoisting replicate regions out was not intended (see the discussion and at the review and comment on shallow traversal in licm()). Fixes https://github.com/llvm/llvm-project/issues/109510. diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 06ac15f52fe1..fd6090affbbf 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1158,7 +1158,6 @@ void VPlanTransforms::optimize(VPlan &Plan) { removeRedundantInductionCasts(Plan); simplifyRecipes(Plan); - licm(Plan); legalizeAndOptimizeInductions(Plan); removeDeadRecipes(Plan); @@ -1166,6 +1165,7 @@ void VPlanTransforms::optimize(VPlan &Plan) { removeRedundantExpandSCEVRecipes(Plan); mergeBlocksIntoPredecessors(Plan); + licm(Plan); } // Add a VPActiveLaneMaskPHIRecipe and related recipes to \p Plan and replace
[ { "file": "llvm/test/Transforms/LoopVectorize/invariant-replicate-region.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "test_invariant_replicate_region", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128-Fn32\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\ndefine i32 @test_invariant_replicate_region(i32 %x, i1 %c) {\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.latch\n\nthen: ; preds = %loop.header\n %rem.1 = urem i32 10, %x\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %res = phi i32 [ 0, %loop.header ], [ %rem.1, %then ]\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 99\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "A/F: verifyVPlanIsValid(*Plan) && \"VPlan is invalid\" after a861ed411a", "body": "We have an internal test that recently started to hit an assertion failure which I bisected back to commit a861ed411a359b7cb2b58d642e4a7f2fdcf92057. \r\n\r\nConsider the following code:\r\n```c\r\nint g_78, g_659, func_32_l_1852;\r\nlong g_128;\r\nunsigned func_32_p_33;\r\nvoid func_32() {\r\n int *l_1145 = &g_659;\r\n *l_1145 = 0;\r\n short __trans_tmp_11;\r\n for (; g_78; g_78 += 1) {\r\n func_32_l_1852 = 0;\r\n for (; func_32_l_1852 <= 3; func_32_l_1852 += 1) {\r\n int *l_1863 = &g_659;\r\n __trans_tmp_11 = *l_1863;\r\n if (10 % ((__trans_tmp_11 >= 0) - func_32_p_33))\r\n break;\r\n ++g_128;\r\n *l_1863 = func_32_p_33 <= --g_128;\r\n }\r\n }\r\n}\r\n```\r\n\r\nIf compiled with optimizations and a compiler built from a861ed411a359b7cb2b58d642e4a7f2fdcf92057 you can see it hits an assertion failure:\r\n```\r\n$ ~/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang -c -O2 repro.c\r\nVPIRBasicBlock can only be used as pre-header or a successor of middle-block at the moment!\r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8594: void llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount): Assertion `verifyVPlanIsValid(*Plan) && \"VPlan is invalid\"' 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: /home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang -c -O2 repro.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\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.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"func_32\"\r\n #0 0x00005572973a049f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x233549f)\r\n #1 0x000055729739dfec llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2332fec)\r\n #2 0x00005572972f0418 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f5d2a347420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #4 0x00007f5d29e1400b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #5 0x00007f5d29df3859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #6 0x00007f5d29df3729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #7 0x00007f5d29df3729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #8 0x00007f5d29e04fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #9 0x0000557298e08438 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3d9d438)\r\n#10 0x0000557298e0878f llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3d9d78f)\r\n#11 0x0000557298e0a62e llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3d9f62e)\r\n#12 0x0000557298e0d501 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3da2501)\r\n#13 0x0000557298e0db73 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3da2b73)\r\n#14 0x0000557298836146 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x37cb146)\r\n#15 0x0000557296e5bd41 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x1df0d41)\r\n#16 0x0000557295f84cc6 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/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xf19cc6)\r\n#17 0x0000557296e5a6ad llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x1def6ad)\r\n#18 0x0000557295f85686 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xf1a686)\r\n#19 0x0000557296e5a0e1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x1def0e1)\r\n#20 0x0000557297636863 (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#21 0x0000557297639dbd 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*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x25cedbd)\r\n#22 0x0000557297d17c5c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cacc5c)\r\n#23 0x0000557299c7aa8c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x4c0fa8c)\r\n#24 0x0000557297d18078 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cad078)\r\n#25 0x0000557297fdf129 clang::FrontendAction::Execute() (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2f74129)\r\n#26 0x0000557297f5b6fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2ef06fe)\r\n#27 0x00005572980cba26 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3060a26)\r\n#28 0x0000557295f09185 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xe9e185)\r\n#29 0x0000557295f00f0a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#30 0x0000557297d5e0cd 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#31 0x00005572972f0920 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2285920)\r\n#32 0x0000557297d5e6ef 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#33 0x0000557297d22274 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cb7274)\r\n#34 0x0000557297d2338d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cb838d)\r\n#35 0x0000557297d2b4a5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cc04a5)\r\n#36 0x0000557295f0611b clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xe9b11b)\r\n#37 0x0000557295e3609b main (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xdcb09b)\r\n#38 0x00007f5d29df5083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#39 0x0000557295f0099e _start (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xe9599e)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 20.0.0 (https://github.com/llvm/llvm-project.git a861ed411a359b7cb2b58d642e4a7f2fdcf92057)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin\r\nBuild config: +assertions\r\n```\r\n\r\nBuilding with a compiler built from the commit that immediately preceded this one (37e5319a12ba47c18049728804d3d1e1b10c4eb4), you can see that the compilation succeeds.\r\n```\r\n$ ~/src/upstream/37e5319a12ba47c18049728804d3d1e1b10c4eb4-linux/bin/clang -c -O2 repro.c\r\n$\r\n```", "author": "dyung", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
58e05779b483bb3d9f734bd09f5cb2241431a0b7
142518
https://github.com/llvm/llvm-project/issues/142518
miscompilation
9ba332f9963561bb5ac6933266afe38eb8fde8cd
2025-06-03T02:15:27
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "e2c698c7e836306f1a25c67597ae9e25a1fcc575", "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": [ [ 4513, 4518 ] ], "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::sinkNotIntoLogicalOp" ], "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 e2c698c7e836306f1a25c67597ae9e25a1fcc575 Author: Yingwei Zheng <[email protected]> Date: Wed Jun 4 17:48:01 2025 +0800 [InstCombine] Fix miscompilation in `sinkNotIntoLogicalOp` (#142727) Consider the following case: ``` define i1 @src(i8 %x) { %cmp = icmp slt i8 %x, -1 %not1 = xor i1 %cmp, true %or = or i1 %cmp, %not1 %not2 = xor i1 %or, true ret i1 %not2 } ``` `sinkNotIntoLogicalOp(%or)` calls `freelyInvert(%cmp, /*IgnoredUser=*/%or)` first. However, as `%cmp` is also used by `Op1 = %not1`, the RHS of `%or` is set to `%cmp.not = xor i1 %cmp, true`. Thus `Op1` is out of date in the second call to `freelyInvert`. Similarly, the second call may change `Op0`. According to the analysis above, I decided to avoid this fold when one of the operands is also a user of the other. Closes https://github.com/llvm/llvm-project/issues/142518. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 2fb4bfecda8a..c6c231f81c4a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -4513,6 +4513,12 @@ bool InstCombinerImpl::sinkNotIntoLogicalOp(Instruction &I) { if (Op0 == Op1) return false; + // If one of the operands is a user of the other, + // freelyInvert->freelyInvertAllUsersOf will change the operands of I, which + // may cause miscompilation. + if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0)))) + return false; + Instruction::BinaryOps NewOpc = match(&I, m_LogicalAnd()) ? Instruction::Or : Instruction::And; bool IsBinaryOp = isa<BinaryOperator>(I);
[ { "file": "llvm/test/Transforms/InstCombine/pr142518.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr142518", "test_body": "define i8 @pr142518(ptr %p, i8 %x, i1 %c) #0 {\nentry:\n %flag = alloca i8, align 1\n %cmp = icmp slt i8 %x, -1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i1 [ %cmp, %entry ], [ %c, %loop ]\n %not1 = xor i1 %phi, true\n %or = or i1 %cmp, %not1\n %not2 = xor i1 %or, true\n %ext2 = zext i1 %not2 to i8\n store i8 %ext2, ptr %p, align 1\n store i8 1, ptr %flag, align 1\n %flagv = load i8, ptr %flag, align 1\n %cond = icmp eq i8 %flagv, 0\n br i1 %cond, label %loop, label %exit\n\nexit: ; preds = %loop\n %not3 = xor i1 %or, true\n %ext3 = zext i1 %not3 to i8\n ret i8 %ext3\n}\n\nattributes #0 = { \"instcombine-no-verify-fixpoint\" }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "InstCombine 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\nI've tried to reduce the MIR, but I think there's a pretty complicated structure required because I can't get the MIR very small.\nhttps://godbolt.org/z/G6qsWP57T\n\nThe program seems to miscompile starting at `rustc -Zmir-opt-level=0 -Copt-level=1 -Cllvm-args=-opt-bisect-limit=159`", "author": "saethlin", "labels": [ "miscompilation", "llvm:instcombine", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/l2ArgJ\n\n> I've tried to reduce the MIR, but I think there's a pretty complicated structure required because I can't get the MIR very small.\n\nFYI you can use https://github.com/dtcxzyw/llvm-ub-aware-interpreter?tab=readme-ov-file#automatic-ub-free-test-case-reduction-for-middle-end-miscompilation-bugs to reduce csmith/rustlantics-generated miscompilation reproducers.\n" }, { "author": "saethlin", "body": "I'd love to use llubi but it doesn't compile against the tip of master or the llvm submodule in rust-lang/rust. So I'm not really sure how to get a working build on my system." }, { "author": "dtcxzyw", "body": "> I'd love to use llubi but it doesn't compile against the tip of master or the llvm submodule in rust-lang/rust. So I'm not really sure how to get a working build on my system.\n\nFixed. It was broken by recent changes to ValueTracking: https://github.com/llvm/llvm-project/pull/142384" } ] }
true
null
121110
https://github.com/llvm/llvm-project/issues/121110
miscompilation
f68dbbbd57dd0947730300d1e827ad16c2dfffb5
2024-12-25T13:57:11
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "f2f02b21cd581057e3c9b4a7a27e0014eeb9ba15", "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": [ [ 1669, 1675 ], [ 1677, 1684 ], [ 1727, 1740 ], [ 1750, 1759 ] ], "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::foldShuffleOfBinops" ], "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 f2f02b21cd581057e3c9b4a7a27e0014eeb9ba15 Author: Simon Pilgrim <[email protected]> Date: Sat Dec 28 09:21:22 2024 +0000 [VectorCombine] foldShuffleOfBinops - only accept exact matching cmp predicates m_SpecificCmp allowed equivalent predicate+flags which don't necessarily work after being folded from "shuffle (cmpop), (cmpop)" into "cmpop (shuffle), (shuffle)" Fixes #121110 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index ecbc13d489eb..2460ccc61d84 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1669,7 +1669,8 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { Value *X, *Y, *Z, *W; bool IsCommutative = false; - CmpPredicate Pred = CmpInst::BAD_ICMP_PREDICATE; + CmpPredicate PredLHS = CmpInst::BAD_ICMP_PREDICATE; + CmpPredicate PredRHS = CmpInst::BAD_ICMP_PREDICATE; if (match(LHS, m_BinOp(m_Value(X), m_Value(Y))) && match(RHS, m_BinOp(m_Value(Z), m_Value(W)))) { auto *BO = cast<BinaryOperator>(LHS); @@ -1677,8 +1678,9 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { if (llvm::is_contained(OldMask, PoisonMaskElem) && BO->isIntDivRem()) return false; IsCommutative = BinaryOperator::isCommutative(BO->getOpcode()); - } else if (match(LHS, m_Cmp(Pred, m_Value(X), m_Value(Y))) && - match(RHS, m_SpecificCmp(Pred, m_Value(Z), m_Value(W)))) { + } else if (match(LHS, m_Cmp(PredLHS, m_Value(X), m_Value(Y))) && + match(RHS, m_Cmp(PredRHS, m_Value(Z), m_Value(W))) && + (CmpInst::Predicate)PredLHS == (CmpInst::Predicate)PredRHS) { IsCommutative = cast<CmpInst>(LHS)->isCommutative(); } else return false; @@ -1727,14 +1729,14 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { TTI.getShuffleCost(SK0, BinOpTy, NewMask0, CostKind, 0, nullptr, {X, Z}) + TTI.getShuffleCost(SK1, BinOpTy, NewMask1, CostKind, 0, nullptr, {Y, W}); - if (Pred == CmpInst::BAD_ICMP_PREDICATE) { + if (PredLHS == CmpInst::BAD_ICMP_PREDICATE) { NewCost += TTI.getArithmeticInstrCost(LHS->getOpcode(), ShuffleDstTy, CostKind); } else { auto *ShuffleCmpTy = FixedVectorType::get(BinOpTy->getElementType(), ShuffleDstTy); NewCost += TTI.getCmpSelInstrCost(LHS->getOpcode(), ShuffleCmpTy, - ShuffleDstTy, Pred, CostKind); + ShuffleDstTy, PredLHS, CostKind); } LLVM_DEBUG(dbgs() << "Found a shuffle feeding two binops: " << I @@ -1750,10 +1752,10 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { Value *Shuf0 = Builder.CreateShuffleVector(X, Z, NewMask0); Value *Shuf1 = Builder.CreateShuffleVector(Y, W, NewMask1); - Value *NewBO = Pred == CmpInst::BAD_ICMP_PREDICATE + Value *NewBO = PredLHS == CmpInst::BAD_ICMP_PREDICATE ? Builder.CreateBinOp( cast<BinaryOperator>(LHS)->getOpcode(), Shuf0, Shuf1) - : Builder.CreateCmp(Pred, Shuf0, Shuf1); + : Builder.CreateCmp(PredLHS, Shuf0, Shuf1); // Intersect flags from the old binops. if (auto *NewInst = dyn_cast<Instruction>(NewBO)) {
[ { "file": "llvm/test/Transforms/VectorCombine/X86/shuffle-of-cmps.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=sse2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=sse4.2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=avx2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=avx512vl" ], "tests": [ { "test_name": "shuf_icmp_ugt_v4i32_use", "test_body": "declare void @use(<4 x i1>)\n\ndefine <4 x i32> @shuf_icmp_ugt_v4i32_use(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z, <4 x i32> %w) {\n %c0 = icmp ugt <4 x i32> %x, %y\n %c1 = icmp ugt <4 x i32> %z, %w\n call void @use(<4 x i1> %c0)\n %s = shufflevector <4 x i1> %c0, <4 x i1> %c1, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %r = sext <4 x i1> %s to <4 x i32>\n ret <4 x i32> %r\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "PR121110", "test_body": "define <2 x i1> @PR121110() {\n %ugt = icmp samesign ugt <2 x i32> zeroinitializer, zeroinitializer\n %sgt = icmp sgt <2 x i32> zeroinitializer, <i32 6, i32 -4>\n %res = shufflevector <2 x i1> %ugt, <2 x i1> %sgt, <2 x i32> <i32 0, i32 3>\n ret <2 x i1> %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Miscompilation at -Os", "body": "This code prints 9 at `-Os` and 0 at `-O0/1/2/3`:\n\n```c\nint printf(const char *, ...);\nchar a = 9, c, d;\nint b, e;\nunsigned short f;\nchar *g = &a;\nvoid h(int i) {\n for (; b; b++)\n c &= 0 <= i;\n}\nstatic short j(unsigned long i) {\n int k;\n for (; e + d + 4 > 0;) {\n k = i + 49;\n h(k + i - 52 + i);\n *g = 0;\n return 0;\n }\n return 0;\n}\nint main() {\n j(6 < (unsigned short)(f - 7) + f);\n printf(\"%d\\n\", a);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/Mo5TEKh8r\n\nBisected to https://github.com/llvm/llvm-project/commit/5287299f8809ae927a0acafb179c4b37ce9ff21d, which was committed by @RKSimon ", "author": "cardigan1008", "labels": [ "miscompilation", "vectorizers" ], "comments": [ { "author": "RKSimon", "body": "I'm not convinced the patch is responsible, it's more likely exposed something else. I'll take a look after the Christmas break." }, { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/jdkwFh\n```\n; bin/opt -passes=vector-combine test.ll -S\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine <2 x i1> @src() {\nentry:\n %0 = icmp samesign ugt <2 x i32> zeroinitializer, zeroinitializer\n %1 = icmp sgt <2 x i32> zeroinitializer, <i32 6, i32 -4>\n %2 = shufflevector <2 x i1> %0, <2 x i1> %1, <2 x i32> <i32 0, i32 3>\n ret <2 x i1> %2\n}\n```\n```\ndefine <2 x i1> @tgt() {\nentry:\n ret <2 x i1> zeroinitializer\n}\n```\n```\n\n----------------------------------------\ndefine <2 x i1> @src() {\nentry:\n %#0 = icmp samesign ugt <2 x i32> { 0, 0 }, { 0, 0 }\n %#1 = icmp sgt <2 x i32> { 0, 0 }, { 6, 4294967292 }\n %#2 = shufflevector <2 x i1> %#0, <2 x i1> %#1, 0, 3\n ret <2 x i1> %#2\n}\n=>\ndefine <2 x i1> @tgt() {\nentry:\n ret <2 x i1> { 0, 0 }\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\n\nSource:\n<2 x i1> %#0 = < #x0 (0), #x0 (0) >\n<2 x i1> %#1 = < #x0 (0), #x1 (1) >\n<2 x i1> %#2 = < #x0 (0), #x1 (1) >\n\nTarget:\nSource value: < #x0 (0), #x1 (1) >\nTarget value: < #x0 (0), #x0 (0) >\n```\n" } ] }
true
null
92887
https://github.com/llvm/llvm-project/issues/92887
miscompilation
f78b1a40864470f7eb30dfda44a6ea8e845346a5
2024-05-21T09:38:14
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "263224e4481b0850539a93a272184aac4abe86d4", "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": [ [ 2901, 2907 ] ], "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 263224e4481b0850539a93a272184aac4abe86d4 Author: Nikita Popov <[email protected]> Date: Tue May 21 14:57:19 2024 +0200 [InstCombine] Require poison operand in canEvaluateShuffled transform This transform works on single-source shuffles, which require that the second operand is poison, not undef. Otherwise we may convert undef to poison. Fixes https://github.com/llvm/llvm-project/issues/92887. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 99f1f8eb34bb..745ccbfe9dc7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -2901,7 +2901,7 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) { if (Instruction *I = foldIdentityPaddedShuffles(SVI)) return I; - if (match(RHS, m_Undef()) && canEvaluateShuffled(LHS, Mask)) { + if (match(RHS, m_Poison()) && canEvaluateShuffled(LHS, Mask)) { Value *V = evaluateInDifferentElementOrder(LHS, Mask, Builder); return replaceInstUsesWith(SVI, V); }
[ { "file": "llvm/test/Transforms/InstCombine/vec_shuffle.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "pr92887", "test_body": "define i16 @pr92887(<2 x i16> %v) {\n %v0 = extractelement <2 x i16> %v, i64 0\n %v0lo = and i16 %v0, 1\n %v1 = extractelement <2 x i16> %v, i64 1\n %v1lo = and i16 %v1, 1\n %ins1 = insertelement <4 x i16> poison, i16 %v0lo, i64 0\n %ins2 = insertelement <4 x i16> %ins1, i16 %v1lo, i64 1\n %shuf = shufflevector <4 x i16> %ins2, <4 x i16> <i16 poison, i16 poison, i16 undef, i16 undef>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>\n %extract = extractelement <4 x i16> %shuf, i32 2\n ret i16 %extract\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "blend_elements_from_load", "test_body": "define <4 x i16> @blend_elements_from_load(ptr align 8 %_0) {\n %load = load <3 x i16>, ptr %_0, align 8\n %rv = shufflevector <3 x i16> <i16 0, i16 undef, i16 undef>, <3 x i16> %load, <4 x i32> <i32 0, i32 1, i32 3, i32 5>\n ret <4 x i16> %rv\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Miscompile with opt -passes=\"instcombine\"", "body": "llvm commit: 502bea25bdc07d1\r\n\r\nReproduce with:\r\n```opt -passes=\"instcombine\" bbi-95633_2.ll -S -o -```\r\n\r\nResult:\r\n```\r\ndefine i16 @foo() {\r\nentry:\r\n store i16 0, ptr @bit, align 2\r\n store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 2), align 2\r\n store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 4), align 2\r\n store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 6), align 2\r\n store i16 2, ptr getelementptr inbounds (i8, ptr @bit, i64 8), align 2\r\n store i16 0, ptr getelementptr inbounds (i8, ptr @bit, i64 10), align 2\r\n ret i16 poison\r\n}\r\n```\r\nNote the poison return value which I think is wrong.\r\n\r\nBefore commit e93d324adb4ff8\r\n```\r\n[InstCombine] Preserve poison in evaluateInDifferentElementOrder()\r\n\r\nDon't unnecessarily replace poison with undef.\r\n```\r\nwe instead got\r\n```\r\ndefine i16 @foo() {\r\nentry:\r\n store i16 0, ptr @bit, align 2\r\n store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 1), align 2\r\n store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 2), align 2\r\n store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 3), align 2\r\n store i16 2, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 4), align 2\r\n store i16 0, ptr getelementptr inbounds (%struct.bit, ptr @bit, i64 0, i32 5), align 2\r\n ret i16 1\r\n}\r\n```\r\nwhere we return 1 instead of poison.\r\n\r\nI tried to use Alive2 on the input/output in\r\n https://alive2.llvm.org/ce/z/1GVkRh\r\nand it says\r\n```\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n```\r\n\r\n[bbi-95633_2.ll.gz](https://github.com/llvm/llvm-project/files/15387836/bbi-95633_2.ll.gz)\r\n", "author": "mikaelholmen", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "mikaelholmen", "body": "@nikic : Any idea about this?" }, { "author": "artagnon", "body": "Here's a reduced test case:\r\n\r\n```llvm\r\n; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5\r\n; RUN: opt -passes=instcombine -S %s | FileCheck %s\r\n\r\n%struct.widget = type { i16, i16, i16, i16, i16, i16 }\r\n\r\n; Miscompile. Correct output: 1, incorrect output: poison.\r\ndefine i16 @pr92887(ptr %p, i16 %x, i16 %y) {\r\n; CHECK-LABEL: define i16 @pr92887(\r\n; CHECK-SAME: ptr [[P:%.*]], i16 [[X:%.*]], i16 [[Y:%.*]]) {\r\n; CHECK-NEXT: store i16 0, ptr [[P]], align 2\r\n; CHECK-NEXT: [[P_REPACK1:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 2\r\n; CHECK-NEXT: store i16 0, ptr [[P_REPACK1]], align 2\r\n; CHECK-NEXT: [[P_REPACK2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 4\r\n; CHECK-NEXT: store i16 0, ptr [[P_REPACK2]], align 2\r\n; CHECK-NEXT: [[P_REPACK3:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 6\r\n; CHECK-NEXT: store i16 0, ptr [[P_REPACK3]], align 2\r\n; CHECK-NEXT: [[P_REPACK4:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 8\r\n; CHECK-NEXT: store i16 2, ptr [[P_REPACK4]], align 2\r\n; CHECK-NEXT: [[P_REPACK5:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 10\r\n; CHECK-NEXT: store i16 0, ptr [[P_REPACK5]], align 2\r\n; CHECK-NEXT: ret i16 poison\r\n;\r\n store %struct.widget { i16 0, i16 0, i16 0, i16 0, i16 2, i16 0 }, ptr %p\r\n %insert.y = insertelement <2 x i16> zeroinitializer, i16 %y, i64 0\r\n %insert.x = insertelement <2 x i16> %insert.y, i16 %x, i64 1\r\n %shufflevector = shufflevector <2 x i16> %insert.x, <2 x i16> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>\r\n %extract = extractelement <4 x i16> %shufflevector, i32 2 ; undef\r\n %and = and i16 %extract, 0 ; 0\r\n %gep = getelementptr %struct.widget, ptr %p, i32 0, i32 4\r\n %load = load i16, ptr %gep ; 2\r\n %or = or i16 %and, %load ; 2\r\n %ashr = ashr i16 %or, 1 ; 1\r\n ret i16 %ashr ; 1\r\n}\r\n```\r\n\r\nEDIT: Sorry, Alive2 verifies the transformation as correct." }, { "author": "nikic", "body": "The problematic transform is:\r\n```llvm\r\ndefine i16 @src(<2 x i16> %v) {\r\n %v0 = extractelement <2 x i16> %v, i64 0\r\n %v0lo = and i16 %v0, 1\r\n %v1 = extractelement <2 x i16> %v, i64 1\r\n %v1lo = and i16 %v1, 1\r\n %ins1 = insertelement <4 x i16> poison, i16 %v0lo, i64 0\r\n %ins2 = insertelement <4 x i16> %ins1, i16 %v1lo, i64 1\r\n %shuf = shufflevector <4 x i16> %ins2, <4 x i16> <i16 poison, i16 poison, i16 undef, i16 undef>, <4 x i32> <i32 0, i32 1, i32 6, i32 7>\r\n %extract = extractelement <4 x i16> %shuf, i32 2\r\n ret i16 %extract\r\n}\r\n```\r\nTo:\r\n```\r\ndefine i16 @src(<2 x i16> %v) {\r\n %v0 = extractelement <2 x i16> %v, i64 0\r\n %v0lo = and i16 %v0, 1\r\n %v1 = extractelement <2 x i16> %v, i64 1\r\n %v1lo = and i16 %v1, 1\r\n %1 = insertelement <4 x i16> poison, i16 %v0lo, i64 0\r\n %shuf = insertelement <4 x i16> %1, i16 %v1lo, i64 1\r\n %extract = extractelement <4 x i16> %shuf, i32 2\r\n ret i16 %extract\r\n}\r\n```\r\n\r\nAt a glance, the problem is likely that https://github.com/llvm/llvm-project/blob/e93d324adb4ff80dcbf0e5b678ed3342350eb2de/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp#L2881 should be matching m_Poison, not m_Undef, otherwise it's not a real single-source shuffle." }, { "author": "mikaelholmen", "body": "Thanks for the quick fix!\r\nI've verified that it solves the problem we saw." }, { "author": "nikic", "body": "As a bonus, fixed a similar miscompile in https://github.com/llvm/llvm-project/commit/ecd269e8305330c185bbedbd5a59e887122333ba." }, { "author": "nikic", "body": "Another one in https://github.com/llvm/llvm-project/commit/8f1c984325bd679b2634a6173db69548da87ac71." }, { "author": "nikic", "body": "And... one more in https://github.com/llvm/llvm-project/commit/d0e0205bfc5a147f8744a176a10f185af7520c26." }, { "author": "mikaelholmen", "body": "Nice, four fixes from just one issue! :)" } ] }
true
null
120076
https://github.com/llvm/llvm-project/issues/120076
miscompilation
2402bccc805614069efb0a47e1ef43349ea7ba1e
2024-12-16T13:09:17
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "d1a7225076218ce224cd29c74259b715b393dc9d", "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": [ [ 2931, 2943 ], [ 17515, 17522 ], [ 17528, 17533 ], [ 17623, 17630 ], [ 17926, 17931 ], [ 17949, 17954 ], [ 18071, 18078 ], [ 18206, 18212 ], [ 18214, 18219 ] ], "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", "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 d1a7225076218ce224cd29c74259b715b393dc9d Author: Alexey Bataev <[email protected]> Date: Mon Dec 16 07:52:32 2024 -0800 [SLP]Check if the node must keep its original bitwidth Need to check if during previous analysis the node has requested to keep its original bitwidth to avoid incorrect codegen. Fixes #120076 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 3bd983ee6e12..d967813075bb 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2931,13 +2931,11 @@ private: /// truncation. We collect the entries that will be demoted in ToDemote. /// \param E Node for analysis /// \param ToDemote indices of the nodes to be demoted. - bool collectValuesToDemote(const TreeEntry &E, bool IsProfitableToDemoteRoot, - unsigned &BitWidth, - SmallVectorImpl<unsigned> &ToDemote, - DenseSet<const TreeEntry *> &Visited, - unsigned &MaxDepthLevel, - bool &IsProfitableToDemote, - bool IsTruncRoot) const; + bool collectValuesToDemote( + const TreeEntry &E, bool IsProfitableToDemoteRoot, unsigned &BitWidth, + SmallVectorImpl<unsigned> &ToDemote, DenseSet<const TreeEntry *> &Visited, + const SmallDenseSet<unsigned, 8> &NodesToKeepBWs, unsigned &MaxDepthLevel, + bool &IsProfitableToDemote, bool IsTruncRoot) const; /// Check if the operands on the edges \p Edges of the \p UserTE allows /// reordering (i.e. the operands can be reordered because they have only one @@ -17515,8 +17513,8 @@ unsigned BoUpSLP::getVectorElementSize(Value *V) { bool BoUpSLP::collectValuesToDemote( const TreeEntry &E, bool IsProfitableToDemoteRoot, unsigned &BitWidth, SmallVectorImpl<unsigned> &ToDemote, DenseSet<const TreeEntry *> &Visited, - unsigned &MaxDepthLevel, bool &IsProfitableToDemote, - bool IsTruncRoot) const { + const SmallDenseSet<unsigned, 8> &NodesToKeepBWs, unsigned &MaxDepthLevel, + bool &IsProfitableToDemote, bool IsTruncRoot) const { // We can always demote constants. if (all_of(E.Scalars, IsaPred<Constant>)) return true; @@ -17528,6 +17526,10 @@ bool BoUpSLP::collectValuesToDemote( return true; } + // Check if the node was analyzed already and must keep its original bitwidth. + if (NodesToKeepBWs.contains(E.Idx)) + return false; + // If the value is not a vectorized instruction in the expression and not used // by the insertelement instruction and not used in multiple vector nodes, it // cannot be demoted. @@ -17623,8 +17625,8 @@ bool BoUpSLP::collectValuesToDemote( for (const TreeEntry *Op : Operands) { unsigned Level = InitLevel; if (!collectValuesToDemote(*Op, IsProfitableToDemoteRoot, BitWidth, - ToDemote, Visited, Level, IsProfitableToDemote, - IsTruncRoot)) { + ToDemote, Visited, NodesToKeepBWs, Level, + IsProfitableToDemote, IsTruncRoot)) { if (!IsProfitableToDemote) return false; NeedToExit = true; @@ -17926,6 +17928,7 @@ void BoUpSLP::computeMinimumValueSizes() { bool IsTruncRoot = false; bool IsProfitableToDemoteRoot = !IsStoreOrInsertElt; SmallVector<unsigned> RootDemotes; + SmallDenseSet<unsigned, 8> NodesToKeepBWs; if (NodeIdx != 0 && VectorizableTree[NodeIdx]->State == TreeEntry::Vectorize && VectorizableTree[NodeIdx]->getOpcode() == Instruction::Trunc) { @@ -17949,6 +17952,7 @@ void BoUpSLP::computeMinimumValueSizes() { // Check if the root is trunc and the next node is gather/buildvector, then // keep trunc in scalars, which is free in most cases. if (E.isGather() && IsTruncRoot && E.UserTreeIndices.size() == 1 && + !NodesToKeepBWs.contains(E.Idx) && E.Idx > (IsStoreOrInsertElt ? 2u : 1u) && all_of(E.Scalars, [&](Value *V) { return V->hasOneUse() || isa<Constant>(V) || @@ -18071,8 +18075,8 @@ void BoUpSLP::computeMinimumValueSizes() { bool NeedToDemote = IsProfitableToDemote; if (!collectValuesToDemote(E, IsProfitableToDemoteRoot, MaxBitWidth, - ToDemote, Visited, MaxDepthLevel, NeedToDemote, - IsTruncRoot) || + ToDemote, Visited, NodesToKeepBWs, MaxDepthLevel, + NeedToDemote, IsTruncRoot) || (MaxDepthLevel <= Limit && !(((Opcode == Instruction::SExt || Opcode == Instruction::ZExt) && (!IsTopRoot || !(IsStoreOrInsertElt || UserIgnoreList) || @@ -18206,7 +18210,7 @@ void BoUpSLP::computeMinimumValueSizes() { }); } - // If the maximum bit width we compute is less than the with of the roots' + // If the maximum bit width we compute is less than the width of the roots' // type, we can proceed with the narrowing. Otherwise, do nothing. if (MaxBitWidth == 0 || MaxBitWidth >= @@ -18214,6 +18218,7 @@ void BoUpSLP::computeMinimumValueSizes() { ->getBitWidth()) { if (UserIgnoreList) AnalyzedMinBWVals.insert(TreeRoot.begin(), TreeRoot.end()); + NodesToKeepBWs.insert(ToDemote.begin(), ToDemote.end()); continue; }
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/minbw-node-used-twice.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux < %s" ], "tests": [ { "test_name": "test", "test_body": "define i8 @test() {\nentry:\n %conv4.i.i = zext i16 0 to i32\n %conv7.i.i = sext i16 0 to i32\n %cmp8.i.i = icmp slt i32 %conv7.i.i, %conv4.i.i\n %conv9.i.i = zext i1 %cmp8.i.i to i32\n %or10.i.i = or i32 %conv9.i.i, %conv4.i.i\n %cmp11.i.i = icmp eq i32 %or10.i.i, %conv4.i.i\n %sub.i.i79.peel.i = sub i16 0, 1\n %xor5.i81.peel.i = zext i16 %sub.i.i79.peel.i to i32\n %conv7.i84.peel.i = sext i16 0 to i32\n %cmp8.i85.peel.i = icmp slt i32 %conv7.i84.peel.i, %xor5.i81.peel.i\n %conv9.i86.peel.i = zext i1 %cmp8.i85.peel.i to i32\n %or10.i87.peel.i = or i32 %conv9.i86.peel.i, %xor5.i81.peel.i\n %cmp11.i88.peel.i = icmp eq i32 %or10.i87.peel.i, %xor5.i81.peel.i\n %conv13.i89.peel.i = zext i1 %cmp8.i85.peel.i to i8\n ret i8 %conv13.i89.peel.i\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Miscompile at O3", "body": "Reproducer: https://alive2.llvm.org/ce/z/_88AAB\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 i8 @func_129() {\nentry:\n %conv4.i.i = zext i16 0 to i32\n %conv7.i.i = sext i16 0 to i32\n %cmp8.i.i = icmp slt i32 %conv7.i.i, %conv4.i.i\n %conv9.i.i = zext i1 %cmp8.i.i to i32\n %or10.i.i = or i32 %conv9.i.i, %conv4.i.i\n %cmp11.i.i = icmp eq i32 %or10.i.i, %conv4.i.i\n %sub.i.i79.peel.i = sub i16 0, 1\n %xor5.i81.peel.i = zext i16 %sub.i.i79.peel.i to i32\n %conv7.i84.peel.i = sext i16 0 to i32\n %cmp8.i85.peel.i = icmp slt i32 %conv7.i84.peel.i, %xor5.i81.peel.i\n %conv9.i86.peel.i = zext i1 %cmp8.i85.peel.i to i32\n %or10.i87.peel.i = or i32 %conv9.i86.peel.i, %xor5.i81.peel.i\n %cmp11.i88.peel.i = icmp eq i32 %or10.i87.peel.i, %xor5.i81.peel.i\n %conv13.i89.peel.i = zext i1 %cmp8.i85.peel.i to i8\n ret i8 %conv13.i89.peel.i\n}\n```\n```\ndefine i8 @func_129() {\nentry:\n %sub.i.i79.peel.i = sub i16 0, 1\n %0 = insertelement <2 x i16> <i16 poison, i16 0>, i16 %sub.i.i79.peel.i, i32 0\n %1 = icmp slt <2 x i16> zeroinitializer, %0\n %2 = zext <2 x i1> %1 to <2 x i16>\n %3 = or <2 x i16> %2, %0\n %4 = icmp eq <2 x i16> %3, %0\n %5 = extractelement <2 x i1> %1, i32 0\n %conv13.i89.peel.i = zext i1 %5 to i8\n ret i8 %conv13.i89.peel.i\n}\n```\n```\n----------------------------------------\ndefine i8 @src() {\nentry:\n %sub.i.i79.peel.i = sub i16 0, 1\n %xor5.i81.peel.i = zext i16 %sub.i.i79.peel.i to i32\n %conv7.i84.peel.i = sext i16 0 to i32\n %cmp8.i85.peel.i = icmp slt i32 %conv7.i84.peel.i, %xor5.i81.peel.i\n %conv13.i89.peel.i = zext i1 %cmp8.i85.peel.i to i8\n ret i8 %conv13.i89.peel.i\n}\n=>\ndefine i8 @tgt() {\nentry:\n %sub.i.i79.peel.i = sub i16 0, 1\n %#0 = insertelement <2 x i16> { poison, 0 }, i16 %sub.i.i79.peel.i, i32 0\n %#1 = icmp slt <2 x i16> { 0, 0 }, %#0\n %#5 = extractelement <2 x i1> %#1, i32 0\n %conv13.i89.peel.i = zext i1 %#5 to i8\n ret i8 %conv13.i89.peel.i\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\n\nSource:\ni16 %sub.i.i79.peel.i = #xffff (65535, -1)\ni32 %xor5.i81.peel.i = #x0000ffff (65535)\ni32 %conv7.i84.peel.i = #x00000000 (0)\ni1 %cmp8.i85.peel.i = #x1 (1)\ni8 %conv13.i89.peel.i = #x01 (1)\n\nTarget:\ni16 %sub.i.i79.peel.i = #xffff (65535, -1)\n<2 x i16> %#0 = < #xffff (65535, -1), #x0000 (0) >\n<2 x i1> %#1 = < #x0 (0), #x0 (0) >\ni1 %#5 = #x0 (0)\ni8 %conv13.i89.peel.i = #x00 (0)\nSource value: #x01 (1)\nTarget value: #x00 (0)\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [ { "author": "fhahn", "body": "cc @alexey-bataev \n" } ] }
true
null
82877
https://github.com/llvm/llvm-project/issues/82877
hang
f32c6b28b84130dc77e0e69d6d3b692aec933280
2024-02-24T13:05:43
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "abe4677d9f8ab82f722f29dbf57952052accd70b", "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": [ [ 2341, 2351 ], [ 2361, 2372 ], [ 2375, 2380 ] ], "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": [ "InstCombiner::getFreelyInvertedImpl" ], "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 abe4677d9f8ab82f722f29dbf57952052accd70b Author: Yingwei Zheng <[email protected]> Date: Tue Mar 5 03:51:06 2024 +0800 [InstCombine] Fix infinite loop due to incorrect `DoesConsume` (#82973) When a call to `getFreelyInvertedImpl` with a select/phi node fails, `DoesConsume` should not be changed. Fixes https://github.com/llvm/llvm-project/issues/82877. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 87c8dca7efed..80ce0c9275b2 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2341,11 +2341,13 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses, !shouldAvoidAbsorbingNotIntoSelect(*cast<SelectInst>(V)); // Selects/min/max with invertible operands are freely invertible if (IsSelect || match(V, m_MaxOrMin(m_Value(A), m_Value(B)))) { + bool LocalDoesConsume = DoesConsume; if (!getFreelyInvertedImpl(B, B->hasOneUse(), /*Builder*/ nullptr, - DoesConsume, Depth)) + LocalDoesConsume, Depth)) return nullptr; if (Value *NotA = getFreelyInvertedImpl(A, A->hasOneUse(), Builder, - DoesConsume, Depth)) { + LocalDoesConsume, Depth)) { + DoesConsume = LocalDoesConsume; if (Builder != nullptr) { Value *NotB = getFreelyInvertedImpl(B, B->hasOneUse(), Builder, DoesConsume, Depth); @@ -2361,12 +2363,13 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses, } if (PHINode *PN = dyn_cast<PHINode>(V)) { + bool LocalDoesConsume = DoesConsume; SmallVector<std::pair<Value *, BasicBlock *>, 8> IncomingValues; for (Use &U : PN->operands()) { BasicBlock *IncomingBlock = PN->getIncomingBlock(U); Value *NewIncomingVal = getFreelyInvertedImpl( U.get(), /*WillInvertAllUses=*/false, - /*Builder=*/nullptr, DoesConsume, MaxAnalysisRecursionDepth - 1); + /*Builder=*/nullptr, LocalDoesConsume, MaxAnalysisRecursionDepth - 1); if (NewIncomingVal == nullptr) return nullptr; // Make sure that we can safely erase the original PHI node. @@ -2375,6 +2378,8 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses, if (Builder != nullptr) IncomingValues.emplace_back(NewIncomingVal, IncomingBlock); } + + DoesConsume = LocalDoesConsume; if (Builder != nullptr) { IRBuilderBase::InsertPointGuard Guard(*Builder); Builder->SetInsertPoint(PN);
[ { "file": "llvm/test/Transforms/InstCombine/pr82877.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "func", "test_body": "define i64 @func(i32 %p, i1 %cmp1) {\nentry:\n %not = xor i32 %p, -1\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\n %cond = select i1 %cmp1, i32 0, i32 -1231558963\n %xor = xor i32 %cond, %p0\n %cmp2 = icmp ne i32 %xor, 1\n %conv = zext i1 %cmp2 to i32\n br i1 %cmp2, label %for.body, label %for.exit\n\nfor.exit: ; preds = %for.body\n ret i64 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] InstCombine gets stuck when simplifying icmps ", "body": "Reduced test case: https://godbolt.org/z/dc6jnha5q\r\n```\r\ndefine i64 @func(i32 %p) {\r\nentry:\r\n %not = xor i32 %p, -1\r\n br label %for.body\r\n\r\nfor.body:\r\n %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\n %p1 = phi i32 [ 0, %entry ], [ %inc, %for.body ]\r\n %inc = add i32 %p1, 1\r\n %cmp1 = icmp ne i32 %inc, 0\r\n %cond = select i1 %cmp1, i32 0, i32 -1231558963\r\n %xor = xor i32 %cond, %p0\r\n %cmp2 = icmp ne i32 %xor, -2\r\n %conv = zext i1 %cmp2 to i32\r\n br i1 %cmp2, label %for.body, label %for.exit\r\n\r\nfor.exit:\r\n ret i64 0\r\n}\r\n```\r\n\r\n```\r\nIC: Visiting: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\nIC: Visiting: %cmp2 = icmp ne i32 %1, -2\r\nADD DEFERRED: %2 = select i1 %cmp1.not, i32 1231558962, i32 -1\r\nADD DEFERRED: %3 = xor i32 %2, %p0\r\nIC: Old = %cmp2 = icmp ne i32 %1, -2\r\n New = <badref> = icmp ne i32 %3, 1\r\nADD: %cmp2 = icmp ne i32 %3, 1\r\nIC: ERASE %4 = icmp ne i32 %1, -2\r\nADD DEFERRED: %1 = xor i32 %0, %p0\r\nIC: ERASE %1 = xor i32 %0, %p0\r\nADD DEFERRED: %0 = select i1 %cmp1.not, i32 -1231558963, i32 0\r\nADD DEFERRED: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\nADD: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\nIC: ERASE %0 = select i1 %cmp1.not, i32 -1231558963, i32 0\r\nADD DEFERRED: %cmp1.not = icmp eq i32 %inc, 0\r\nADD: %cmp1.not = icmp eq i32 %inc, 0\r\nADD: %1 = xor i32 %0, %p0\r\nADD: %0 = select i1 %cmp1.not, i32 1231558962, i32 -1\r\nIC: Visiting: %0 = select i1 %cmp1.not, i32 1231558962, i32 -1\r\nIC: Visiting: %1 = xor i32 %0, %p0\r\nIC: Visiting: %cmp1.not = icmp eq i32 %inc, 0\r\nIC: Visiting: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\nIC: Visiting: %cmp2 = icmp ne i32 %1, 1\r\nADD DEFERRED: %2 = select i1 %cmp1.not, i32 -1231558963, i32 0\r\nADD DEFERRED: %3 = xor i32 %2, %p0\r\nIC: Old = %cmp2 = icmp ne i32 %1, 1\r\n New = <badref> = icmp ne i32 %3, -2\r\nADD: %cmp2 = icmp ne i32 %3, -2\r\nIC: ERASE %4 = icmp ne i32 %1, 1\r\nADD DEFERRED: %1 = xor i32 %0, %p0\r\nIC: ERASE %1 = xor i32 %0, %p0\r\nADD DEFERRED: %0 = select i1 %cmp1.not, i32 1231558962, i32 -1\r\nADD DEFERRED: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\nADD: %p0 = phi i32 [ %not, %entry ], [ %conv, %for.body ]\r\nIC: ERASE %0 = select i1 %cmp1.not, i32 1231558962, i32 -1\r\nADD DEFERRED: %cmp1.not = icmp eq i32 %inc, 0\r\nADD: %cmp1.not = icmp eq i32 %inc, 0\r\nADD: %1 = xor i32 %0, %p0\r\nADD: %0 = select i1 %cmp1.not, i32 -1231558963, i32 0\r\nIC: Visiting: %0 = select i1 %cmp1.not, i32 -1231558963, i32 0\r\nIC: Visiting: %1 = xor i32 %0, %p0\r\nIC: Visiting: %cmp1.not = icmp eq i32 %inc, 0\r\n\r\nRepeats multiple times...\r\n```", "author": "dtcxzyw", "labels": [ "llvm:instcombine", "llvm:hang" ], "comments": [ { "author": "dtcxzyw", "body": "Another reproducer:\r\n```\r\n/*\r\n * This is a RANDOMLY GENERATED PROGRAM.\r\n *\r\n * Generator: csmith 2.4.0\r\n * Git version: 0ec6f1b\r\n * Options: --max-funcs 3 --max-block-depth 3 --quiet --no-packed-struct --no-bitfields --no-volatiles --no-volatile-pointers --output ./csmith2024-02-24@16:09/test34436.c\r\n * Seed: 3421191658\r\n */\r\n\r\n#include \"csmith.h\"\r\n\r\n\r\nstatic long __undefined;\r\n\r\n\r\n\r\nstatic int32_t g_11[2] = {(-1L),(-1L)};\r\nstatic uint16_t g_12 = 0x5EB7L;\r\nstatic uint64_t g_31 = 2UL;\r\nstatic uint64_t g_33[9][1][9] = {{{0x0273394210AB9CA2LL,0x0B9C45D188285970LL,0x0B9C45D188285970LL,0x0273394210AB9CA2LL,18446744073709551611UL,18446744073709551607UL,0x461D90BCC9DF78A4LL,0x0B9C45D188285970LL,18446744073709551607UL}},{{4UL,0x0B9C45D188285970LL,0xF205A4AAC46587A7LL,0x461D90BCC9DF78A4LL,18446744073709551614UL,18446744073709551614UL,0x461D90BCC9DF78A4LL,0xF205A4AAC46587A7LL,0x0B9C45D188285970LL}},{{0x461D90BCC9DF78A4LL,18446744073709551611UL,0xF205A4AAC46587A7LL,0xD17401D8B2D29C61LL,18446744073709551611UL,0x0B9C45D188285970LL,1UL,0xF205A4AAC46587A7LL,0xF205A4AAC46587A7LL}},{{4UL,18446744073709551614UL,0x0B9C45D188285970LL,0xD17401D8B2D29C61LL,0x0B9C45D188285970LL,18446744073709551614UL,4UL,0x0B9C45D188285970LL,0xF205A4AAC46587A7LL}},{{0x0273394210AB9CA2LL,18446744073709551611UL,18446744073709551607UL,0x461D90BCC9DF78A4LL,0x0B9C45D188285970LL,18446744073709551607UL,1UL,18446744073709551607UL,0xDAEE255298A7B986LL}},{{0xF205A4AAC46587A7LL,0xDAEE255298A7B986LL,0xDAEE255298A7B986LL,0xF205A4AAC46587A7LL,18446744073709551606UL,0x68F5B79C14114C53LL,18446744073709551607UL,0xDAEE255298A7B986LL,0x68F5B79C14114C53LL}},{{0x0B9C45D188285970LL,0xDAEE255298A7B986LL,1UL,18446744073709551607UL,18446744073709551609UL,18446744073709551609UL,18446744073709551607UL,1UL,0xDAEE255298A7B986LL}},{{18446744073709551607UL,18446744073709551606UL,1UL,18446744073709551611UL,18446744073709551606UL,0xDAEE255298A7B986LL,18446744073709551614UL,1UL,1UL}},{{0x0B9C45D188285970LL,18446744073709551609UL,0xDAEE255298A7B986LL,18446744073709551611UL,0xDAEE255298A7B986LL,18446744073709551609UL,0x0B9C45D188285970LL,0xDAEE255298A7B986LL,1UL}}};\r\nstatic const int32_t *g_35 = &g_11[1];\r\nstatic int64_t g_66[5][4] = {{(-9L),6L,6L,(-9L)},{6L,(-9L),6L,6L},{(-9L),(-9L),3L,(-9L)},{(-9L),6L,6L,(-9L)},{6L,(-9L),6L,6L}};\r\nstatic uint32_t g_94[3] = {0x3680C6D9L,0x3680C6D9L,0x3680C6D9L};\r\nstatic uint32_t g_149 = 5UL;\r\nstatic int64_t g_157[9] = {9L,9L,(-1L),9L,9L,(-1L),9L,9L,(-1L)};\r\nstatic int8_t g_165 = 8L;\r\nstatic int16_t g_168 = 0xD32BL;\r\nstatic int32_t *g_169 = &g_11[0];\r\nstatic int32_t *g_170 = (void*)0;\r\nstatic uint8_t g_185 = 246UL;\r\nstatic int32_t **g_256 = &g_169;\r\nstatic int32_t *** const g_255 = &g_256;\r\nstatic uint32_t g_306 = 0xF063AF95L;\r\nstatic int16_t g_311 = 7L;\r\nstatic int32_t g_313 = 0x472F43A5L;\r\nstatic const uint16_t g_341 = 0xB915L;\r\nstatic uint8_t g_346[6] = {0x3EL,0x3EL,0x3EL,0x3EL,0x3EL,0x3EL};\r\nstatic uint8_t g_366[6][2] = {{0x39L,0x39L},{0UL,0x39L},{0x39L,0UL},{0x39L,0x39L},{0UL,0x39L},{0x39L,0UL}};\r\nstatic const int64_t *g_373 = &g_157[0];\r\nstatic const int64_t **g_372 = &g_373;\r\nstatic uint32_t g_380 = 4294967293UL;\r\nstatic uint16_t g_407 = 0UL;\r\nstatic int8_t g_409 = (-2L);\r\nstatic int8_t *g_408 = &g_409;\r\nstatic const int8_t g_412 = 0xF0L;\r\nstatic const int8_t g_414 = 0x89L;\r\nstatic const int8_t g_416[5][10] = {{0L,0xDDL,0L,(-1L),(-1L),0L,0xDDL,0L,(-1L),(-1L)},{0L,0xDDL,0L,(-1L),(-1L),0L,0xDDL,0L,(-1L),(-1L)},{0L,0xDDL,0L,(-1L),(-1L),0L,0xDDL,0L,(-1L),(-1L)},{0L,0xDDL,0L,(-1L),(-1L),0L,0xDDL,0L,(-1L),(-1L)},{0L,0xDDL,0L,(-1L),(-1L),0L,0xDDL,0L,(-1L),(-1L)}};\r\nstatic const int8_t *g_415[9][1] = {{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]},{&g_416[2][2]}};\r\nstatic int8_t g_426 = (-6L);\r\nstatic int32_t g_457 = 0x1708815BL;\r\nstatic int16_t *g_466[10][10][2] = {{{&g_311,&g_168},{&g_311,(void*)0},{&g_311,&g_168},{&g_311,&g_311},{&g_168,&g_311},{(void*)0,&g_311},{&g_168,&g_311},{&g_311,&g_168},{&g_311,(void*)0},{&g_311,&g_168}},{{&g_311,&g_311},{&g_168,&g_311},{(void*)0,&g_311},{&g_168,&g_311},{&g_311,&g_168},{&g_311,(void*)0},{&g_311,&g_168},{&g_311,&g_311},{&g_168,&g_311},{(void*)0,&g_311}},{{&g_168,&g_311},{&g_311,&g_168},{&g_311,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168}},{{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168}},{{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0}},{{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0}},{{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0}},{{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0}},{{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168}},{{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168},{&g_168,(void*)0},{(void*)0,(void*)0},{(void*)0,&g_168},{&g_168,&g_168},{(void*)0,(void*)0},{(void*)0,(void*)0},{&g_168,&g_168}}};\r\nstatic int32_t *g_596[1] = {&g_11[0]};\r\n\r\n\r\n\r\nstatic uint8_t func_1(void);\r\nstatic int32_t func_8(int32_t p_9);\r\nstatic int16_t func_15(int8_t p_16, uint32_t p_17, int32_t p_18);\r\n\r\n\r\n\r\n\r\n\r\nstatic uint8_t func_1(void)\r\n{ \r\n int32_t l_7 = (-8L);\r\n uint16_t *l_572 = &g_407;\r\n int32_t *l_573 = &g_11[1];\r\n int32_t *l_588 = &g_313;\r\n int8_t *l_595 = (void*)0;\r\n int32_t **l_597 = &g_596[0];\r\n (*l_573) = (safe_div_func_uint16_t_u_u(((*l_572) = (0xCDF98A59L && (((0x4EBB0CB8CE3E63E3LL > (safe_lshift_func_uint32_t_u_u(1UL, (~(l_7 , func_8(l_7)))))) > (((safe_mul_func_uint32_t_u_u((l_7 || (safe_add_func_uint8_t_u_u(((g_341 && (-1L)) , 0x01L), g_416[2][6]))), l_7)) & 0xDE15L) , l_7)) >= l_7))), 65527UL));\r\n (*l_597) = (((((*l_573) ^ (**g_372)) != (safe_div_func_int8_t_s_s((safe_rshift_func_uint64_t_u_u(0x1A63987AF980F8B3LL, (safe_rshift_func_uint8_t_u_u((((g_426 ^= ((safe_add_func_int64_t_s_s(((safe_add_func_uint32_t_u_u(((safe_sub_func_uint16_t_u_u((safe_mod_func_int8_t_s_s(0x95L, (((*l_588) = (*l_573)) ^ ((*l_573) != (safe_rshift_func_int32_t_s_s((*l_573), ((((safe_sub_func_int32_t_s_s(((((safe_mod_func_int8_t_s_s((*g_408), 3UL)) && 0x38L) || g_168) == (*l_573)), (*l_573))) && 249UL) & g_31) , g_457))))))), g_94[0])) , g_341), g_94[2])) ^ g_149), (*g_373))) > 0xF735A181L)) != (*l_573)) != (-1L)), g_185)))), (*l_573)))) ^ (-1L)) , g_596[0]);\r\n for (g_185 = 0; (g_185 == 37); g_185 = safe_add_func_uint32_t_u_u(g_185, 4))\r\n { \r\n uint32_t l_600 = 0x5F5A8D5BL;\r\n (**l_597) = l_600;\r\n }\r\n return g_426;\r\n}\r\n\r\n\r\n\r\n\r\nstatic int32_t func_8(int32_t p_9)\r\n{ \r\n int32_t *l_10[7][10][3] = {{{&g_11[0],&g_11[0],&g_11[1]},{&g_11[1],&g_11[0],(void*)0},{&g_11[0],&g_11[0],&g_11[1]},{&g_11[0],&g_11[0],&g_11[1]},{&g_11[0],(void*)0,(void*)0},{&g_11[0],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[0],&g_11[0],&g_11[1]},{(void*)0,&g_11[1],(void*)0},{&g_11[1],(void*)0,&g_11[1]}},{{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[0],&g_11[1],(void*)0},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[0],&g_11[0],&g_11[1]},{&g_11[0],&g_11[1],&g_11[0]},{(void*)0,&g_11[1],&g_11[0]},{&g_11[0],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]}},{{(void*)0,(void*)0,(void*)0},{&g_11[0],&g_11[1],&g_11[1]},{(void*)0,&g_11[1],(void*)0},{&g_11[0],&g_11[0],&g_11[1]},{(void*)0,&g_11[0],&g_11[1]},{&g_11[1],&g_11[1],&g_11[0]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[0],&g_11[1],&g_11[1]},{(void*)0,(void*)0,&g_11[0]},{&g_11[0],&g_11[1],&g_11[0]}},{{&g_11[0],(void*)0,&g_11[0]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[0],&g_11[1],&g_11[1]},{&g_11[1],&g_11[0],&g_11[0]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[0],(void*)0},{&g_11[1],&g_11[0],&g_11[1]},{&g_11[1],&g_11[0],(void*)0},{&g_11[1],&g_11[1],&g_11[1]}},{{&g_11[0],&g_11[1],&g_11[1]},{&g_11[1],&g_11[0],&g_11[1]},{&g_11[1],&g_11[1],&g_11[0]},{&g_11[0],&g_11[1],&g_11[0]},{&g_11[1],(void*)0,&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],(void*)0,(void*)0},{&g_11[0],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]}},{{&g_11[0],&g_11[0],&g_11[1]},{&g_11[1],&g_11[0],&g_11[1]},{&g_11[1],&g_11[1],&g_11[0]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],(void*)0,&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[0],&g_11[1],(void*)0},{&g_11[1],&g_11[1],&g_11[1]}},{{&g_11[0],&g_11[0],&g_11[1]},{&g_11[0],&g_11[1],&g_11[0]},{(void*)0,&g_11[1],&g_11[0]},{&g_11[0],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{&g_11[1],&g_11[1],&g_11[1]},{(void*)0,(void*)0,(void*)0},{&g_11[0],&g_11[1],&g_11[1]},{(void*)0,&g_11[1],(void*)0},{&g_11[0],&g_11[0],&g_11[1]}}};\r\n int32_t **l_23 = &l_10[6][7][1];\r\n int32_t l_24[1];\r\n uint64_t *l_30 = &g_31;\r\n uint64_t *l_32 = &g_33[8][0][8];\r\n int16_t *l_310 = &g_311;\r\n int32_t *l_312 = &g_313;\r\n uint16_t *l_314 = &g_12;\r\n uint8_t * const l_319 = &g_185;\r\n int32_t *l_338[7];\r\n int8_t l_381 = 0x82L;\r\n int64_t *l_425 = &g_66[1][0];\r\n int64_t **l_424[6] = {&l_425,&l_425,&l_425,&l_425,&l_425,&l_425};\r\n int64_t ***l_423 = &l_424[2];\r\n int i, j, k;\r\n for (i = 0; i < 1; i++)\r\n l_24[i] = 1L;\r\n for (i = 0; i < 7; i++)\r\n l_338[i] = &g_313;\r\n --g_12;\r\n (*l_312) |= (((*l_310) |= func_15((((((*l_32) = ((*l_30) = (((safe_mod_func_uint64_t_u_u((((p_9 , (void*)0) == ((*l_23) = l_10[5][8][0])) && (g_11[1] <= 0x8543L)), l_24[0])) , (!(safe_div_func_uint16_t_u_u((g_12 , ((((((safe_sub_func_int64_t_s_s(((-1L) && (g_12 >= p_9)), p_9)) > 0xED293E35L) | 0x12CB5DCFL) > g_11[1]) , p_9) , p_9)), g_11[1])))) && g_11[0]))) , 0UL) != 0x52L) || g_12), p_9, g_12)) <= 0xA360L);\r\n (*l_23) = (void*)0;\r\n if (((p_9 && (((((*l_312) >= ((*l_314) = 65535UL)) , (safe_div_func_int32_t_s_s((safe_mod_func_uint16_t_u_u(((((l_319 == l_319) >= (safe_rshift_func_int16_t_s_s((((safe_mod_func_uint32_t_u_u(p_9, g_149)) , (void*)0) != l_30), p_9))) , g_31) != p_9), g_31)), p_9))) != g_157[0]) && p_9)) && 0L))\r\n { \r\n int8_t * const l_324[7] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};\r\n int8_t *l_326[9] = {&g_165,&g_165,&g_165,&g_165,&g_165,&g_165,&g_165,&g_165,&g_165};\r\n int8_t **l_325 = &l_326[6];\r\n int8_t *l_328 = &g_165;\r\n int8_t **l_327 = &l_328;\r\n int32_t l_333 = 1L;\r\n int32_t l_369 = 0x5EBB0ECBL;\r\n const int8_t *l_413 = &g_414;\r\n int32_t **l_417 = (void*)0;\r\n int32_t l_458[9][2][1] = {{{(-5L)},{(-5L)}},{{(-6L)},{(-5L)}},{{(-5L)},{(-6L)}},{{(-5L)},{(-5L)}},{{(-6L)},{(-5L)}},{{(-5L)},{(-6L)}},{{(-5L)},{(-5L)}},{{(-6L)},{(-5L)}},{{(-5L)},{(-6L)}}};\r\n int32_t l_496[6][7] = {{1L,0xA4F1B851L,0x37A88DA2L,0xA4F1B851L,1L,0L,0L},{1L,0xA4F1B851L,0x37A88DA2L,0xA4F1B851L,1L,0L,0L},{1L,0xA4F1B851L,0x37A88DA2L,0xA4F1B851L,1L,0L,0L},{1L,0xA4F1B851L,0x37A88DA2L,0xA4F1B851L,1L,0L,0L},{1L,0xA4F1B851L,0x37A88DA2L,0xA4F1B851L,1L,0L,0L},{1L,0xA4F1B851L,0x37A88DA2L,0xA4F1B851L,1L,0L,0L}};\r\n uint8_t l_499 = 4UL;\r\n int i, j, k;\r\n if (((((l_324[0] == ((*l_327) = ((*l_325) = &g_165))) , 0x77C2C50F563A9C1DLL) , ((*l_319) = (safe_mul_func_int32_t_s_s(p_9, ((safe_lshift_func_uint64_t_u_u(l_333, (--(*l_32)))) & (safe_mul_func_uint64_t_u_u(((void*)0 != l_338[2]), (safe_sub_func_int64_t_s_s(0x64D8F0F17592A3D5LL, ((0x23L ^ g_313) < g_12)))))))))) , g_341))\r\n { \r\n return p_9;\r\n }\r\n else\r\n { \r\n int64_t l_367 = 1L;\r\n int32_t l_368 = 3L;\r\n int64_t *l_399 = &g_157[0];\r\n int64_t **l_398[8] = {&l_399,&l_399,&l_399,&l_399,&l_399,&l_399,&l_399,&l_399};\r\n int64_t ***l_397 = &l_398[6];\r\n int32_t **l_420 = (void*)0;\r\n int32_t l_460[9][4][7] = {{{0x3D2FE6F7L,(-1L),0L,0x6944E926L,(-1L),(-1L),0x2AF43CFEL},{0x77DC1A4FL,7L,0L,0xB5C39BA6L,0x8A6F8D2AL,0x78B5A455L,6L},{0L,3L,0x3D2FE6F7L,0x27A80343L,0x38C9E105L,(-1L),(-1L)},{0xD73C9A77L,0xCE3D98E2L,0x38C9E105L,(-1L),8L,(-1L),0x38C9E105L}},{{6L,6L,0x835FBC13L,5L,0xCCB98A17L,5L,0x651280DBL},{8L,1L,(-1L),0L,(-1L),(-1L),0x571592F3L},{0L,0x10A7A682L,0xB9488037L,6L,0xCCB98A17L,0x2F71711FL,0x27A80343L},{(-1L),0x38C9E105L,1L,4L,8L,7L,(-1L)}},{{0x7639893BL,0L,0x8D6AEC21L,1L,0x38C9E105L,0x541A2144L,0x08FC8D1FL},{0x651280DBL,(-1L),0L,0xD73C9A77L,0x8A6F8D2AL,0x74F12713L,0L},{1L,0x74F12713L,1L,0x52681015L,(-1L),0L,0x34D5741FL},{0x6944E926L,0xB5C39BA6L,0x78B5A455L,0x92017A1BL,(-1L),0L,(-1L)}},{{0x787EDD2CL,0x0AF78BCDL,0xB5C39BA6L,5L,(-1L),0x74F12713L,0L},{0x74F12713L,(-10L),0x10A7A682L,1L,0L,0x541A2144L,3L},{0L,0xCCB98A17L,0x7639893BL,6L,0xA8583C15L,7L,0xA8583C15L},{0x8A6F8D2AL,0xC899F44EL,0xC899F44EL,0x8A6F8D2AL,0x88020F57L,0x2F71711FL,(-1L)}},{{0xA8583C15L,0x835FBC13L,0x2AF43CFEL,0L,0x787EDD2CL,0x77DC1A4FL,1L},{1L,5L,5L,0x73D9572DL,0L,0L,0x77DC1A4FL},{(-1L),0x7639893BL,0x2DCD775DL,2L,0L,0xC899F44EL,(-10L)},{(-1L),0xB9488037L,0x835FBC13L,1L,0x92017A1BL,4L,0xCE3D98E2L}},{{0x7BF1CC1CL,6L,(-1L),0x92017A1BL,0x8A6F8D2AL,(-1L),(-1L)},{4L,0x571592F3L,0xC899F44EL,8L,0L,0x835FBC13L,0L},{2L,0x77DC1A4FL,8L,0x7BF1CC1CL,0xCCB98A17L,0x74F12713L,0x08FC8D1FL},{2L,0x8A6F8D2AL,3L,0x571592F3L,(-1L),0L,1L}},{{4L,3L,0x92017A1BL,0x38C9E105L,0x7BF1CC1CL,0x88020F57L,5L},{0x7BF1CC1CL,(-1L),0L,0x78B5A455L,5L,(-1L),0x835FBC13L},{(-1L),0L,0L,0L,0L,(-1L),0L},{(-1L),0x3D2FE6F7L,1L,3L,0xC14CCFD7L,0L,0x2F71711FL}},{{1L,0x787EDD2CL,1L,0x651280DBL,8L,0x92017A1BL,0x7639893BL},{(-10L),0x3D2FE6F7L,1L,(-1L),0L,(-1L),1L},{0x52681015L,0L,2L,(-1L),0x88020F57L,0x0AF78BCDL,0L},{7L,(-1L),0x0AF78BCDL,1L,0xB9488037L,1L,0L}},{{(-1L),3L,0x2DFF457AL,0x787EDD2CL,1L,0L,0x8D6AEC21L},{0x27A80343L,0x8A6F8D2AL,6L,0x2DFF457AL,1L,8L,(-1L)},{(-1L),0x77DC1A4FL,6L,1L,(-1L),1L,0x34D5741FL},{6L,0x571592F3L,0x2DFF457AL,1L,0x78B5A455L,0x52681015L,0x3D2FE6F7L}}};\r\n uint8_t l_461 = 0xE6L;\r\n int i, j, k;\r\n for (g_185 = 0; (g_185 <= 2); g_185 += 1)\r\n { \r\n int32_t l_358[8][2] = {{0xC6A9D3CAL,(-5L)},{0x33E30AB4L,0x33E30AB4L},{(-5L),0xC6A9D3CAL},{0x356F701CL,0xC6A9D3CAL},{(-5L),0x33E30AB4L},{0x33E30AB4L,(-5L)},{0xC6A9D3CAL,0x356F701CL},{0xC6A9D3CAL,(-5L)}};\r\n uint8_t *l_364 = (void*)0;\r\n uint8_t *l_365[9][4][7] = {{{&g_185,&g_366[5][1],(void*)0,&g_185,&g_366[5][1],&g_366[5][1],(void*)0},{&g_185,&g_366[4][1],&g_185,&g_366[2][0],(void*)0,&g_366[5][1],&g_185},{(void*)0,&g_366[5][1],&g_366[1][0],&g_366[5][1],&g_366[1][0],&g_366[5][1],(void*)0},{&g_185,&g_366[5][1],(void*)0,&g_366[2][0],&g_185,&g_366[4][1],&g_185}},{{(void*)0,&g_366[5][1],&g_366[5][1],&g_185,(void*)0,&g_366[5][1],&g_185},{&g_366[5][1],&g_366[5][1],(void*)0,&g_185,&g_366[5][1],&g_366[5][1],&g_366[5][1]},{&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[1][1],&g_185},{&g_366[2][0],&g_185,&g_366[5][1],&g_366[4][1],&g_366[5][1],&g_185,&g_366[5][1]}},{{(void*)0,&g_366[5][1],&g_366[1][1],&g_366[5][1],&g_366[4][0],&g_366[5][1],(void*)0},{&g_366[2][0],&g_366[4][1],&g_366[5][1],&g_185,&g_366[5][1],&g_366[5][1],&g_185},{&g_366[5][1],&g_366[5][0],&g_366[5][1],&g_366[5][1],&g_366[0][1],&g_366[5][1],(void*)0},{&g_185,(void*)0,&g_366[5][1],&g_366[5][1],&g_366[2][0],&g_366[5][1],&g_366[5][1]}},{{&g_366[0][1],&g_185,&g_366[4][0],&g_366[5][1],&g_366[1][0],&g_366[5][1],&g_185},{&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_185,&g_185,&g_366[5][1],&g_366[5][1]},{&g_366[1][1],&g_366[1][1],&g_366[0][1],&g_185,&g_366[1][0],&g_366[5][1],&g_366[5][1]},{&g_366[5][1],&g_185,&g_366[2][0],&g_366[5][1],&g_366[2][0],&g_185,&g_366[5][1]}},{{&g_366[5][1],&g_366[5][1],&g_366[1][0],&g_185,&g_366[0][1],&g_366[1][1],&g_366[1][1]},{&g_366[5][1],&g_366[5][1],&g_185,&g_185,&g_366[5][1],&g_366[5][1],&g_366[5][1]},{&g_185,&g_366[5][1],&g_366[1][0],&g_366[5][1],&g_366[4][0],&g_185,&g_366[0][1]},{&g_366[5][1],&g_366[5][1],&g_366[2][0],&g_366[5][1],&g_366[5][1],(void*)0,&g_185}},{{(void*)0,&g_366[5][1],&g_366[0][1],&g_366[5][1],&g_366[5][1],&g_366[5][0],&g_366[5][1]},{&g_185,&g_366[5][1],&g_366[5][1],&g_185,&g_366[5][1],&g_366[4][1],&g_366[2][0]},{(void*)0,&g_366[5][1],&g_366[4][0],&g_366[5][1],&g_366[1][1],&g_366[5][1],(void*)0},{&g_366[5][1],&g_185,&g_366[5][1],&g_366[4][1],&g_366[5][1],&g_185,&g_366[2][0]}},{{&g_185,&g_366[1][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1]},{&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_185,&g_185},{&g_366[5][1],&g_185,&g_366[1][1],&g_366[5][1],(void*)0,&g_366[5][1],&g_366[0][1]},{&g_366[5][1],(void*)0,&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[4][1],&g_366[5][1]}},{{&g_366[1][1],&g_366[5][0],&g_366[5][1],&g_185,&g_366[5][1],&g_366[5][0],&g_366[1][1]},{&g_366[5][1],&g_366[4][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],(void*)0,&g_366[5][1]},{&g_366[0][1],&g_366[5][1],(void*)0,&g_366[5][1],&g_366[1][1],&g_185,&g_366[5][1]},{&g_185,&g_185,&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1]}},{{&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],&g_366[5][1],(void*)0,&g_366[5][1]},{&g_366[5][1],&g_366[5][1],&g_366[5][1],(void*)0,&g_185,&g_366[5][1],&g_185},{&g_366[0][1],&g_366[5][1],(void*)0,&g_185,&g_185,&g_366[1][1],&g_366[5][1]},{&g_366[5][1],(void*)0,&g_185,&g_366[5][1],&g_185,&g_185,&g_366[5][1]}}};\r\n const int64_t ***l_374 = &g_372;\r\n int32_t l_379 = 1L;\r\n int i, j, k;\r\n (***g_255) &= (p_9 , ((((safe_div_func_int32_t_s_s(((*l_312) = (safe_add_func_int16_t_s_s(p_9, (g_346[4] = ((*l_314) = 0x6B72L))))), ((safe_sub_func_int16_t_s_s(((g_380 = (safe_sub_func_uint64_t_u_u(((safe_rshift_func_uint64_t_u_s(((((!(safe_sub_func_int64_t_s_s((safe_mul_func_int16_t_s_s(0xB195L, l_358[2][0])), (safe_unary_minus_func_int8_t_s(g_157[5]))))) , ((safe_rshift_func_uint32_t_u_s((((safe_mod_func_uint64_t_u_u((l_358[7][1] = p_9), (((g_366[3][0]--) & (((((*l_374) = g_372) != ((safe_sub_func_int16_t_s_s((l_369 |= ((((**l_327) |= (safe_div_func_int16_t_s_s((g_157[7] , g_157[0]), 0x06ABL))) | g_31) , g_306)), p_9)) , (void*)0)) == 0UL) , p_9)) , p_9))) < g_341) >= g_33[1][0][8]), 17)) , 0x2338L)) ^ 65535UL) , g_94[1]), l_379)) & (*g_373)), 0x739DBB08F21F6146LL))) , g_31), 0L)) && l_381))) >= (-5L)) & 0L) ^ l_379));\r\n }\r\n for (g_165 = 0; (g_165 == (-6)); g_165 = safe_sub_func_int8_t_s_s(g_165, 3))\r\n { \r\n const int64_t ***l_396 = (void*)0;\r\n int64_t ****l_400 = (void*)0;\r\n int64_t ****l_401 = &l_397;\r\n int32_t l_406 = (-1L);\r\n const int8_t *l_411[4][10][5] = {{{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,&g_412,(void*)0},{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412}},{{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,&g_412,(void*)0},{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412}},{{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,&g_412,(void*)0},{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412}},{{&g_412,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,(void*)0},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,&g_412,&g_412,&g_412,(void*)0},{(void*)0,&g_412,&g_412,&g_412,&g_412},{(void*)0,&g_412,&g_412,(void*)0,&g_412},{&g_412,&g_412,&g_412,&g_412,&g_412},{&g_412,(void*)0,&g_412,&g_412,&g_412}}};\r\n const int8_t **l_410[5][8][6] = {{{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[3][7][3],&l_411[2][7][3]},{&l_411[3][5][2],&l_411[2][7][3],&l_411[3][4][4],&l_411[2][7][3],&l_411[2][7][3],(void*)0},{(void*)0,&l_411[2][7][3],(void*)0,&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[3][5][2],&l_411[0][2][2],&l_411[2][7][3],&l_411[2][7][3],&l_411[3][3][1],&l_411[2][7][3]},{&l_411[2][7][3],&l_411[0][3][1],&l_411[0][7][3],&l_411[2][3][0],&l_411[2][7][3],&l_411[2][7][3]},{(void*)0,&l_411[2][8][1],&l_411[2][7][3],&l_411[2][7][3],(void*)0,&l_411[2][7][3]},{&l_411[2][7][3],&l_411[3][1][4],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[0][8][2],&l_411[2][7][3],&l_411[0][7][3],&l_411[2][7][3],&l_411[0][7][3],&l_411[2][7][3]}},{{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],(void*)0,&l_411[2][7][3]},{&l_411[2][7][3],(void*)0,(void*)0,&l_411[0][2][2],&l_411[2][7][3],(void*)0},{&l_411[2][7][3],(void*)0,&l_411[3][4][4],&l_411[3][1][4],(void*)0,&l_411[2][7][3]},{&l_411[1][2][4],&l_411[2][7][3],&l_411[2][7][3],&l_411[0][3][1],&l_411[0][7][3],&l_411[2][3][0]},{&l_411[3][3][1],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[3][2][0],&l_411[3][1][4],&l_411[3][7][3],&l_411[2][7][3],(void*)0,&l_411[2][8][1]},{&l_411[3][2][0],&l_411[2][8][1],(void*)0,&l_411[2][7][3],&l_411[2][7][3],&l_411[3][6][3]},{&l_411[3][3][1],&l_411[0][3][1],&l_411[2][7][3],&l_411[0][3][1],&l_411[3][3][1],&l_411[2][7][3]}},{{&l_411[1][2][4],&l_411[0][2][2],&l_411[2][7][3],&l_411[3][1][4],&l_411[2][7][3],&l_411[1][1][3]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[0][2][2],&l_411[2][7][3],&l_411[1][1][3]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[3][7][3],&l_411[2][7][3]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[3][6][3]},{&l_411[0][8][2],(void*)0,(void*)0,&l_411[2][7][3],&l_411[3][5][2],&l_411[2][8][1]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[3][7][3],&l_411[2][7][3],&l_411[3][5][2],&l_411[2][7][3]},{(void*)0,(void*)0,&l_411[2][7][3],&l_411[2][3][0],&l_411[2][7][3],&l_411[2][3][0]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[3][7][3],&l_411[2][7][3]}},{{&l_411[3][5][2],&l_411[2][7][3],&l_411[3][4][4],&l_411[2][7][3],&l_411[2][7][3],(void*)0},{(void*)0,&l_411[2][7][3],(void*)0,&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[3][5][2],&l_411[0][2][2],&l_411[2][7][3],&l_411[2][7][3],(void*)0,&l_411[2][7][3]},{(void*)0,&l_411[2][7][3],&l_411[2][7][3],&l_411[0][3][1],&l_411[1][2][4],(void*)0},{&l_411[3][5][2],&l_411[3][1][4],&l_411[1][2][4],&l_411[2][4][2],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[3][3][1],&l_411[2][7][3],&l_411[1][2][4],&l_411[2][7][3],(void*)0,(void*)0},{&l_411[3][4][4],&l_411[2][7][3],&l_411[2][7][3],&l_411[1][1][3],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][8][1],(void*)0,&l_411[2][7][3]}},{{&l_411[2][7][3],&l_411[2][3][0],&l_411[3][5][2],&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3]},{&l_411[2][7][3],&l_411[2][3][0],(void*)0,&l_411[2][7][3],(void*)0,&l_411[0][2][2]},{&l_411[2][7][3],&l_411[2][7][3],(void*)0,&l_411[2][7][3],&l_411[2][7][3],&l_411[0][3][1]},{(void*)0,&l_411[2][7][3],&l_411[3][3][1],&l_411[0][2][2],(void*)0,&l_411[2][8][1]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[0][7][3],(void*)0,&l_411[2][7][3],&l_411[3][1][4]},{&l_411[2][7][3],&l_411[3][1][4],&l_411[2][7][3],&l_411[0][2][2],&l_411[1][2][4],&l_411[2][7][3]},{(void*)0,&l_411[2][7][3],&l_411[2][7][3],&l_411[2][7][3],(void*)0,&l_411[2][7][3]},{&l_411[2][7][3],&l_411[2][7][3],&l_411[3][7][3],&l_411[2][7][3],&l_411[2][7][3],(void*)0}}};\r\n int32_t **l_418 = &l_338[6];\r\n int32_t ***l_419[4][2] = {{&l_23,&l_418},{&l_23,&l_418},{&l_23,&l_418},{&l_23,&l_418}};\r\n int i, j, k;\r\n l_333 ^= (((safe_rshift_func_int64_t_s_u((p_9 , ((((((g_407 |= (l_369 = (safe_mod_func_int64_t_s_s(((0xA2936E82L == ((safe_add_func_uint32_t_u_u((safe_mod_func_uint8_t_u_u(l_368, (((((((p_9 , (safe_mod_func_int64_t_s_s((safe_mod_func_int8_t_s_s((l_396 != ((*l_401) = l_397)), (safe_lshift_func_uint32_t_u_s((g_311 || ((safe_lshift_func_uint8_t_u_u((p_9 <= p_9), 4)) | (*g_373))), 31)))), 1L))) && p_9) , &g_373) == &l_399) & (-2L)) , g_313) , g_149))), l_406)) | (-7L))) || g_33[2][0][6]), 0xE09499CAD8E44A95LL)))) ^ p_9) > (*g_169)) || p_9) , g_94[2]) >= (-1L))), 54)) , (*l_312)) | p_9);\r\n (*g_169) = (((*l_314) = (((g_408 = &g_165) != (g_415[6][0] = (l_413 = (void*)0))) <= ((((((*g_255) = l_417) != (l_420 = (l_23 = l_418))) | (l_368 ^= ((((*l_319) = ((((((p_9 | ((safe_mul_func_uint16_t_u_u(0x7263L, (&g_373 == ((**l_401) = (*l_397))))) < ((&g_372 != l_423) & 0x5FL))) && g_414) , p_9) , (*g_372)) != (void*)0) ^ g_185)) && g_426) >= 0x0347D94C0175571CLL))) & p_9) , g_366[5][1]))) == g_414);\r\n if (p_9)\r\n break;\r\n if ((*g_169))\r\n continue;\r\n }\r\n if ((((*l_425) = (p_9 , p_9)) ^ p_9))\r\n { \r\n int32_t *l_434 = &l_24[0];\r\n l_434 = ((safe_unary_minus_func_int64_t_s((safe_rshift_func_uint32_t_u_s((safe_add_func_int32_t_s_s((safe_lshift_func_uint16_t_u_u(5UL, 10)), 4294967293UL)), 24)))) , &g_313);\r\n (*l_23) = (*l_23);\r\n (*l_23) = l_434;\r\n (*l_23) = l_434;\r\n }\r\n else\r\n { \r\n int8_t ***l_437 = (void*)0;\r\n int8_t ***l_438[3];\r\n int32_t l_443 = (-7L);\r\n int32_t l_459[8][9][1] = {{{0x6734A3A9L},{0x17C83ADDL},{0x328560B7L},{1L},{0x220AB6B7L},{1L},{0x220AB6B7L},{1L},{0x328560B7L}},{{0x17C83ADDL},{0x6734A3A9L},{0x7340F128L},{6L},{0x8A5B444AL},{0x553E4A9CL},{6L},{0x71E29F3CL},{6L}},{{0x553E4A9CL},{0x8A5B444AL},{6L},{0x7340F128L},{0x6734A3A9L},{0x17C83ADDL},{0x328560B7L},{1L},{0x220AB6B7L}},{{1L},{0x220AB6B7L},{1L},{0x328560B7L},{0x17C83ADDL},{0x6734A3A9L},{0x7340F128L},{6L},{0x8A5B444AL}},{{0x553E4A9CL},{6L},{0x71E29F3CL},{6L},{0x553E4A9CL},{0x8A5B444AL},{6L},{0x7340F128L},{0x6734A3A9L}},{{0x17C83ADDL},{0x328560B7L},{1L},{0x220AB6B7L},{1L},{0x220AB6B7L},{1L},{0x328560B7L},{0x17C83ADDL}},{{0x6734A3A9L},{0x7340F128L},{6L},{0x8A5B444AL},{0x553E4A9CL},{6L},{0x71E29F3CL},{6L},{0x553E4A9CL}},{{0x8A5B444AL},{6L},{0x7340F128L},{0x6734A3A9L},{0x17C83ADDL},{0x328560B7L},{1L},{0x220AB6B7L},{1L}}};\r\n int16_t * const l_467 = &g_168;\r\n int i, j, k;\r\n for (i = 0; i < 3; i++)\r\n l_438[i] = &l_327;\r\n l_443 = (((safe_div_func_uint32_t_u_u((&g_415[6][0] == (l_327 = &g_408)), (l_333 = 1L))) & ((safe_lshift_func_int8_t_s_s((safe_sub_func_int16_t_s_s(l_443, ((~((!(l_417 != l_420)) | (0x38L ^ ((safe_sub_func_uint64_t_u_u((safe_sub_func_uint16_t_u_u((((safe_add_func_int8_t_s_s((((*l_314) = (safe_mul_func_int64_t_s_s(((*l_425) ^= (*g_373)), (g_457 = (safe_add_func_int64_t_s_s((((~l_443) | p_9) , (*g_373)), g_11[1])))))) , 9L), 0xE4L)) , g_346[4]) , 0x1284L), p_9)), 0x1264E6488AB867F8LL)) , 0xF8L)))) , g_380))), 1)) , (*g_408))) & (-8L));\r\n l_461--;\r\n (*l_312) ^= (((g_466[8][2][1] = &g_168) == l_467) < ((safe_rshift_func_int32_t_s_u((p_9 != (safe_add_func_int64_t_s_s((safe_rshift_func_int8_t_s_s((safe_rshift_func_int16_t_s_u((safe_rshift_func_int16_t_s_s(((safe_add_func_int32_t_s_s((safe_sub_func_uint16_t_u_u(p_9, ((++(*l_314)) & (~((safe_div_func_int32_t_s_s((safe_rshift_func_int16_t_s_s((((*l_30) = l_443) & (((safe_lshift_func_uint16_t_u_u((+((safe_mul_func_uint8_t_u_u((--(*l_319)), l_496[1][1])) | ((safe_add_func_uint8_t_u_u((((*l_32) = p_9) <= (l_326[7] == &g_346[2])), 0xA6L)) , p_9))), 13)) , p_9) < l_443)), p_9)), 9UL)) | g_11[1]))))), p_9)) , 0x32F2L), g_416[3][4])), g_66[3][3])), 2)), p_9))), 31)) == (*g_373)));\r\n (*g_169) ^= p_9;\r\n }\r\n }\r\n (*g_169) = p_9;\r\n ++l_499;\r\n }\r\n else\r\n { \r\n int64_t *l_512[8] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};\r\n int32_t l_513[4];\r\n int64_t l_524[6][10][4] = {{{0x4C3D815AE43813BALL,0xF0C6CFC406DFDF2ALL,0x082E0D4638A26EFBLL,1L},{0xC881B6CB4CC4A5C9LL,0xE4DE13E2542AFC13LL,(-5L),0x2E1C39099BE1D503LL},{(-2L),(-1L),0xC881B6CB4CC4A5C9LL,(-1L)},{0xCD7E5718D9CE495DLL,0x25989EA0395394D5LL,0x25989EA0395394D5LL,0xCD7E5718D9CE495DLL},{0xF0C6CFC406DFDF2ALL,0xF884BC59129141D1LL,(-1L),(-1L)},{9L,0xE1735034541A91DALL,1L,0x082E0D4638A26EFBLL},{(-2L),3L,0xC42F5F76941C79BDLL,0x082E0D4638A26EFBLL},{0x25989EA0395394D5LL,0xE1735034541A91DALL,1L,0x19EE989D2DF288E2LL},{0xCF630E151FD4A638LL,1L,0x4C3D815AE43813BALL,(-3L)},{(-1L),(-7L),9L,0xE4DE13E2542AFC13LL}},{{1L,0x19EE989D2DF288E2LL,1L,0xCF630E151FD4A638LL},{0L,(-5L),0xA72890E95F62B265LL,0xE1735034541A91DALL},{0xCD7E5718D9CE495DLL,0xA726B99D96E26521LL,0L,0x49C30984D15A5727LL},{9L,(-1L),0L,(-1L)},{0xF884BC59129141D1LL,0xCD7E5718D9CE495DLL,0xF884BC59129141D1LL,3L},{3L,0xC881B6CB4CC4A5C9LL,0xE1735034541A91DALL,7L},{(-1L),0x082E0D4638A26EFBLL,(-10L),0xC881B6CB4CC4A5C9LL},{1L,0x2E1C39099BE1D503LL,(-10L),(-1L)},{(-1L),(-1L),0xE1735034541A91DALL,1L},{3L,(-1L),0xF884BC59129141D1LL,0x5333F827537ACEF5LL}},{{0xF884BC59129141D1LL,0x5333F827537ACEF5LL,0L,(-7L)},{9L,0x25989EA0395394D5LL,0L,1L},{0xCD7E5718D9CE495DLL,1L,0xA72890E95F62B265LL,0x4C3D815AE43813BALL},{0L,(-2L),1L,0L},{1L,0xC42F5F76941C79BDLL,9L,9L},{(-1L),(-1L),0x4C3D815AE43813BALL,(-2L)},{0xCF630E151FD4A638LL,0x49C30984D15A5727LL,1L,1L},{0x25989EA0395394D5LL,0L,0xC42F5F76941C79BDLL,1L},{(-2L),0L,1L,1L},{0L,0x49C30984D15A5727LL,0xE4DE13E2542AFC13LL,(-2L)}},{{0xA726B99D96E26521LL,(-1L),(-7L),9L},{(-3L),0xC42F5F76941C79BDLL,0xF0C6CFC406DFDF2ALL,0L},{(-1L),(-2L),0x5333F827537ACEF5LL,0x4C3D815AE43813BALL},{0xF0C6CFC406DFDF2ALL,1L,0x49C30984D15A5727LL,1L},{(-1L),0x25989EA0395394D5LL,1L,(-7L)},{0L,0x5333F827537ACEF5LL,(-1L),0x5333F827537ACEF5LL},{0x49C30984D15A5727LL,(-1L),0x2E1C39099BE1D503LL,1L},{(-7L),(-1L),0L,(-1L)},{(-2L),0x2E1C39099BE1D503LL,(-2L),0xC881B6CB4CC4A5C9LL},{(-2L),0x082E0D4638A26EFBLL,0L,7L}},{{(-7L),0xC881B6CB4CC4A5C9LL,0x2E1C39099BE1D503LL,3L},{0x49C30984D15A5727LL,0xCD7E5718D9CE495DLL,(-1L),(-1L)},{0L,(-1L),1L,0x49C30984D15A5727LL},{(-1L),0xA726B99D96E26521LL,0x49C30984D15A5727LL,0xE1735034541A91DALL},{0xF0C6CFC406DFDF2ALL,(-5L),0x5333F827537ACEF5LL,0xCF630E151FD4A638LL},{(-1L),0x19EE989D2DF288E2LL,0xF0C6CFC406DFDF2ALL,0xE4DE13E2542AFC13LL},{(-3L),(-7L),(-7L),(-3L)},{0xA726B99D96E26521LL,1L,0xE4DE13E2542AFC13LL,0x19EE989D2DF288E2LL},{0L,0xE1735034541A91DALL,1L,0x082E0D4638A26EFBLL},{(-2L),3L,0xC42F5F76941C79BDLL,0x082E0D4638A26EFBLL}},{{0x25989EA0395394D5LL,0xE1735034541A91DALL,1L,0x19EE989D2DF288E2LL},{0xCF630E151FD4A638LL,1L,0x4C3D815AE43813BALL,(-3L)},{(-1L),(-7L),9L,0xE4DE13E2542AFC13LL},{0xE1735034541A91DALL,(-1L),(-1L),0L},{(-2L),0x5333F827537ACEF5LL,0x4C3D815AE43813BALL,3L},{(-3L),0x2E1C39099BE1D503LL,7L,9L},{0L,0xF884BC59129141D1LL,0x25989EA0395394D5LL,0xE4DE13E2542AFC13LL},{1L,(-3L),1L,(-10L)},{(-10L),0xF0C6CFC406DFDF2ALL,3L,(-1L)},{1L,0x49C30984D15A5727LL,1L,0xF0C6CFC406DFDF2ALL}}};\r\n int16_t l_549 = 8L;\r\n int8_t l_567 = 0x65L;\r\n int i, j, k;\r\n for (i = 0; i < 4; i++)\r\n l_513[i] = 0x50CAB1D2L;\r\n (*g_169) |= 1L;\r\n for (g_12 = 0; (g_12 != 9); g_12++)\r\n { \r\n for (g_426 = 17; (g_426 == (-2)); g_426 = safe_sub_func_uint16_t_u_u(g_426, 3))\r\n { \r\n uint8_t l_523[10][4][6] = {{{0xF4L,0x83L,0UL,0xF4L,0xF1L,0x11L},{255UL,0xF4L,0UL,0xF4L,255UL,0xB7L},{0xF4L,255UL,0xB7L,0xC9L,255UL,0x6DL},{0x83L,0xF4L,0xF1L,255UL,0xF1L,0x6DL}},{{0xF1L,0x83L,0xB7L,0x11L,0x11L,0xB7L},{0xF1L,0xF1L,0UL,255UL,253UL,0x11L},{0x83L,0xF1L,0UL,0xC9L,0x11L,0UL},{0xF4L,0x83L,0UL,0xF4L,0xF1L,0x11L}},{{255UL,0xF4L,0UL,0xF4L,255UL,0xB7L},{0xF4L,255UL,0xB7L,0xC9L,255UL,0x6DL},{0x83L,0xF4L,0xF1L,255UL,0xF1L,0x6DL},{0xF1L,0x83L,0xB7L,0x11L,0x11L,0xB7L}},{{0xF1L,0xF1L,0UL,255UL,253UL,0x11L},{0x83L,0xF1L,0UL,0xC9L,0x11L,0UL},{0xF4L,0x83L,0UL,0xF4L,0xF1L,0x11L},{255UL,0xF4L,0UL,0xF4L,255UL,0xB7L}},{{0xF4L,255UL,0xB7L,0xC9L,255UL,0x6DL},{0x83L,0xF4L,0xF1L,255UL,0xF1L,0x6DL},{0xF1L,0x83L,0xB7L,0x11L,0x11L,0xB7L},{0xF1L,0xF1L,0UL,255UL,253UL,0x11L}},{{0x83L,0xF1L,0UL,0xC9L,0x11L,0UL},{0xF4L,0x83L,0UL,0xF4L,0xF1L,0x11L},{255UL,0xF4L,0UL,0xF4L,255UL,0xB7L},{0xF4L,255UL,0xB7L,0xC9L,255UL,0x6DL}},{{0x83L,0xF4L,0xF1L,255UL,0xF1L,0x6DL},{0xF1L,0x83L,0xB7L,0x11L,0x11L,0xB7L},{0xF1L,0xF1L,0UL,255UL,253UL,0x11L},{0x83L,0x79L,255UL,255UL,0x80L,0xF1L}},{{8UL,1UL,255UL,8UL,0x79L,0xC9L},{253UL,8UL,0xF1L,8UL,253UL,0x11L},{8UL,253UL,0x11L,255UL,253UL,0x83L},{1UL,8UL,253UL,253UL,0x79L,0x83L}},{{0x79L,1UL,0x11L,0x80L,0x80L,0x11L},{0x79L,0x79L,0xF1L,253UL,0x5FL,0xC9L},{1UL,0x79L,255UL,255UL,0x80L,0xF1L},{8UL,1UL,255UL,8UL,0x79L,0xC9L}},{{253UL,8UL,0xF1L,8UL,253UL,0x11L},{8UL,253UL,0x11L,255UL,253UL,0x83L},{1UL,8UL,253UL,253UL,0x79L,0x83L},{0x79L,1UL,0x11L,0x80L,0x80L,0x11L}}};\r\n int i, j, k;\r\n (**g_256) = ((safe_div_func_int8_t_s_s(1L, ((p_9 , ((safe_sub_func_int32_t_s_s(p_9, ((safe_add_func_int16_t_s_s((l_512[7] == (void*)0), ((*l_310) = (g_165 | l_513[1])))) | (safe_add_func_uint64_t_u_u(p_9, (safe_sub_func_uint32_t_u_u((safe_sub_func_int8_t_s_s(((!(safe_add_func_uint64_t_u_u(((p_9 <= 0L) ^ g_33[8][0][8]), (-1L)))) < l_513[0]), g_149)), l_513[1]))))))) , (-1L))) && g_426))) ^ l_523[3][2][5]);\r\n return l_524[3][2][1];\r\n }\r\n for (g_426 = 0; (g_426 < 8); g_426++)\r\n { \r\n (**g_255) = &l_513[2];\r\n }\r\n }\r\n for (g_426 = 26; (g_426 == 5); g_426 = safe_sub_func_uint8_t_u_u(g_426, 8))\r\n { \r\n int32_t l_534 = (-1L);\r\n int32_t l_536 = 0xD26B6040L;\r\n uint64_t l_537 = 18446744073709551610UL;\r\n for (g_407 = 25; (g_407 < 30); g_407 = safe_add_func_uint64_t_u_u(g_407, 8))\r\n { \r\n uint16_t l_533 = 0xD203L;\r\n int32_t l_535 = (-4L);\r\n (**g_256) = (safe_add_func_uint16_t_u_u((l_533 != (((l_533 > p_9) > p_9) ^ l_533)), l_513[1]));\r\n l_537++;\r\n return l_535;\r\n }\r\n for (l_537 = 0; (l_537 >= 29); l_537++)\r\n { \r\n uint32_t *l_564[5][7][7] = {{{&g_94[2],&g_380,&g_149,&g_380,&g_94[0],&g_380,&g_149},{&g_149,&g_149,(void*)0,&g_94[2],&g_380,&g_94[2],&g_380},{&g_94[1],&g_149,&g_149,&g_94[2],&g_94[2],&g_380,&g_380},{&g_94[2],&g_380,&g_380,&g_94[0],&g_380,&g_94[2],&g_149},{&g_94[2],&g_94[2],&g_94[2],(void*)0,&g_94[0],(void*)0,&g_149},{&g_94[1],&g_149,&g_94[2],&g_94[0],&g_149,(void*)0,&g_149},{&g_149,&g_94[2],(void*)0,&g_94[2],&g_94[2],(void*)0,&g_149}},{{&g_94[2],&g_380,&g_94[2],&g_94[2],&g_94[0],(void*)0,&g_380},{&g_94[2],&g_94[2],&g_94[2],&g_380,&g_380,(void*)0,&g_380},{&g_380,&g_380,&g_380,&g_94[2],&g_380,(void*)0,&g_149},{&g_94[2],&g_94[2],&g_149,&g_380,&g_94[0],&g_94[2],&g_149},{&g_380,&g_149,(void*)0,&g_380,&g_94[2],&g_380,(void*)0},{&g_94[2],&g_94[2],&g_149,&g_94[2],&g_149,&g_94[2],&g_149},{&g_94[2],&g_380,&g_149,&g_380,&g_94[0],&g_380,&g_149}},{{&g_149,&g_149,(void*)0,&g_94[2],&g_380,&g_94[2],&g_380},{&g_94[1],&g_149,&g_149,&g_94[2],&g_94[2],&g_380,&g_380},{&g_94[2],&g_380,&g_94[2],&g_94[0],&g_94[0],&g_94[2],&g_149},{&g_380,&g_149,&g_380,&g_149,&g_380,&g_149,&g_94[2]},{&g_94[2],(void*)0,&g_149,&g_94[0],&g_94[1],&g_380,&g_94[2]},{&g_94[0],&g_380,&g_94[2],&g_94[2],&g_149,&g_149,&g_149},{&g_149,&g_94[2],&g_149,&g_380,&g_94[2],&g_149,&g_94[2]}},{{&g_94[2],(void*)0,&g_380,&g_94[2],(void*)0,&g_380,&g_94[1]},{&g_380,&g_94[2],&g_94[2],&g_94[2],(void*)0,&g_149,&g_380},{&g_149,&g_380,&g_94[2],&g_149,&g_94[2],&g_94[2],&g_94[2]},{&g_380,(void*)0,&g_94[2],&g_149,&g_149,&g_380,&g_149},{&g_94[2],&g_149,&g_380,&g_94[2],&g_94[1],&g_94[2],&g_94[2]},{&g_149,&g_380,&g_380,&g_94[2],&g_380,&g_94[2],&g_380},{&g_94[0],&g_94[0],&g_94[2],&g_380,&g_94[0],&g_94[2],&g_94[1]}},{{&g_94[2],&g_94[0],&g_94[2],&g_94[2],&g_94[2],&g_380,&g_94[2]},{&g_380,&g_380,&g_94[2],&g_94[0],&g_94[0],&g_94[2],&g_149},{&g_380,&g_149,&g_380,&g_149,&g_380,&g_149,&g_94[2]},{&g_94[2],(void*)0,&g_149,&g_94[0],&g_94[1],&g_380,&g_94[2]},{&g_94[0],&g_380,&g_94[2],&g_94[2],&g_149,&g_149,&g_149},{&g_149,&g_94[2],&g_149,&g_380,&g_94[2],&g_149,&g_94[2]},{&g_94[2],(void*)0,&g_380,&g_94[2],(void*)0,&g_380,&g_94[1]}}};\r\n int32_t l_565 = 0x56C2B96EL;\r\n uint16_t l_566[10][7] = {{0x136DL,0UL,0x0D3AL,0UL,0x136DL,0xF559L,4UL},{0UL,0UL,0xE1E7L,0x5533L,2UL,0x5533L,0xE1E7L},{4UL,4UL,0UL,0x0D3AL,0xFD06L,0xFB9BL,0xF306L},{0UL,0x5533L,1UL,1UL,0x5533L,0UL,2UL},{0x136DL,0UL,0UL,0xDCD5L,0xFD06L,0xFD06L,0xDCD5L},{2UL,0x92D3L,2UL,65535UL,2UL,0xE80DL,0UL},{0UL,0UL,0x136DL,0xFB9BL,0x136DL,0UL,0UL},{1UL,0x5533L,0UL,2UL,0x852DL,0xE80DL,0x852DL},{0UL,4UL,4UL,4UL,0xF559L,0x136DL,0UL},{0x92D3L,0xE80DL,2UL,0x5533L,0x5533L,2UL,0xE80DL}};\r\n int i, j, k;\r\n l_567 = (safe_div_func_int32_t_s_s(((*l_312) ^= (!(**g_372))), (safe_lshift_func_int32_t_s_s((p_9 == ((((((*l_314) ^= l_549) || (((--(*l_30)) && ((*g_373) >= (safe_sub_func_uint8_t_u_u(p_9, ((*l_319) = (((safe_mod_func_int64_t_s_s(((*l_425) = (safe_mod_func_uint16_t_u_u(((l_536 = ((safe_mul_func_uint16_t_u_u(g_346[3], (((((safe_sub_func_int8_t_s_s((safe_add_func_uint32_t_u_u((&g_380 != l_564[2][0][2]), ((0xDD250ABB124CD325LL < g_409) >= (*g_373)))), g_407)) , (*g_373)) < l_565) , &g_185) != (void*)0))) , p_9)) < p_9), p_9))), 0xEEC46540531036A0LL)) == 4294967288UL) < g_412)))))) != 0x6A948BE95CCE685BLL)) != p_9) , l_566[0][3]) , g_366[3][0])), p_9))));\r\n (**g_256) |= ((void*)0 != &g_407);\r\n if (p_9)\r\n break;\r\n }\r\n }\r\n }\r\n return p_9;\r\n}\r\n\r\n\r\n\r\n\r\nstatic int16_t func_15(int8_t p_16, uint32_t p_17, int32_t p_18)\r\n{ \r\n uint16_t l_43[8][6] = {{4UL,0x864FL,65527UL,0x864FL,4UL,65527UL},{0x864FL,4UL,65527UL,0x11FBL,0x11FBL,65527UL},{0x11FBL,0x11FBL,65527UL,4UL,0x864FL,65527UL},{4UL,0x864FL,65527UL,0x864FL,4UL,65527UL},{0x864FL,4UL,65527UL,0x11FBL,0x11FBL,65527UL},{0x11FBL,0x11FBL,65527UL,4UL,0x864FL,65527UL},{4UL,0x864FL,65527UL,0x864FL,4UL,65527UL},{0x864FL,4UL,65527UL,0x11FBL,0x11FBL,65527UL}};\r\n int32_t l_54 = 1L;\r\n int32_t l_55 = 0x1814A667L;\r\n int32_t l_57 = 0xF053B50BL;\r\n int32_t l_58[8];\r\n int64_t *l_83 = &g_66[3][3];\r\n int32_t l_106[2];\r\n int32_t *l_111 = (void*)0;\r\n int32_t **l_110[9] = {(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0};\r\n int32_t ***l_109 = &l_110[8];\r\n const int32_t l_145 = (-1L);\r\n int64_t *l_156 = &g_157[0];\r\n int8_t *l_164 = &g_165;\r\n uint16_t l_166 = 4UL;\r\n int16_t *l_167 = &g_168;\r\n int64_t *l_171 = (void*)0;\r\n int64_t *l_172 = &g_157[8];\r\n uint32_t l_196 = 4294967295UL;\r\n uint16_t l_199 = 4UL;\r\n int8_t l_288 = 0L;\r\n int8_t l_291 = (-5L);\r\n uint32_t l_302 = 18446744073709551615UL;\r\n int i, j;\r\n for (i = 0; i < 8; i++)\r\n l_58[i] = 0xE0FBC7DBL;\r\n for (i = 0; i < 2; i++)\r\n l_106[i] = (-1L);\r\nlbl_244:\r\n for (g_31 = 0; (g_31 <= 0); g_31 += 1)\r\n { \r\n int32_t l_52[5] = {0x50B10B9BL,0x50B10B9BL,0x50B10B9BL,0x50B10B9BL,0x50B10B9BL};\r\n uint16_t l_108 = 1UL;\r\n int i;\r\n if (g_11[(g_31 + 1)])\r\n break;\r\n if (g_11[(g_31 + 1)])\r\n break;\r\n for (p_18 = 0; (p_18 <= 0); p_18 += 1)\r\n { \r\n int32_t *l_38 = &g_11[(g_31 + 1)];\r\n int32_t l_53 = 0x2DAC39F6L;\r\n int32_t l_56[8][5][2] = {{{0xEDC4196DL,0x55470A06L},{0xFFFF0E59L,0L},{6L,0xEDC4196DL},{(-1L),9L},{2L,0x62CF0DA5L}},{{0x2A43FB2FL,0xFFFF0E59L},{0x7A36831AL,0x7A36831AL},{(-1L),6L},{0x28A4BD3CL,0xEF314FBCL},{0xFB4D153BL,0L}},{{0x1831F773L,0xFB4D153BL},{9L,0x0066401EL},{9L,0xFB4D153BL},{0x1831F773L,0L},{0xFB4D153BL,0xEF314FBCL}},{{0x28A4BD3CL,6L},{(-1L),0x7A36831AL},{0x7A36831AL,0xFFFF0E59L},{0x2A43FB2FL,0x62CF0DA5L},{2L,9L}},{{(-1L),0xEDC4196DL},{6L,0L},{0xFFFF0E59L,0x55470A06L},{0xEDC4196DL,0x55470A06L},{0xFFFF0E59L,0L}},{{6L,0xEDC4196DL},{(-1L),9L},{2L,0x62CF0DA5L},{0x2A43FB2FL,0xFFFF0E59L},{0x7A36831AL,0x7A36831AL}},{{(-1L),6L},{0x28A4BD3CL,0xEF314FBCL},{0xFB4D153BL,0L},{0x1831F773L,0xFB4D153BL},{9L,0x0066401EL}},{{9L,0xFB4D153BL},{0x1831F773L,0L},{0xFB4D153BL,0xEF314FBCL},{0x28A4BD3CL,6L},{(-1L),0x7A36831AL}}};\r\n uint8_t l_59[3];\r\n int i, j, k;\r\n for (i = 0; i < 3; i++)\r\n l_59[i] = 0x9FL;\r\n if (p_18)\r\n { \r\n const int32_t *l_34 = &g_11[0];\r\n int32_t *l_37 = &g_11[1];\r\n int32_t **l_36[5][1][4] = {{{&l_37,&l_37,&l_37,&l_37}},{{&l_37,&l_37,&l_37,&l_37}},{{&l_37,&l_37,&l_37,&l_37}},{{&l_37,&l_37,&l_37,&l_37}},{{&l_37,&l_37,&l_37,&l_37}}};\r\n int32_t ***l_39 = &l_36[3][0][1];\r\n int i, j, k;\r\n g_35 = l_34;\r\n g_11[g_31] = 0x10944B0CL;\r\n l_38 = &g_11[1];\r\n g_11[g_31] = (((*l_39) = (void*)0) == &l_38);\r\n }\r\n else\r\n { \r\n int32_t *l_40 = &g_11[0];\r\n int32_t *l_41 = &g_11[(g_31 + 1)];\r\n int32_t *l_42[3][7] = {{&g_11[(g_31 + 1)],&g_11[(g_31 + 1)],&g_11[1],&g_11[1],&g_11[(g_31 + 1)],&g_11[(g_31 + 1)],&g_11[1]},{&g_11[1],&g_11[(g_31 + 1)],&g_11[1],&g_11[(g_31 + 1)],&g_11[1],&g_11[(g_31 + 1)],&g_11[1]},{&g_11[(g_31 + 1)],&g_11[1],&g_11[1],&g_11[(g_31 + 1)],&g_11[(g_31 + 1)],&g_11[1],&g_11[1]}};\r\n int i, j;\r\n l_43[0][0]--;\r\n }\r\n for (p_17 = 0; (p_17 <= 0); p_17 += 1)\r\n { \r\n int32_t *l_46 = &g_11[1];\r\n int32_t *l_47 = &g_11[1];\r\n int32_t *l_48 = &g_11[1];\r\n int32_t *l_49 = &g_11[1];\r\n int32_t *l_50 = &g_11[0];\r\n int32_t *l_51[3][10] = {{(void*)0,(void*)0,&g_11[1],(void*)0,(void*)0,&g_11[1],(void*)0,(void*)0,&g_11[1],(void*)0},{(void*)0,&g_11[1],&g_11[1],(void*)0,&g_11[1],&g_11[1],(void*)0,&g_11[1],&g_11[1],(void*)0},{&g_11[1],(void*)0,&g_11[1],&g_11[1],(void*)0,&g_11[1],&g_11[1],(void*)0,&g_11[1],&g_11[1]}};\r\n int32_t **l_62[7][7] = {{&l_38,&l_38,&l_47,&l_38,&l_38,&l_47,&l_38},{(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0},{&l_51[1][6],&l_38,&l_51[1][6],&l_51[1][6],&l_38,&l_51[1][6],&l_51[1][6]},{(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0},{&l_38,&l_51[1][6],&l_51[1][6],&l_38,&l_51[1][6],&l_51[1][6],&l_38},{(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0,(void*)0},{&l_38,&l_38,&l_47,&l_38,&l_38,&l_47,&l_38}};\r\n int i, j;\r\n --l_59[0];\r\n g_35 = l_51[1][6];\r\n }\r\n if ((*l_38))\r\n continue;\r\n for (l_53 = 0; (l_53 <= 1); l_53 += 1)\r\n { \r\n int i, j, k;\r\n return l_56[(g_31 + 6)][(l_53 + 2)][p_18];\r\n }\r\n for (l_54 = 0; (l_54 >= 0); l_54 -= 1)\r\n { \r\n int64_t *l_65 = &g_66[3][3];\r\n int64_t **l_84 = (void*)0;\r\n int64_t **l_85 = &l_65;\r\n int64_t *l_87[8] = {&g_66[2][3],&g_66[4][1],&g_66[4][1],&g_66[2][3],&g_66[4][1],&g_66[4][1],&g_66[2][3],&g_66[4][1]};\r\n int64_t **l_86 = &l_87[7];\r\n uint32_t *l_93[3];\r\n int32_t l_104 = 0L;\r\n int32_t l_105[1];\r\n uint32_t l_107 = 0UL;\r\n int32_t l_112 = 0x2EFCB156L;\r\n int i;\r\n for (i = 0; i < 3; i++)\r\n l_93[i] = &g_94[2];\r\n for (i = 0; i < 1; i++)\r\n l_105[i] = 0L;\r\n l_112 &= ((((safe_mul_func_uint8_t_u_u(((((*l_65) &= 1L) , (safe_div_func_int32_t_s_s((safe_div_func_uint32_t_u_u((((((((safe_rshift_func_uint32_t_u_s(g_11[(g_31 + 1)], ((safe_div_func_int8_t_s_s(((((safe_mul_func_int64_t_s_s(((safe_sub_func_int16_t_s_s(p_16, (p_16 <= ((!(safe_mul_func_int64_t_s_s(((*l_83) = (~(l_105[0] ^= ((((*l_85) = l_83) == ((*l_86) = (void*)0)) >= ((((((+(safe_mul_func_uint8_t_u_u(0x1FL, (safe_sub_func_uint32_t_u_u((g_94[2]--), (+(safe_mul_func_int64_t_s_s(((safe_mod_func_uint32_t_u_u(g_11[1], (safe_sub_func_uint16_t_u_u(((g_12 <= g_11[(g_31 + 1)]) >= g_12), 7L)))) != p_16), l_55)))))))) == l_104) , 0x02DFE65AL) , p_17) , g_12) ^ 0xA833846322F5C3AALL))))), g_31))) < l_106[0])))) , l_107), 0UL)) , l_104) & 0x93ACL) > p_16), g_11[1])) , l_108))) , 4L) <= l_58[7]) , l_109) != (void*)0) & p_16) < p_16), 4294967291UL)), p_17))) & p_16), g_12)) != l_52[3]) , p_17) ^ 0x0A3500CD5182C662LL);\r\n }\r\n }\r\n }\r\n for (p_17 = 1; (p_17 <= 5); p_17 += 1)\r\n { \r\n int64_t * const *l_114 = (void*)0;\r\n int32_t l_115 = 0xC0B326B5L;\r\n int32_t l_122 = (-1L);\r\n int32_t l_128 = 3L;\r\n int32_t l_129 = (-6L);\r\n int32_t ***l_144 = &l_110[3];\r\n for (g_12 = 0; (g_12 <= 5); g_12 += 1)\r\n { \r\n int i, j;\r\n if (l_43[g_12][g_12])\r\n break;\r\n for (p_18 = 0; (p_18 <= 8); p_18 += 1)\r\n { \r\n return p_17;\r\n }\r\n for (g_31 = 0; (g_31 <= 7); g_31 += 1)\r\n { \r\n int i;\r\n l_58[g_31] = (~p_18);\r\n if (p_16)\r\n continue;\r\n g_11[1] = (((0x33A8E694L & p_18) , 0xE34AC405L) & (((void*)0 == l_114) , 0x7FEED684L));\r\n }\r\n }\r\n if (p_16)\r\n { \r\n uint64_t l_116 = 0xDCA698BDAB2CB753LL;\r\n int32_t l_119 = (-7L);\r\n int32_t l_123 = 0xDAE3C54FL;\r\n int32_t l_125 = 0x5C04B26AL;\r\n int32_t l_127[4][3] = {{1L,1L,0x4C425AE9L},{1L,1L,0x4C425AE9L},{1L,1L,0x4C425AE9L},{1L,1L,0x4C425AE9L}};\r\n uint32_t *l_146 = (void*)0;\r\n uint32_t *l_147 = (void*)0;\r\n uint32_t *l_148 = &g_149;\r\n int i, j;\r\n l_115 = l_115;\r\n for (p_18 = 1; (p_18 <= 5); p_18 += 1)\r\n { \r\n int16_t l_120 = 0xDB9CL;\r\n int32_t l_121 = 0x49656563L;\r\n int32_t l_124[1][4] = {{0x080E9152L,0x080E9152L,0x080E9152L,0x080E9152L}};\r\n int32_t l_126 = (-6L);\r\n uint16_t l_130 = 0x6C88L;\r\n int i, j;\r\n --l_116;\r\n l_130++;\r\n }\r\n g_11[0] = ((l_127[1][0] = ((1L ^ (safe_mod_func_int16_t_s_s(((g_94[1] , (safe_add_func_int16_t_s_s(((l_83 != &l_116) < ((((+((*l_148) ^= (g_94[1] = ((safe_mul_func_int32_t_s_s(((((safe_mul_func_int32_t_s_s((g_11[1] , (g_33[8][0][8] > (((((safe_mod_func_uint8_t_u_u(0xB6L, ((g_31 <= (((l_115 >= 1UL) < g_94[2]) < p_16)) , p_17))) , 0xB692CA01L) , &l_110[8]) == l_144) | g_94[2]))), g_31)) , (void*)0) != (void*)0) , p_17), l_145)) | 0x7FL)))) != 1L) != l_123) && p_17)), p_18))) || p_16), g_12))) || (-1L))) == 4294967292UL);\r\n }\r\n else\r\n { \r\n int32_t **l_150 = (void*)0;\r\n l_150 = (*l_144);\r\n }\r\n return g_33[6][0][7];\r\n }\r\n if (((g_66[3][3] && 0x44L) | (((*l_172) = (&g_11[0] == (g_170 = (g_169 = ((!(safe_lshift_func_int8_t_s_u(((safe_mul_func_uint8_t_u_u((g_12 , (((l_83 == (l_156 = l_83)) || g_94[1]) == (((*l_167) = (safe_div_func_uint16_t_u_u((0x63AD2DFDL > (safe_mul_func_int8_t_s_s(((*l_164) ^= (safe_add_func_uint64_t_u_u(g_33[2][0][2], 0UL))), l_166))), g_33[8][0][8]))) <= g_11[1]))), p_17)) >= (-1L)), 6))) , &g_11[1]))))) , 0L)))\r\n { \r\n uint16_t l_173 = 1UL;\r\n uint32_t *l_186[9];\r\n int64_t *l_188[5] = {&g_66[3][3],&g_66[3][3],&g_66[3][3],&g_66[3][3],&g_66[3][3]};\r\n int32_t l_193 = 1L;\r\n int32_t ***l_257 = &g_256;\r\n uint64_t *l_276[9] = {&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8],&g_33[7][0][8]};\r\n int32_t l_283 = (-9L);\r\n int32_t l_287 = 0L;\r\n int32_t l_292 = 0x1C44CF0EL;\r\n int32_t l_293 = 0x11BC2BF2L;\r\n int32_t l_295 = 0xE1623BE8L;\r\n int32_t l_296[1][9] = {{0xD646E06EL,0xD646E06EL,0x34B75A98L,0xD646E06EL,0xD646E06EL,0x34B75A98L,0xD646E06EL,0xD646E06EL,0x34B75A98L}};\r\n uint16_t l_299 = 0x0AFDL;\r\n uint16_t l_305 = 0xFAD6L;\r\n int i, j;\r\n for (i = 0; i < 9; i++)\r\n l_186[i] = &g_149;\r\nlbl_267:\r\n ++l_173;\r\n for (l_55 = 0; (l_55 <= 5); l_55 += 1)\r\n { \r\n uint8_t *l_184 = &g_185;\r\n int64_t * const l_187 = &g_66[3][3];\r\n int64_t **l_191 = &l_172;\r\n const uint8_t l_192 = 0x7EL;\r\n int32_t l_236 = 1L;\r\n int i;\r\n if ((safe_div_func_uint8_t_u_u((safe_mod_func_int32_t_s_s((*g_170), ((safe_mod_func_uint8_t_u_u((((*l_184) = (l_164 != &p_16)) || (((((((l_186[6] = l_111) != &g_94[2]) , l_187) == l_188[3]) == (safe_rshift_func_uint32_t_u_u(g_33[2][0][5], (((*l_191) = &g_157[3]) != &g_66[3][3])))) > 0xB3L) != l_173)), 3L)) , p_17))), l_192)))\r\n { \r\n int32_t l_194 = 0xBE4B794FL;\r\n int32_t l_195[8] = {0xFA8EE88EL,0xFA8EE88EL,0x2CC03310L,0xFA8EE88EL,0xFA8EE88EL,0x2CC03310L,0xFA8EE88EL,0xFA8EE88EL};\r\n int i;\r\n ++l_196;\r\n g_170 = &g_11[1];\r\n return g_33[6][0][6];\r\n }\r\n else\r\n { \r\n --l_199;\r\n }\r\n for (g_165 = 0; (g_165 <= 8); g_165 += 1)\r\n { \r\n int i, j;\r\n (*g_170) ^= l_43[l_55][l_55];\r\n return g_157[(l_55 + 1)];\r\n }\r\n for (g_12 = 1; (g_12 <= 5); g_12 += 1)\r\n { \r\n uint64_t l_239 = 0xCCD539717E3722A4LL;\r\n int i, j;\r\n (*g_169) = (safe_mod_func_int8_t_s_s((safe_mul_func_int8_t_s_s((safe_div_func_int32_t_s_s((safe_sub_func_uint32_t_u_u((safe_mod_func_uint16_t_u_u((safe_rshift_func_uint16_t_u_u(((l_193 = (((safe_mod_func_uint64_t_u_u(p_16, (safe_sub_func_uint8_t_u_u(((*l_184)++), ((((safe_unary_minus_func_uint32_t_u((((safe_mul_func_int16_t_s_s((0L ^ l_173), ((((safe_sub_func_uint16_t_u_u((safe_add_func_int64_t_s_s(p_17, (((safe_sub_func_uint16_t_u_u(p_18, (l_43[(g_12 + 1)][g_12] |= (((safe_add_func_int16_t_s_s(((g_33[0][0][2]++) || (!l_173)), ((l_236 = 0x9C1AF257L) >= (*g_169)))) < (safe_lshift_func_int32_t_s_u((*g_169), 5))) || g_33[8][0][8])))) < l_193) ^ g_11[1]))), g_168)) , g_149) , g_66[3][3]) , 0x3A3CL))) & l_239) , p_17))) < l_239) > l_193) >= 18446744073709551607UL))))) , (-1L)) != g_12)) ^ 0x81AF9209L), 2)), g_165)), (*g_169))), g_157[2])), g_165)), g_94[2]));\r\n (*g_170) = p_18;\r\n }\r\n for (l_173 = 1; (l_173 <= 5); l_173 += 1)\r\n { \r\n l_193 = (-1L);\r\n return g_33[8][0][8];\r\n }\r\n }\r\n for (g_165 = 0; (g_165 >= (-25)); g_165--)\r\n { \r\n uint8_t *l_251[10][10][2] = {{{&g_185,(void*)0},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,(void*)0},{&g_185,&g_185}},{{(void*)0,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185}},{{&g_185,&g_185},{&g_185,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,(void*)0},{&g_185,&g_185}},{{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{(void*)0,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,&g_185}},{{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,(void*)0},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,&g_185},{&g_185,(void*)0}},{{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{&g_185,(void*)0},{&g_185,(void*)0},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,&g_185}},{{&g_185,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{(void*)0,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185}},{{&g_185,&g_185},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,(void*)0},{&g_185,&g_185}},{{(void*)0,&g_185},{&g_185,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{&g_185,(void*)0},{&g_185,(void*)0}},{{&g_185,&g_185},{(void*)0,&g_185},{&g_185,&g_185},{&g_185,&g_185},{&g_185,(void*)0},{&g_185,&g_185},{&g_185,&g_185},{(void*)0,&g_185},{&g_185,(void*)0},{(void*)0,&g_185}}};\r\n int32_t l_252[2];\r\n int32_t l_266 = (-9L);\r\n int64_t *l_274 = &g_157[7];\r\n int32_t l_289[7] = {0xA2D0A057L,0xA2D0A057L,0xA2D0A057L,0xA2D0A057L,0xA2D0A057L,0xA2D0A057L,0xA2D0A057L};\r\n int i, j, k;\r\n for (i = 0; i < 2; i++)\r\n l_252[i] = 0L;\r\n for (p_16 = (-8); (p_16 > (-2)); p_16++)\r\n { \r\n if (g_168)\r\n goto lbl_244;\r\n }\r\n if (((safe_sub_func_int16_t_s_s((((safe_add_func_int16_t_s_s((safe_lshift_func_uint8_t_u_s((l_252[1] ^= (g_149 , p_16)), (((p_16 > (((0xA6BC4429L & (g_255 != l_257)) ^ (((safe_mul_func_int64_t_s_s((g_33[8][0][8] || ((safe_add_func_uint64_t_u_u((safe_mul_func_uint64_t_u_u(((safe_add_func_int8_t_s_s(g_12, l_266)) , 0x221D217DB600C3A3LL), 0xF75A03B73B3FD032LL)), g_33[8][0][8])) | g_157[0])), 0x36BB0D7DC54451A0LL)) != 0xE35EL) <= g_149)) < 4294967293UL)) | p_16) | l_266))), g_33[3][0][6])) > 1UL) , g_33[1][0][6]), g_66[1][1])) | p_16))\r\n { \r\n if ((***g_255))\r\n break;\r\n }\r\n else\r\n { \r\n uint16_t l_270[10] = {0x99BCL,0x1F3FL,0x2820L,0x2820L,0x1F3FL,0x99BCL,0x1F3FL,0x2820L,0x2820L,0x1F3FL};\r\n int64_t **l_275 = &l_188[4];\r\n int32_t l_284 = (-1L);\r\n int32_t l_285 = 1L;\r\n int32_t l_286 = 0x8B011B8DL;\r\n int32_t l_290 = 1L;\r\n int32_t l_294 = 0x4EF4180CL;\r\n int32_t l_297 = (-1L);\r\n int32_t l_298[9] = {9L,9L,9L,9L,9L,9L,9L,9L,9L};\r\n int i;\r\n if (l_55)\r\n goto lbl_267;\r\n (***g_255) = (g_31 == g_66[3][3]);\r\n (***l_257) ^= ((safe_add_func_int32_t_s_s(l_270[0], (((safe_sub_func_int32_t_s_s((0x1737AA7C1C7358A4LL && g_157[3]), (((safe_unary_minus_func_int16_t_s(((((*l_275) = l_274) != (void*)0) != ((void*)0 != l_276[5])))) <= (safe_rshift_func_int32_t_s_s((safe_div_func_uint64_t_u_u((safe_add_func_uint16_t_u_u(g_33[8][0][8], g_94[2])), l_270[0])), l_252[1]))) & g_168))) , 4294967295UL) , p_16))) , p_16);\r\n --l_299;\r\n }\r\n l_302++;\r\n g_306 &= (l_305 = (***l_257));\r\n }\r\n }\r\n else\r\n { \r\n uint8_t l_307[9][7] = {{0x0DL,0x0DL,1UL,0xE6L,1UL,1UL,1UL},{0xE6L,255UL,255UL,0xE6L,0UL,246UL,0xE6L},{246UL,1UL,0UL,0UL,0UL,0x22L,1UL},{0UL,255UL,0x0DL,246UL,246UL,0x0DL,255UL},{0UL,1UL,0x22L,0UL,9UL,9UL,0UL},{0x22L,255UL,0x22L,9UL,255UL,1UL,1UL},{255UL,0UL,0x0DL,0UL,255UL,0x0DL,246UL},{246UL,1UL,9UL,246UL,9UL,1UL,246UL},{0x22L,246UL,1UL,9UL,246UL,9UL,1UL}};\r\n int i, j;\r\n --l_307[0][5];\r\n }\r\n return p_16;\r\n}\r\n\r\n\r\n\r\n\r\n\r\nint main (int argc, char* argv[])\r\n{\r\n int i, j, k;\r\n int print_hash_value = 0;\r\n if (argc == 2 && strcmp(argv[1], \"1\") == 0) print_hash_value = 1;\r\n platform_main_begin();\r\n crc32_gentab();\r\n func_1();\r\n for (i = 0; i < 2; i++)\r\n {\r\n transparent_crc(g_11[i], \"g_11[i]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d]\\n\", i);\r\n\r\n }\r\n transparent_crc(g_12, \"g_12\", print_hash_value);\r\n transparent_crc(g_31, \"g_31\", print_hash_value);\r\n for (i = 0; i < 9; i++)\r\n {\r\n for (j = 0; j < 1; j++)\r\n {\r\n for (k = 0; k < 9; k++)\r\n {\r\n transparent_crc(g_33[i][j][k], \"g_33[i][j][k]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d][%d][%d]\\n\", i, j, k);\r\n\r\n }\r\n }\r\n }\r\n for (i = 0; i < 5; i++)\r\n {\r\n for (j = 0; j < 4; j++)\r\n {\r\n transparent_crc(g_66[i][j], \"g_66[i][j]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d][%d]\\n\", i, j);\r\n\r\n }\r\n }\r\n for (i = 0; i < 3; i++)\r\n {\r\n transparent_crc(g_94[i], \"g_94[i]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d]\\n\", i);\r\n\r\n }\r\n transparent_crc(g_149, \"g_149\", print_hash_value);\r\n for (i = 0; i < 9; i++)\r\n {\r\n transparent_crc(g_157[i], \"g_157[i]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d]\\n\", i);\r\n\r\n }\r\n transparent_crc(g_165, \"g_165\", print_hash_value);\r\n transparent_crc(g_168, \"g_168\", print_hash_value);\r\n transparent_crc(g_185, \"g_185\", print_hash_value);\r\n transparent_crc(g_306, \"g_306\", print_hash_value);\r\n transparent_crc(g_311, \"g_311\", print_hash_value);\r\n transparent_crc(g_313, \"g_313\", print_hash_value);\r\n transparent_crc(g_341, \"g_341\", print_hash_value);\r\n for (i = 0; i < 6; i++)\r\n {\r\n transparent_crc(g_346[i], \"g_346[i]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d]\\n\", i);\r\n\r\n }\r\n for (i = 0; i < 6; i++)\r\n {\r\n for (j = 0; j < 2; j++)\r\n {\r\n transparent_crc(g_366[i][j], \"g_366[i][j]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d][%d]\\n\", i, j);\r\n\r\n }\r\n }\r\n transparent_crc(g_380, \"g_380\", print_hash_value);\r\n transparent_crc(g_407, \"g_407\", print_hash_value);\r\n transparent_crc(g_409, \"g_409\", print_hash_value);\r\n transparent_crc(g_412, \"g_412\", print_hash_value);\r\n transparent_crc(g_414, \"g_414\", print_hash_value);\r\n for (i = 0; i < 5; i++)\r\n {\r\n for (j = 0; j < 10; j++)\r\n {\r\n transparent_crc(g_416[i][j], \"g_416[i][j]\", print_hash_value);\r\n if (print_hash_value) printf(\"index = [%d][%d]\\n\", i, j);\r\n\r\n }\r\n }\r\n transparent_crc(g_426, \"g_426\", print_hash_value);\r\n transparent_crc(g_457, \"g_457\", print_hash_value);\r\n platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);\r\n return 0;\r\n}\r\n\r\n/************************ statistics *************************\r\nXXX max struct depth: 0\r\nbreakdown:\r\n depth: 0, occurrence: 138\r\nXXX total union variables: 0\r\n\r\nXXX max expression depth: 48\r\nbreakdown:\r\n depth: 1, occurrence: 114\r\n depth: 2, occurrence: 28\r\n depth: 3, occurrence: 1\r\n depth: 4, occurrence: 1\r\n depth: 5, occurrence: 1\r\n depth: 6, occurrence: 2\r\n depth: 16, occurrence: 1\r\n depth: 17, occurrence: 2\r\n depth: 18, occurrence: 2\r\n depth: 19, occurrence: 1\r\n depth: 24, occurrence: 1\r\n depth: 25, occurrence: 1\r\n depth: 28, occurrence: 1\r\n depth: 29, occurrence: 1\r\n depth: 30, occurrence: 1\r\n depth: 31, occurrence: 1\r\n depth: 32, occurrence: 1\r\n depth: 34, occurrence: 3\r\n depth: 38, occurrence: 1\r\n depth: 43, occurrence: 1\r\n depth: 48, occurrence: 1\r\n\r\nXXX total number of pointers: 101\r\n\r\nXXX times a variable address is taken: 515\r\nXXX times a pointer is dereferenced on RHS: 36\r\nbreakdown:\r\n depth: 1, occurrence: 32\r\n depth: 2, occurrence: 2\r\n depth: 3, occurrence: 2\r\nXXX times a pointer is dereferenced on LHS: 69\r\nbreakdown:\r\n depth: 1, occurrence: 59\r\n depth: 2, occurrence: 7\r\n depth: 3, occurrence: 3\r\nXXX times a pointer is compared with null: 5\r\nXXX times a pointer is compared with address of another variable: 5\r\nXXX times a pointer is compared with another pointer: 3\r\nXXX times a pointer is qualified to be dereferenced: 1932\r\n\r\nXXX max dereference level: 3\r\nbreakdown:\r\n level: 0, occurrence: 0\r\n level: 1, occurrence: 190\r\n level: 2, occurrence: 35\r\n level: 3, occurrence: 30\r\nXXX number of pointers point to pointers: 36\r\nXXX number of pointers point to scalars: 65\r\nXXX number of pointers point to structs: 0\r\nXXX percent of pointers has null in alias set: 38.6\r\nXXX average alias set size: 1.44\r\n\r\nXXX times a non-volatile is read: 427\r\nXXX times a non-volatile is write: 241\r\nXXX times a volatile is read: 0\r\nXXX times read thru a pointer: 0\r\nXXX times a volatile is write: 0\r\nXXX times written thru a pointer: 0\r\nXXX times a volatile is available for access: 0\r\nXXX percentage of non-volatile access: 100\r\n\r\nXXX forward jumps: 0\r\nXXX backward jumps: 2\r\n\r\nXXX stmts: 111\r\nXXX max block depth: 3\r\nbreakdown:\r\n depth: 0, occurrence: 13\r\n depth: 1, occurrence: 17\r\n depth: 2, occurrence: 28\r\n depth: 3, occurrence: 53\r\n\r\nXXX percentage a fresh-made variable is used: 16.5\r\nXXX percentage an existing variable is used: 83.5\r\nXXX total OOB instances added: 0\r\n********************* end of statistics **********************/\r\n\r\n```" } ] }
true
null
107198
https://github.com/llvm/llvm-project/issues/107198
crash
c2b92a4250b3f514685676ba8985ea73450f14d3
2024-09-04T08:17:58
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "d65ff3e9364536f9e0bd5f1c1bace626c256a2ad", "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": [ [ 7780, 7785 ] ], "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::canMapToVector" ], "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 d65ff3e9364536f9e0bd5f1c1bace626c256a2ad Author: Alexey Bataev <[email protected]> Date: Wed Sep 4 05:12:17 2024 -0700 [SLP]Fix PR107198: add a check for empty complex type Need to check if the complex type is empty before trying to dig in, trying to find vectorizable type Fixes https://github.com/llvm/llvm-project/issues/107198 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 19b95cf473e9..a2af7f4e1b01 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7780,6 +7780,8 @@ unsigned BoUpSLP::canMapToVector(Type *T) const { Type *EltTy = T; while (isa<StructType, ArrayType, FixedVectorType>(EltTy)) { + if (EltTy->isEmptyTy()) + return 0; if (auto *ST = dyn_cast<StructType>(EltTy)) { // Check that struct is homogeneous. for (const auto *Ty : ST->elements())
[ { "file": "llvm/test/Transforms/SLPVectorizer/empty-struct.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "test", "test_body": "define { { {}, {}, {}, {}, {}, {}, {} } } @test({ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0) {\n %2 = extractvalue { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0, 18\n %3 = insertvalue { { {}, {}, {}, {}, {}, {}, {} } } undef, { {}, {}, {}, {}, {}, {}, {} } %2, 0\n ret { { {}, {}, {}, {}, {}, {}, {} } } %3\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Crash on slp-vectorizer", "body": "When running `/opt/llvm-19/bin/opt -O3 -S bug.ll` opt crashes with the following:\r\n\r\n(tested on 19 rc2 and rc4 and 18)\r\n```\r\n/opt/llvm-19/bin/llvm-config --version\r\n19.1.0-rc2\r\n\r\n/opt/llvm-19/bin/opt: WARNING: failed to create target machine for 'arm64-apple-darwin23.6.0': unable to get target for 'arm64-apple-darwin23.6.0', see --version and --triple.\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/llvm-19/bin/opt -O3 -S bug.ll\r\n1.\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-use-loop-info;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;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;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"lol.ll\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"bug\"\r\n #0 0x00005558779163f7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/admin/repos/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13\r\n #1 0x0000555877914570 llvm::sys::RunSignalHandlers() /home/admin/repos/llvm-project/llvm/lib/Support/Signals.cpp:106:18\r\n #2 0x0000555877916d9a SignalHandler(int) /home/admin/repos/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1\r\n #3 0x00007fb7b7e5b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)\r\n #4 0x0000555878d08ae0 llvm::slpvectorizer::BoUpSLP::canMapToVector(llvm::Type*) const /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:0\r\n #5 0x0000555878d3ca29 llvm::SLPVectorizerPass::vectorizeInsertValueInst(llvm::InsertValueInst*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, bool) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:18336:8\r\n #6 0x0000555878d3d459 llvm::SLPVectorizerPass::vectorizeInserts(llvm::SmallSetVector<llvm::Instruction*, 8u>&, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:0:11\r\n #7 0x0000555878d3e35b llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::$_172::operator()(bool) const /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:18847:20\r\n #8 0x0000555878d34039 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:18963:18\r\n #9 0x0000555878d31968 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:15865:13\r\n#10 0x0000555878d31431 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/admin/repos/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:15796:18\r\n#11 0x0000555878921dfd llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:5\r\n#12 0x0000555877ab570d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:8\r\n#13 0x00005558785d887d 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/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:5\r\n#14 0x0000555877ab94f0 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/admin/repos/llvm-project/llvm/lib/IR/PassManager.cpp:129:23\r\n#15 0x00005558785d86cd llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:5\r\n#16 0x0000555877ab44ed llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/admin/repos/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:8\r\n#17 0x00005558788ca8c9 llvm::SmallPtrSetImplBase::isSmall() const /home/admin/repos/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:197:33\r\n#18 0x00005558788ca8c9 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /home/admin/repos/llvm-project/llvm/include/llvm/ADT/SmallPtrSet.h:84:10\r\n#19 0x00005558788ca8c9 llvm::PreservedAnalyses::~PreservedAnalyses() /home/admin/repos/llvm-project/llvm/include/llvm/IR/Analysis.h:111:7\r\n#20 0x00005558788ca8c9 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/admin/repos/llvm-project/llvm/tools/opt/NewPMDriver.cpp:547:3\r\n#21 0x00005558778e5779 optMain /home/admin/repos/llvm-project/llvm/tools/opt/optdriver.cpp:739:12\r\n#22 0x00007fb7b7e4624a (/lib/x86_64-linux-gnu/libc.so.6+0x2724a)\r\n#23 0x00007fb7b7e46305 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27305)\r\n#24 0x00005558778dfd21 _start (/opt/llvm-19/bin/opt+0xf17d21)\r\nSegmentation fault\r\n```\r\n\r\n```llvmir\r\n; ModuleID = 'LLVMDialectModule'\r\nsource_filename = \"LLVMDialectModule\"\r\ntarget datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"arm64-apple-darwin23.6.0\"\r\n\r\ndefine { { {}, {}, {}, {}, {}, {}, {} } } @\"bug\"({ {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0) {\r\n %2 = extractvalue { {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, { {}, {}, {}, {}, {}, {}, {} }, { {} } } %0, 18\r\n %3 = insertvalue { { {}, {}, {}, {}, {}, {}, {} } } undef, { {}, {}, {}, {}, {}, {}, {} } %2, 0\r\n ret { { {}, {}, {}, {}, {}, {}, {} } } %3\r\n}\r\n\r\n!llvm.module.flags = !{!0}\r\n\r\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\r\n```", "author": "edg-l", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "edg-l", "body": "one question, will this be included in llvm 19?" }, { "author": "alexey-bataev", "body": "Not sure, it is not an immediate regression from 18 to 19, and it is too late, I think, to include it into 19" } ] }
true
null
105120
https://github.com/llvm/llvm-project/issues/105120
crash
6ec3130a38e6982a61e7fa74bd5223c95c0bb918
2024-08-20T17:04:34
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e31252bf54dedadfe78b36d07ea6084156faa38a", "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": [ [ 7227, 7232 ], [ 7238, 7247 ] ], "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 e31252bf54dedadfe78b36d07ea6084156faa38a Author: Alexey Bataev <[email protected]> Date: Wed Aug 21 11:47:00 2024 -0700 [SLP]Fix PR105120: fix the order of phi nodes vectorization. The operands of the phi nodes should be vectorized in the same order, in which they were created, otherwise the compiler may crash when trying to correctly build dependency for nodes with non-schedulable instructions for gather/buildvector nodes. Fixes https://github.com/llvm/llvm-project/issues/105120 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index dee6d688b1b9..848e0de20e7b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7227,6 +7227,22 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, unsigned ShuffleOrOp = S.isAltShuffle() ? (unsigned) Instruction::ShuffleVector : S.getOpcode(); + auto CreateOperandNodes = [&](TreeEntry *TE, const auto &Operands) { + // Postpone PHI nodes creation + SmallVector<unsigned> PHIOps; + for (unsigned I : seq<unsigned>(Operands.size())) { + ArrayRef<Value *> Op = Operands[I]; + if (Op.empty()) + continue; + InstructionsState S = getSameOpcode(Op, *TLI); + if (S.getOpcode() != Instruction::PHI || S.isAltShuffle()) + buildTree_rec(Op, Depth + 1, {TE, I}); + else + PHIOps.push_back(I); + } + for (unsigned I : PHIOps) + buildTree_rec(Operands[I], Depth + 1, {TE, I}); + }; switch (ShuffleOrOp) { case Instruction::PHI: { auto *PH = cast<PHINode>(VL0); @@ -7238,10 +7254,12 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, // Keeps the reordered operands to avoid code duplication. PHIHandler Handler(*DT, PH, VL); Handler.buildOperands(); - for (unsigned I : seq<unsigned>(0, PH->getNumOperands())) + for (unsigned I : seq<unsigned>(PH->getNumOperands())) TE->setOperand(I, Handler.getOperands(I)); - for (unsigned I : seq<unsigned>(0, PH->getNumOperands())) - buildTree_rec(Handler.getOperands(I), Depth + 1, {TE, I}); + SmallVector<ArrayRef<Value *>> Operands(PH->getNumOperands()); + for (unsigned I : seq<unsigned>(PH->getNumOperands())) + Operands[I] = Handler.getOperands(I); + CreateOperandNodes(TE, Operands); return; } case Instruction::ExtractValue:
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/phi-nodes-as-operand-reorder.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %phi = phi i32 [ 0, %bb ], [ %add5, %bb3 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb3 ]\n br i1 false, label %bb6, label %bb3\n\nbb3: ; preds = %bb1\n %add = add i32 0, 0\n %add4 = add i32 0, 0\n %add5 = add i32 %phi, 0\n br i1 false, label %bb6, label %bb1\n\nbb6: ; preds = %bb3, %bb1\n %phi7 = phi i32 [ %phi2, %bb1 ], [ %add4, %bb3 ]\n %phi8 = phi i32 [ %phi, %bb1 ], [ %add5, %bb3 ]\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "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 = %bb3, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %add5, %bb3 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb3 ]\r\n br i1 false, label %bb6, label %bb3\r\n\r\nbb3: ; preds = %bb1\r\n %add = add i32 0, 0\r\n %add4 = add i32 0, 0\r\n %add5 = add i32 %phi, 0\r\n br i1 false, label %bb6, label %bb1\r\n\r\nbb6: ; preds = %bb3, %bb1\r\n %phi7 = phi i32 [ %phi2, %bb1 ], [ %add4, %bb3 ]\r\n %phi8 = phi i32 [ %phi, %bb1 ], [ %add5, %bb3 ]\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/W96s5a1cb\r\n\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = shufflevector <2 x i32> %0, <2 x i32> <i32 0, i32 poison>, <2 x i32> <i32 2, i32 1>\r\n %1 = add <2 x i32> zeroinitializer, %2\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.\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 \"verify\" on module \"<source>\"\r\n #0 0x0000000004f84b88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f84b88)\r\n #1 0x0000000004f822fc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074dcb3642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074dcb36969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074dcb3642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074dcb36287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b7cc5 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004ebea18 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ebea18)\r\n #8 0x0000000004dbae20 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4dbae20)\r\n #9 0x00000000008dbbde llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8dbbde)\r\n#10 0x0000000004d7ebb0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7ebb0)\r\n#11 0x00000000008e6912 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+0x8e6912)\r\n#12 0x00000000008d97ec optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d97ec)\r\n#13 0x000074dcb3629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x000074dcb3629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008d127e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d127e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "llvm:crash" ], "comments": [ { "author": "alexey-bataev", "body": "Yes" } ] }
true
null
80597
https://github.com/llvm/llvm-project/issues/80597
crash
8f4d8945536e9fc45db0e349b91c2f4b3a9cae29
2024-02-04T14:06:35
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "cb8d83a77c25e529f58eba17bb1ec76069a04e90", "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": [ [ 802, 807 ] ], "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 cb8d83a77c25e529f58eba17bb1ec76069a04e90 Author: Yingwei Zheng <[email protected]> Date: Tue Feb 6 01:29:38 2024 +0800 [InstCombine] Fix assertion failure in issue80597 (#80614) The assertion in #80597 failed when we were trying to compute known bits of a value in an unreachable BB. https://github.com/llvm/llvm-project/blob/859b09da08c2a47026ba0a7d2f21b7dca705864d/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L749-L810 In this case, `SignBits` is 30 (deduced from instr info), but `Known` is `10000101010111010011110101000?0?00000000000000000000000000000000` (deduced from dom cond). Setting high bits of `lshr Known, 1` will lead to conflict. This patch masks out high bits of `Known.Zero` to address this problem. Fixes #80597. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index a8a5f9831e15..79873a9b4cbb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -802,6 +802,9 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, return InsertNewInstWith(LShr, I->getIterator()); } else if (Known.One[BitWidth-ShiftAmt-1]) { // New bits are known one. Known.One |= HighBits; + // SignBits may be out-of-sync with Known.countMinSignBits(). Mask out + // high bits of Known.Zero to avoid conflicts. + Known.Zero &= ~HighBits; } } else { computeKnownBits(I, Known, Depth, CxtI);
[ { "file": "llvm/test/Transforms/InstCombine/pr80597.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr80597", "test_body": "define i64 @pr80597(i1 %cond) {\nentry:\n %add = select i1 %cond, i64 0, i64 4294967293\n %add8 = shl i64 %add, 32\n %sext1 = add i64 %add8, 8836839514384105472\n %cmp = icmp ult i64 %sext1, -34359738368\n br i1 %cmp, label %if.then, label %if.else\n\nif.else: ; preds = %entry\n %sext2 = or i64 %add8, 8836839522974040064\n %ashr = ashr i64 %sext2, 1\n ret i64 %ashr\n\nif.then: ; preds = %entry\n ret i64 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "llvm crash: Assertion `!LHSKnown.hasConflict() && \"Bits known to be one AND zero?\"' failed.", "body": "llvm crashes in `instcombine`\r\n\r\nBisected to d77067d08a3f56dc2d0e6c95bd2852c943df743a, which was committed by @nikic \r\n\r\nCompiler explorer: https://godbolt.org/z/e4jrvf5Wr\r\n\r\n```console\r\n% cat 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\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main(i1 %.b.i) {\r\nentry:\r\n %add.i = select i1 %.b.i, i64 0, i64 4294967293\r\n %add8.i = shl i64 %add.i, 32\r\n %sext.2.i = add i64 %add8.i, 8836839514384105472\r\n %cmp11.2.i = icmp ult i64 %sext.2.i, -34359738368\r\n br i1 %cmp11.2.i, label %return.loopexit.i, label %for.inc.2.i\r\n\r\nfor.inc.2.i: ; preds = %entry\r\n %sext.4.i = or i64 %add8.i, 8836839522974040064\r\n %conv9.4.i = ashr i64 %sext.4.i, 1\r\n %cmp11.4.i = icmp ult i64 %conv9.4.i, 0\r\n br i1 %cmp11.4.i, label %return.loopexit.i, label %return.loopexit.i\r\n\r\nreturn.loopexit.i: ; preds = %for.inc.2.i, %for.inc.2.i, %entry\r\n ret i32 0\r\n}\r\n%\r\n% opt -disable-output -passes=instcombine reduced.ll\r\nopt: /tmp/tmpzoi34eaf/tmporhhh5ti/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp:246: llvm::Value* llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Value*, llvm::APInt, llvm::KnownBits&, unsigned int, llvm::Instruction*): Assertion `!LHSKnown.hasConflict() && \"Bits known to be one AND zero?\"' 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: /zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt -disable-output -passes=instcombine reduced.ll\r\n #0 0x00007f7698f4558f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x93858f)\r\n #1 0x00007f7698f42ab4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7698222090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\r\n #3 0x00007f769822200b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f7698201859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f7698201729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f7698201729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f7698212fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x00007f769a44445d llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Value*, llvm::APInt, llvm::KnownBits&, unsigned int, llvm::Instruction*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1e3745d)\r\n #9 0x00007f769a444d25 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&, llvm::KnownBits&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1e37d25)\r\n#10 0x00007f769a4459c5 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1e389c5)\r\n#11 0x00007f769a38cdc3 llvm::InstCombinerImpl::visitOr(llvm::BinaryOperator&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1d7fdc3)\r\n#12 0x00007f769a3537b1 llvm::InstCombinerImpl::run() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1d467b1)\r\n#13 0x00007f769a355002 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&) (.isra.0) InstructionCombining.cpp:0:0\r\n#14 0x00007f769a355fbb llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1d48fbb)\r\n#15 0x00007f769bea5916 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x3898916)\r\n#16 0x00007f769916239d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0xb5539d)\r\n#17 0x00007f769be9e506 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x3891506)\r\n#18 0x00007f7699160c2d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0xb53c2d)\r\n#19 0x00007f769bea5556 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x3898556)\r\n#20 0x00007f769915eb5d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0xb51b5d)\r\n#21 0x000055c7b779e395 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) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt+0x26395)\r\n#22 0x000055c7b7791e8a main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt+0x19e8a)\r\n#23 0x00007f7698203083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#24 0x000055c7b7792a5e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt+0x1aa5e)\r\n[1] 880216 abort -disable-output -passes=instcombine reduced.ll\r\n%\r\n```\r\n\r\nThe above test case was reduced from\r\n```C\r\nlong a, i;\r\nstatic long b = -4;\r\nchar c;\r\nint d;\r\nstatic int *e = &d, *h = &d;\r\nstatic long *f = &b, *g = &b;\r\nint j() {\r\n for (; a;) {\r\n c = 0;\r\n for (; c <= 6; c++) {\r\n unsigned long k = 1;\r\n i = -8;\r\n *h = i >= (int)k + (int)*f + c + 2057487030 + k;\r\n if (*e)\r\n break;\r\n }\r\n return 0;\r\n }\r\n *g = 0;\r\n return 0;\r\n}\r\nint main() { j(); }\r\n```", "author": "shao-hua-li", "labels": [ "release:backport", "llvm:instcombine", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Minimal reproduction: https://godbolt.org/z/5bzaqP65P" }, { "author": "dtcxzyw", "body": "Reopen this issue to backport the fix to the 18.X release.\r\n" } ] }
true
null
99701
https://github.com/llvm/llvm-project/issues/99701
crash
9a258664024d12a06ba8eb9344e270a9bb5f5d87
2024-07-19T20:27:53
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "ba8126b6fef79bd344a247f6291aaec7b67bdff0", "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": [ [ 137, 142 ], [ 6681, 6686 ], [ 6690, 6695 ], [ 6717, 6722 ] ], "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 ba8126b6fef79bd344a247f6291aaec7b67bdff0 Author: Florian Hahn <[email protected]> Date: Wed Jul 24 09:31:32 2024 +0100 [LV] Mark dead instructions in loop as free. Update collectValuesToIgnore to also ignore dead instructions in the loop. Such instructions will be removed by VPlan-based DCE and won't be considered by the VPlan-based cost model. This closes a gap between the legacy and VPlan-based cost model. In practice with the default pipelines, there shouldn't be any dead instructions in loops reaching LoopVectorize, but it is easy to generate such cases by hand or automatically via fuzzers. Fixes https://github.com/llvm/llvm-project/issues/99701. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 8fa1a57177d9..e4477f96aa62 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -137,6 +137,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/InjectTLIMappings.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/LoopSimplify.h" #include "llvm/Transforms/Utils/LoopUtils.h" #include "llvm/Transforms/Utils/LoopVersioning.h" @@ -6681,6 +6682,7 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { CodeMetrics::collectEphemeralValues(TheLoop, AC, ValuesToIgnore); SmallVector<Value *, 4> DeadInterleavePointerOps; + SmallVector<Value *, 4> DeadOps; for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { // Find all stores to invariant variables. Since they are going to sink @@ -6690,6 +6692,17 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) ValuesToIgnore.insert(&I); + if (VecValuesToIgnore.contains(&I) || ValuesToIgnore.contains(&I)) + continue; + + // Add instructions that would be trivially dead and are only used by + // values already ignored to DeadOps to seed worklist. + if (wouldInstructionBeTriviallyDead(&I, TLI) && + all_of(I.users(), [this](User *U) { + return VecValuesToIgnore.contains(U) || ValuesToIgnore.contains(U); + })) + DeadOps.push_back(&I); + // For interleave groups, we only create a pointer for the start of the // interleave group. Queue up addresses of group members except the insert // position for further processing. @@ -6717,6 +6730,29 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { DeadInterleavePointerOps.append(Op->op_begin(), Op->op_end()); } + // Mark ops that would be trivially dead and are only used by ignored + // instructions as free. + for (unsigned I = 0; I != DeadOps.size(); ++I) { + auto *Op = dyn_cast<Instruction>(DeadOps[I]); + // Skip any op that shouldn't be considered dead. + if (!Op || !TheLoop->contains(Op) || + !wouldInstructionBeTriviallyDead(Op, TLI) || + any_of(Op->users(), [this](User *U) { + return !VecValuesToIgnore.contains(U) && !ValuesToIgnore.contains(U); + })) + continue; + + // If all of Op's users are in ValuesToIgnore, add it to ValuesToIgnore + // which applies for both scalar and vector versions. Otherwise it is only + // dead in vector versions, so only add it to VecValuesToIgnore. + if (all_of(Op->users(), + [this](User *U) { return ValuesToIgnore.contains(U); })) + ValuesToIgnore.insert(Op); + + VecValuesToIgnore.insert(Op); + DeadOps.append(Op->op_begin(), Op->op_end()); + } + // Ignore type-promoting instructions we identified during reduction // detection. for (const auto &Reduction : Legal->getReductionVars()) {
[ { "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": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Test with a dead load in the loop, from\n; https://github.com/llvm/llvm-project/issues/99701\ndefine void @dead_load(ptr %p, i16 %start) {\n;\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop:\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:\n ret void\n}\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "I have a few finds by the fuzzer that affect LLVM (tested using a1d77caaabbb5279b734c061dab36b2138ec476d).\r\nI think they're all duplicates but I'm attaching them all in a .zip so it can be confirmed.\r\n\r\nTestcase:\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 void @e(i64 %0) #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.for.cond.cleanup_crit_edge: ; preds = %for.body\r\n ret void\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\r\n %arrayidx = getelementptr i16, ptr null, i64 %indvars.iv\r\n %1 = load i16, ptr %arrayidx, align 2\r\n %arrayidx5 = getelementptr [0 x i8], ptr null, i64 0, i64 %indvars.iv\r\n store i8 0, ptr %arrayidx5, align 1\r\n %indvars.iv.next = add nsw i64 %indvars.iv, 4\r\n %cmp = icmp ult i64 %indvars.iv, %0\r\n br i1 %cmp, label %for.body, label %for.cond.for.cond.cleanup_crit_edge\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-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-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,-zacas,-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\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 -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10444: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"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 \"e\"\r\n #0 0x000055b365fe4a60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f0ea60)\r\n #1 0x000055b365fe1e7f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f0be7f)\r\n #2 0x000055b365fe1fd5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007612a3042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007612a30969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007612a30969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007612a30969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007612a3042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007612a30287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007612a302871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007612a3039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000055b365005ba8 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f2fba8)\r\n#12 0x000055b365008761 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+0x1f32761)\r\n#13 0x000055b365008ee0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f32ee0)\r\n#14 0x000055b363e81296 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+0xdab296)\r\n#15 0x000055b365dfd4be 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+0x2d274be)\r\n#16 0x000055b363e84426 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+0xdae426)\r\n#17 0x000055b365dfc24b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d2624b)\r\n#18 0x000055b363e80776 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+0xdaa776)\r\n#19 0x000055b365dfa39d 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+0x2d2439d)\r\n#20 0x000055b3636cbdc6 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+0x5f5dc6)\r\n#21 0x000055b3636bda11 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e7a11)\r\n#22 0x00007612a3029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x00007612a3029e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x00007612a3029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x000055b3636b3855 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5dd855)\r\nzsh: IOT instruction /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/a7KPnMh94\r\n\r\nZip with all finds reduced: \r\n[finds.zip](https://github.com/user-attachments/files/16316789/finds.zip)\r\n\r\nRelated: https://github.com/llvm/llvm-project/pull/92555 @fhahn \r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "JonPsson1", "body": "I'm seeing this as well with a multitude of hits with csmith. One reduced test case:\r\n\r\nclang -O3 -march=z16 crash0.i -o a.out -w -mllvm -disable-licm-promotion -mllvm -force-target-instruction-cost=1 -mllvm -unroll-count=4\r\nLoopVectorize.cpp:10071: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\n#9 0x0000000004749e30 llvm::LoopVectorizePass::processLoop()\r\n\r\n[tc_lv.i.tar.gz](https://github.com/user-attachments/files/16337463/tc_lv.i.tar.gz)\r\n\r\n" }, { "author": "fhahn", "body": "Thanks @patrick-rivos, it looks like all test cases had dead instructions, which would be considered by the legacy cost model but not the VPlan-based one (because VPlan-based DCE would clean them up before). Should be fixed now.\r\n\r\n@JonPsson1's case was a different issue and should also be fixed." } ] }
true
null
109835
https://github.com/llvm/llvm-project/issues/109835
crash
79ecb814d0c929a66ad92c7b3e91191f01247ac1
2024-09-24T17:26:42
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "cc01112660499a4db74bc3ee24b6f60b03d88dbd", "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": [ [ 11786, 11792 ], [ 11794, 11799 ] ], "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::getTreeCost" ], "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 cc01112660499a4db74bc3ee24b6f60b03d88dbd Author: Han-Kuan Chen <[email protected]> Date: Tue Oct 1 19:15:58 2024 +0800 [SLP][REVEC] getTypeSizeInBits should apply to scalar type instead of FixedVectorType. (#110610) reference: https://github.com/llvm/llvm-project/issues/109835 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 68bf5c52814f..54a1b99606bc 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -11786,7 +11786,7 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { auto BWIt = MinBWs.find(&Root); if (BWIt != MinBWs.end()) { Type *DstTy = Root.Scalars.front()->getType(); - unsigned OriginalSz = DL->getTypeSizeInBits(DstTy); + unsigned OriginalSz = DL->getTypeSizeInBits(DstTy->getScalarType()); unsigned SrcSz = ReductionBitWidth == 0 ? BWIt->second.first : ReductionBitWidth; if (OriginalSz != SrcSz) { @@ -11794,6 +11794,10 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { if (OriginalSz > SrcSz) Opcode = BWIt->second.second ? Instruction::SExt : Instruction::ZExt; Type *SrcTy = IntegerType::get(DstTy->getContext(), SrcSz); + if (auto *VecTy = dyn_cast<FixedVectorType>(DstTy)) { + assert(SLPReVec && "Only supported by REVEC."); + SrcTy = getWidenedType(SrcTy, VecTy->getNumElements()); + } Cost += TTI->getCastInstrCost(Opcode, DstTy, SrcTy, TTI::CastContextHint::None, TTI::TCK_RecipThroughput);
[ { "file": "llvm/test/Transforms/SLPVectorizer/SystemZ/revec-fix-109835.ll", "commands": [ "opt -mtriple=s390x-unknown-linux -mcpu=z16 -passes=slp-vectorizer -S -slp-revec %s" ], "tests": [ { "test_name": "func_1", "test_body": "@g_3_1_0 = external dso_local global i32, align 4\n@g_7 = external dso_local global [5 x i32], align 4\n\ndefine void @func_1() {\n %.pre = load i32, ptr @g_7, align 4\n %1 = load <4 x i32>, ptr getelementptr inbounds nuw (i8, ptr @g_7, i64 4), align 4\n br label %.loopexit\n\n.loopexit: ; preds = %.loopexit, %0\n %2 = phi i32 [ %op.rdx15, %.loopexit ], [ %.pre, %0 ]\n %3 = phi <4 x i32> [ %71, %.loopexit ], [ %1, %0 ]\n %4 = load volatile i32, ptr @g_3_1_0, align 4\n %5 = load volatile i32, ptr @g_3_1_0, align 4\n %6 = load volatile i32, ptr @g_3_1_0, align 4\n %7 = load volatile i32, ptr @g_3_1_0, align 4\n %8 = load volatile i32, ptr @g_3_1_0, align 4\n %9 = load volatile i32, ptr @g_3_1_0, align 4\n %10 = load volatile i32, ptr @g_3_1_0, align 4\n %11 = load volatile i32, ptr @g_3_1_0, align 4\n %12 = load volatile i32, ptr @g_3_1_0, align 4\n %13 = load volatile i32, ptr @g_3_1_0, align 4\n %14 = load volatile i32, ptr @g_3_1_0, align 4\n %15 = load volatile i32, ptr @g_3_1_0, align 4\n %16 = load volatile i32, ptr @g_3_1_0, align 4\n %17 = load volatile i32, ptr @g_3_1_0, align 4\n %18 = load volatile i32, ptr @g_3_1_0, align 4\n %19 = load volatile i32, ptr @g_3_1_0, align 4\n %20 = insertelement <4 x i32> poison, i32 %4, i32 0\n %21 = insertelement <4 x i32> %20, i32 %9, i32 1\n %22 = insertelement <4 x i32> %21, i32 %14, i32 2\n %23 = insertelement <4 x i32> %22, i32 %19, i32 3\n %24 = icmp eq <4 x i32> %23, zeroinitializer\n %25 = load volatile i32, ptr @g_3_1_0, align 4\n %26 = load volatile i32, ptr @g_3_1_0, align 4\n %27 = load volatile i32, ptr @g_3_1_0, align 4\n %28 = load volatile i32, ptr @g_3_1_0, align 4\n %29 = load volatile i32, ptr @g_3_1_0, align 4\n %.not2.410 = icmp eq i32 %29, 0\n %30 = zext i1 %.not2.410 to i32\n %31 = zext <4 x i1> %24 to <4 x i32>\n %32 = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %31)\n %op.rdx = xor i32 %32, %30\n %op.rdx15 = xor i32 %op.rdx, %2\n %33 = load volatile i32, ptr @g_3_1_0, align 4\n %34 = load volatile i32, ptr @g_3_1_0, align 4\n %35 = load volatile i32, ptr @g_3_1_0, align 4\n %36 = load volatile i32, ptr @g_3_1_0, align 4\n %37 = insertelement <4 x i32> poison, i32 %5, i32 0\n %38 = insertelement <4 x i32> %37, i32 %6, i32 1\n %39 = insertelement <4 x i32> %38, i32 %7, i32 2\n %40 = insertelement <4 x i32> %39, i32 %8, i32 3\n %41 = icmp eq <4 x i32> %40, zeroinitializer\n %42 = zext <4 x i1> %41 to <4 x i32>\n %43 = xor <4 x i32> %3, %42\n %44 = insertelement <4 x i32> poison, i32 %10, i32 0\n %45 = insertelement <4 x i32> %44, i32 %11, i32 1\n %46 = insertelement <4 x i32> %45, i32 %12, i32 2\n %47 = insertelement <4 x i32> %46, i32 %13, i32 3\n %48 = icmp eq <4 x i32> %47, zeroinitializer\n %49 = zext <4 x i1> %48 to <4 x i32>\n %50 = xor <4 x i32> %43, %49\n %51 = insertelement <4 x i32> poison, i32 %15, i32 0\n %52 = insertelement <4 x i32> %51, i32 %16, i32 1\n %53 = insertelement <4 x i32> %52, i32 %17, i32 2\n %54 = insertelement <4 x i32> %53, i32 %18, i32 3\n %55 = icmp eq <4 x i32> %54, zeroinitializer\n %56 = zext <4 x i1> %55 to <4 x i32>\n %57 = xor <4 x i32> %50, %56\n %58 = insertelement <4 x i32> poison, i32 %25, i32 0\n %59 = insertelement <4 x i32> %58, i32 %26, i32 1\n %60 = insertelement <4 x i32> %59, i32 %27, i32 2\n %61 = insertelement <4 x i32> %60, i32 %28, i32 3\n %62 = icmp eq <4 x i32> %61, zeroinitializer\n %63 = zext <4 x i1> %62 to <4 x i32>\n %64 = xor <4 x i32> %57, %63\n %65 = insertelement <4 x i32> poison, i32 %33, i32 0\n %66 = insertelement <4 x i32> %65, i32 %34, i32 1\n %67 = insertelement <4 x i32> %66, i32 %35, i32 2\n %68 = insertelement <4 x i32> %67, i32 %36, i32 3\n %69 = icmp eq <4 x i32> %68, zeroinitializer\n %70 = zext <4 x i1> %69 to <4 x i32>\n %71 = xor <4 x i32> %64, %70\n br label %.loopexit\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP vectorizer] Assertion fails with slp-revec", "body": "[tc_slp_revec.tar.gz](https://github.com/user-attachments/files/17118250/tc_slp_revec.tar.gz)\r\n\r\nopt -mtriple=systemz-unknown -mcpu=z16 -O3 -o out.ll tc_crash22_aftercreduce.ll -slp-revec\r\n\r\nType.cpp:691: static llvm::FixedVectorType* llvm::FixedVectorType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(\r\nElementType) && \"Element type of a VectorType must \" \"be an integer, floating point, or \" \"pointer type.\"' failed.\r\n\r\n#9 0x000002aa076e014e llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize\r\n\r\n", "author": "JonPsson1", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "HanKuanChen", "body": "The fix is landing." }, { "author": "JonPsson1", "body": "Still failing, but this time I see another assertion:\r\n\r\n[tc_slp_revec.tar.gz](https://github.com/user-attachments/files/17192435/tc_slp_revec.tar.gz)\r\n\r\nopt -mtriple=s390x-unknown-linux -mcpu=z16 -O3 tc_crash38_aftercreduce.ll -o /dev/null -slp-revec\r\n\r\nAssertion `!Dst->isVectorTy()' failed.\r\n14 0x00000000030504c2 llvm::SLPVectorizerPass::vectorizeHorReduction\r\n\r\n" }, { "author": "HanKuanChen", "body": "The fix is landing." } ] }
true
null
93096
https://github.com/llvm/llvm-project/issues/93096
miscompilation
300e5b91144249a5b142b02d6331fcb33e13cf1d
2024-05-22T21:03:20
[ "llvm/test/Transforms/SCCP" ]
{ "fix_commit": "27392a35ef052aa515f38359de89aced11a4363d", "components": [ "SCCPSolver" ], "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": 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": [ [ 43, 49 ], [ 1297, 1303 ], [ 1329, 1336 ], [ 1534, 1541 ], [ 1818, 1824 ], [ 1863, 1869 ] ], "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": 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": [ "SCCPInstVisitor::handleCallResult", "SCCPInstVisitor::handleExtractOfWithOverflow", "SCCPInstVisitor::visitBinaryOperator", "SCCPInstVisitor::visitCastInst", "getConstantRange" ], "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 27392a35ef052aa515f38359de89aced11a4363d Author: Nikita Popov <[email protected]> Date: Thu May 23 15:14:34 2024 +0200 [SCCP] Don't allow undef ranges when performing operations (#93163) When performing some range operation (e.g. and) on a constant range that includes undef, we currently just ignore the undef value, which is obviously incorrect. Instead, we can do one of two things: * Say that the result range also includes undef. * Treat undef as a full range. This patch goes with the second approach -- I'd expect it to be a bit better overall, e.g. it allows preserving the fact that a zext of a range with undef isn't a full range. Fixes https://github.com/llvm/llvm-project/issues/93096. diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp index ce40e8b31b76..4f36bac11e34 100644 --- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -43,7 +43,7 @@ static ValueLatticeElement::MergeOptions getMaxWidenStepsOpts() { } static ConstantRange getConstantRange(const ValueLatticeElement &LV, Type *Ty, - bool UndefAllowed = true) { + bool UndefAllowed) { assert(Ty->isIntOrIntVectorTy() && "Should be int or int vector"); if (LV.isConstantRange(UndefAllowed)) return LV.getConstantRange(); @@ -1297,7 +1297,8 @@ void SCCPInstVisitor::visitCastInst(CastInst &I) { if (I.getDestTy()->isIntegerTy() && I.getSrcTy()->isIntOrIntVectorTy()) { auto &LV = getValueState(&I); - ConstantRange OpRange = getConstantRange(OpSt, I.getSrcTy()); + ConstantRange OpRange = + getConstantRange(OpSt, I.getSrcTy(), /*UndefAllowed=*/false); Type *DestTy = I.getDestTy(); // Vectors where all elements have the same known constant range are treated @@ -1329,8 +1330,8 @@ void SCCPInstVisitor::handleExtractOfWithOverflow(ExtractValueInst &EVI, return; // Wait to resolve. Type *Ty = LHS->getType(); - ConstantRange LR = getConstantRange(L, Ty); - ConstantRange RR = getConstantRange(R, Ty); + ConstantRange LR = getConstantRange(L, Ty, /*UndefAllowed=*/false); + ConstantRange RR = getConstantRange(R, Ty, /*UndefAllowed=*/false); if (Idx == 0) { ConstantRange Res = LR.binaryOp(WO->getBinaryOp(), RR); mergeInValue(&EVI, ValueLatticeElement::getRange(Res)); @@ -1534,8 +1535,10 @@ void SCCPInstVisitor::visitBinaryOperator(Instruction &I) { return markOverdefined(&I); // Try to simplify to a constant range. - ConstantRange A = getConstantRange(V1State, I.getType()); - ConstantRange B = getConstantRange(V2State, I.getType()); + ConstantRange A = + getConstantRange(V1State, I.getType(), /*UndefAllowed=*/false); + ConstantRange B = + getConstantRange(V2State, I.getType(), /*UndefAllowed=*/false); auto *BO = cast<BinaryOperator>(&I); ConstantRange R = ConstantRange::getEmpty(I.getType()->getScalarSizeInBits()); @@ -1818,7 +1821,8 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) { // Combine range info for the original value with the new range from the // condition. - auto CopyOfCR = getConstantRange(CopyOfVal, CopyOf->getType()); + auto CopyOfCR = getConstantRange(CopyOfVal, CopyOf->getType(), + /*UndefAllowed=*/true); auto NewCR = ImposedCR.intersectWith(CopyOfCR); // If the existing information is != x, do not use the information from // a chained predicate, as the != x information is more likely to be @@ -1863,7 +1867,8 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) { const ValueLatticeElement &State = getValueState(Op); if (State.isUnknownOrUndef()) return; - OpRanges.push_back(getConstantRange(State, Op->getType())); + OpRanges.push_back( + getConstantRange(State, Op->getType(), /*UndefAllowed=*/false)); } ConstantRange Result =
[ { "file": "llvm/test/Transforms/SCCP/ip-add-range-to-call.ll", "commands": [ "opt -passes=ipsccp -S %s" ], "tests": [ { "test_name": "caller5", "test_body": "declare hidden i32 @callee5(i32, i32)\n\ndefine i32 @caller5() {\n %c1 = call i32 @callee5(i32 10, i32 100)\n %c2 = call i32 @callee5(i32 20, i32 200)\n %a = add i32 %c1, %c2\n ret i32 %a\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SCCP/range-with-undef.ll", "commands": [ "opt -S -passes=ipsccp < %s" ], "tests": [ { "test_name": "test_with_overflow", "test_body": "define i9 @test_with_overflow(i1 %cond, i8 %a) {\nentry:\n br i1 %cond, label %if, label %join\n\nif: ; preds = %entry\n %a.ext = zext i8 %a to i16\n br label %join\n\njoin: ; preds = %if, %entry\n %phi = phi i16 [ undef, %entry ], [ %a.ext, %if ]\n %wo = call { i16, i1 } @llvm.uadd.with.overflow.i16(i16 %phi, i16 1)\n %add = extractvalue { i16, i1 } %wo, 0\n %trunc = trunc i16 %add to i9\n ret i9 %trunc\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { i16, i1 } @llvm.uadd.with.overflow.i16(i16, i16) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_binop", "test_body": "define i8 @test_binop(i1 %cond, i8 %a) {\nentry:\n br i1 %cond, label %if, label %join\n\nif: ; preds = %entry\n %a.ext = zext i8 %a to i16\n br label %join\n\njoin: ; preds = %if, %entry\n %phi = phi i16 [ undef, %entry ], [ %a.ext, %if ]\n %and = and i16 %phi, -1\n %trunc = trunc i16 %and to i8\n ret i8 %trunc\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_cast", "test_body": "define i8 @test_cast(i1 %cond, i8 %a) {\nentry:\n br i1 %cond, label %if, label %join\n\nif: ; preds = %entry\n %a.ext = zext i8 %a to i16\n br label %join\n\njoin: ; preds = %if, %entry\n %phi = phi i16 [ undef, %entry ], [ %a.ext, %if ]\n %zext = zext i16 %phi to i32\n %trunc = trunc i32 %zext to i8\n ret i8 %trunc\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_intrin", "test_body": "define i8 @test_intrin(i1 %cond, i8 %a) {\nentry:\n br i1 %cond, label %if, label %join\n\nif: ; preds = %entry\n %a.ext = zext i8 %a to i16\n br label %join\n\njoin: ; preds = %if, %entry\n %phi = phi i16 [ undef, %entry ], [ %a.ext, %if ]\n %umax = call i16 @llvm.umax.i16(i16 %phi, i16 42)\n %trunc = trunc i16 %umax to i8\n ret i8 %trunc\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.umax.i16(i16, i16) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "nuw/nsw should not be added to trunc instruction when there are undef bits in the source value", "body": "Run ipsccp on the code\r\n```\r\n; opt -passes=ipsccp -S test.ll\r\n\r\ndefine void @foo(i1 %cond1, i32 %p1) {\r\nentry:\r\n br label %loop\r\n\r\nloop:\r\n %phi1 = phi i64 [undef, %entry], [%phi2, %latch]\r\n br i1 %cond1, label %then2, label %else2\r\n\r\nthen2:\r\n %and = and i64 %phi1, -1095216660481 ; 0xFFFFFF00FFFFFFFF\r\n br label %latch\r\n\r\nelse2:\r\n %ext = zext i32 %p1 to i64 \r\n %or = or i64 %ext, 4294967296 ; 0x100000000\r\n br label %latch\r\n\r\nlatch:\r\n %phi2 = phi i64 [%and, %then2], [%or, %else2]\r\n %shr = lshr i64 %phi2, 32\r\n %res = trunc i64 %shr to i8\r\n %cond2 = call i1 @bar(i8 %res)\r\n br i1 %cond2, label %loop, label %exit\r\n\r\nexit:\r\n ret void\r\n}\r\n\r\ndeclare i1 @bar(i8)\r\n```\r\nLLVM adds nuw/nsw flags to the trunc instruction\r\n```\r\n%res = trunc nuw nsw i64 %shr to i8\r\n```\r\nIt means all high bits of %shr are 0. \r\nBut %phi1 may be undef, bits [32..39] of %and are cleared, bits[40..63] can still be undef, and later it is moved to bits[8..31] of %shr, so not all high bits of %shr are 0.\r\n", "author": "weiguozhi", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "nikic", "body": "We do exclude ranges with undef here: https://github.com/llvm/llvm-project/blob/3061fed2f05cde574c84a26c702b1e7932fa4d7e/llvm/lib/Transforms/Utils/SCCPSolver.cpp#L118-L119 Maybe the undef flag doesn't get propagated properly somewhere..." }, { "author": "nikic", "body": "Simplified test case:\r\n```llvm\r\ndefine i8 @src(i1 %cond, i8 %a) {\r\nentry: \r\n br i1 %cond, label %if, label %join\r\n \r\nif:\r\n %a.ext = zext i8 %a to i16 \r\n br label %join \r\n\r\njoin:\r\n %phi = phi i16 [ undef, %entry ], [ %a.ext, %if ] \r\n %and = and i16 %phi, u0x0000ffff \r\n %trunc = trunc i16 %and to i8\r\n ret i8 %trunc\r\n} \r\n```\r\nThis is indeed an issue with the propagation of the undef flag." } ] }
true
null
89338
https://github.com/llvm/llvm-project/issues/89338
miscompilation
ab1d988e1483895a71dcd257bdcaf6fdb0a83d62
2024-04-19T01:55:15
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "46957a138dea339799059ea5bf032e40042ff185", "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": [ [ 1988, 1994 ] ], "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": [ "InstCombinerImpl::visitCallInst" ], "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 46957a138dea339799059ea5bf032e40042ff185 Author: Nikita Popov <[email protected]> Date: Fri Apr 19 14:00:49 2024 +0900 [InstCombine] Fix incorrect fshr to fshl transform This transform is only valid if the (modular) shift amount is not zero. Proof: https://alive2.llvm.org/ce/z/WBxn-x Fixes https://github.com/llvm/llvm-project/issues/89338. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index aa547565bd08..e7a2f54f8680 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1988,7 +1988,10 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { // is not entirely arbitrary. For historical reasons, the backend may // recognize rotate left patterns but miss rotate right patterns. if (IID == Intrinsic::fshr) { - // fshr X, Y, C --> fshl X, Y, (BitWidth - C) + // fshr X, Y, C --> fshl X, Y, (BitWidth - C) if C is not zero. + if (!isKnownNonZero(ShAmtC, SQ.getWithInstruction(II))) + return nullptr; + Constant *LeftShiftC = ConstantExpr::getSub(WidthC, ShAmtC); Module *Mod = II->getModule(); Function *Fshl = Intrinsic::getDeclaration(Mod, Intrinsic::fshl, Ty);
[ { "file": "llvm/test/Transforms/InstCombine/fsh.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "fsh_unary_shuffle_ops_partial_widening", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i32> @llvm.fshr.v2i32(<2 x i32>, <2 x i32>, <2 x i32>) #0\n\ndefine <2 x i32> @fsh_unary_shuffle_ops_partial_widening(<3 x i32> %x, <2 x i32> %y, <2 x i32> %z) {\n %a = shufflevector <3 x i32> %x, <3 x i32> poison, <2 x i32> <i32 1, i32 0>\n %b = shufflevector <2 x i32> %y, <2 x i32> poison, <2 x i32> <i32 1, i32 0>\n %c = shufflevector <2 x i32> %z, <2 x i32> poison, <2 x i32> <i32 1, i32 0>\n %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)\n ret <2 x i32> %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fshr_vec_zero_elem", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i32> @llvm.fshr.v2i32(<2 x i32>, <2 x i32>, <2 x i32>) #0\n\ndefine <2 x i32> @fshr_vec_zero_elem(<2 x i32> %x, <2 x i32> %y) {\n %fsh = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %x, <2 x i32> %y, <2 x i32> <i32 2, i32 0>)\n ret <2 x i32> %fsh\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "instcombine is wrong about a vector fshr->shl transformation", "body": "Instcombine seems to be mis-optimizing this function:\r\n```llvm\r\ndefine i32 @f(<4 x i8> %0) {\r\n %2 = call <4 x i8> @llvm.fshr.v4i8(<4 x i8> %0, <4 x i8> zeroinitializer, <4 x i8> <i8 -12, i8 -80, i8 35, i8 1>)\r\n %3 = bitcast <4 x i8> %2 to i32\r\n ret i32 %3\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare <4 x i8> @llvm.fshr.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\nthe result is:\r\n```llvm\r\ndefine i32 @f(<4 x i8> %0) {\r\n %2 = shl <4 x i8> %0, <i8 4, i8 0, i8 5, i8 7>\r\n %3 = bitcast <4 x i8> %2 to i32\r\n ret i32 %3\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare <4 x i8> @llvm.fshr.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #0\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare <4 x i8> @llvm.fshl.v4i8(<4 x i8>, <4 x i8>, <4 x i8>) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nAlive says:\r\n```\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<4 x i8> %#0 = < #x00 (0), #x01 (1), #x00 (0), #x00 (0) >\r\n\r\nSource:\r\n<4 x i8> %#2 = < #x00 (0), #x00 (0), #x00 (0), #x00 (0) >\r\ni32 %#3 = #x00000000 (0)\r\n\r\nTarget:\r\n<4 x i8> %#2 = < #x00 (0), #x01 (1), #x00 (0), #x00 (0) >\r\ni32 %#3 = #x00000100 (256)\r\nSource value: #x00000000 (0)\r\nTarget value: #x00000100 (256)\r\n```\r\n\r\nhttps://alive2.llvm.org/ce/z/s4UpPe\r\n\r\ncc @hatsunespica\r\n\r\n", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "nikic", "body": "Smaller test case: https://alive2.llvm.org/ce/z/hScyGk" }, { "author": "nikic", "body": "I believe the root cause is the fshr to fshl canonicalization: https://alive2.llvm.org/ce/z/NQM3tR\r\n\r\nWe're performing this transform: https://alive2.llvm.org/ce/z/6UUEsS But we don't verify the pre-condition that the (modular) shift amount is not zero!\r\n\r\nFor non-vectors this is a non-issue because we'd fold a zero shift earlier, but for vectors it is an issue." } ] }
true
null
91078
https://github.com/llvm/llvm-project/issues/91078
crash
d5ca2e46ca97758de6edb9f071f2114205380d87
2024-05-04T18:39:13
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "d145f40963f15e94c4aefcc406a365fbe779e934", "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": [ [ 1755, 1764 ] ], "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 d145f40963f15e94c4aefcc406a365fbe779e934 Author: David Green <[email protected]> Date: Sun May 5 10:47:11 2024 +0100 [VectorCombine] shuffleToIdentity - guard against call instructions. The shuffleToIdentity fold needs to be a bit more careful about the difference between call instructions and intrinsics. The second can be handled, but the first should result in bailing out. This patch also adds some extra intrinsic tests from #91000. Fixes #91078 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 04d2ff594bf5..bbb70134870a 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1755,10 +1755,13 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) { return false; if (IL.first->getValueID() != Item[0].first->getValueID()) return false; + if (isa<CallInst>(IL.first) && !isa<IntrinsicInst>(IL.first)) + return false; auto *II = dyn_cast<IntrinsicInst>(IL.first); return !II || - II->getIntrinsicID() == - cast<IntrinsicInst>(Item[0].first)->getIntrinsicID(); + (isa<IntrinsicInst>(Item[0].first) && + II->getIntrinsicID() == + cast<IntrinsicInst>(Item[0].first)->getIntrinsicID()); })) return false;
[ { "file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "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": "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": "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": "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": "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": "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 } ] } ]
{ "title": "A/F: isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\" after commit a4d1026", "body": "A few of our internal tests started hitting an assertion failure which I bisected back to commit a4d10266d20bfe5930dfed77e17832af341ed66e. \r\n\r\nConsider the following code:\r\n```c++\r\ntemplate <typename a> a b(a);\r\ntypedef float c __attribute__((__vector_size__(32)));\r\ntypedef float __attribute__((ext_vector_type(8))) d;\r\ntypedef float __attribute__((ext_vector_type(4))) e;\r\nc f;\r\n#define g(h) (b(h))\r\nd i;\r\nvoid j() {\r\n c k = __builtin_ia32_rsqrtps256(f);\r\n d l(k);\r\n d m g(i);\r\n volatile e n = __builtin_shufflevector(l, m, 15, 2, 0, 1);\r\n}\r\n```\r\nWhen compiled with optimizations and `-mavx` it hits an assertion failure:\r\n```\r\n$ ~/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang -c -O2 -mavx repro2.cpp \r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::IntrinsicInst; From = llvm::Value]: 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, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang -c -O2 -mavx repro2.cpp\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n #0 0x0000557d533cfe2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4055e2f)\r\n #1 0x0000557d533cd96c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x405396c)\r\n #2 0x0000557d5331a4e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f0ccbb8b420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #4 0x00007f0ccb65800b raise /build/glibc-e2p3jK/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #5 0x00007f0ccb637859 abort /build/glibc-e2p3jK/glibc-2.31/stdlib/abort.c:81:7\r\n #6 0x00007f0ccb637729 get_sysdep_segment_value /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #7 0x00007f0ccb637729 _nl_load_domain /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #8 0x00007f0ccb648fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #9 0x0000557d54cd0f88 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&)::'lambda3'(std::pair<llvm::Value*, int>)::operator()(std::pair<llvm::Value*, int>) const (.isra.0) VectorCombine.cpp:0:0\r\n#10 0x0000557d54cdac11 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\r\n#11 0x0000557d54ce56f1 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\r\n#12 0x0000557d54ce695d llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x596c95d)\r\n#13 0x0000557d547ca386 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x5450386)\r\n#14 0x0000557d50a03b4c 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/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x1689b4c)\r\n#15 0x0000557d52d96d0d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x3a1cd0d)\r\n#16 0x0000557d509e66d6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x166c6d6)\r\n#17 0x0000557d52d94b9d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x3a1ab9d)\r\n#18 0x0000557d5366aa28 (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 0x0000557d5366dd85 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#20 0x0000557d5366e449 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*) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x42f4449)\r\n#21 0x0000557d53cc97ca clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x494f7ca)\r\n#22 0x0000557d55a3f65c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x66c565c)\r\n#23 0x0000557d53cc8278 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x494e278)\r\n#24 0x0000557d53f56729 clang::FrontendAction::Execute() (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4bdc729)\r\n#25 0x0000557d53edc48e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4b6248e)\r\n#26 0x0000557d54040e86 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4cc6e86)\r\n#27 0x0000557d505e1bbc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x1267bbc)\r\n#28 0x0000557d505dacca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#29 0x0000557d53d0d8ed 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#30 0x0000557d5331a9f0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x3fa09f0)\r\n#31 0x0000557d53d0df0f 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#32 0x0000557d53cd2a4c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4958a4c)\r\n#33 0x0000557d53cd34dd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x49594dd)\r\n#34 0x0000557d53cdb8f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x49618f5)\r\n#35 0x0000557d505defab clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x1264fab)\r\n#36 0x0000557d504db96b main (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x116196b)\r\n#37 0x00007f0ccb639083 __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#38 0x0000557d505da79e _start (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x126079e)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 19.0.0 (https://github.com/llvm/llvm-project.git a4d10266d20bfe5930dfed77e17832af341ed66e)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin\r\nBuild config: +assertions\r\n```", "author": "dyung", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
110193
https://github.com/llvm/llvm-project/issues/110193
crash
7dfdca1961aadc75ca397818bfb9bd32f1879248
2024-09-27T00:54:58
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "af6354634d2cec14570108ee038ca4b18cf6856a", "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": [ [ 10340, 10352 ] ], "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::getEntryCost" ], "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 af6354634d2cec14570108ee038ca4b18cf6856a Author: Alexey Bataev <[email protected]> Date: Fri Sep 27 03:55:17 2024 -0700 [SLP]Look for vector user when estimating the cost Need to find the first vector node user, not the very first user node at all. The very first user might be a gather, vectorized as clustered, which may cause compiler crash. Fixes https://github.com/llvm/llvm-project/issues/110193 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 48a8627ab63e..dee0b7e1f437 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -10340,13 +10340,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, InstructionCost VecCost = VectorCost(CommonCost); // Check if the current node must be resized, if the parent node is not // resized. - if (!UnaryInstruction::isCast(E->getOpcode()) && E->Idx != 0 && + if (It != MinBWs.end() && !UnaryInstruction::isCast(E->getOpcode()) && + E->Idx != 0 && (E->getOpcode() != Instruction::Load || !E->UserTreeIndices.empty())) { - const EdgeInfo &EI = E->UserTreeIndices.front(); - if ((EI.UserTE->getOpcode() != Instruction::Select || - EI.EdgeIdx != 0) && - It != MinBWs.end()) { + const EdgeInfo &EI = + *find_if(E->UserTreeIndices, [](const EdgeInfo &EI) { + return !EI.UserTE->isGather() || EI.EdgeIdx != UINT_MAX; + }); + if (EI.UserTE->getOpcode() != Instruction::Select || + EI.EdgeIdx != 0) { auto UserBWIt = MinBWs.find(EI.UserTE); Type *UserScalarTy = EI.UserTE->getOperand(EI.EdgeIdx).front()->getType();
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/minbw-multiused-from-gather.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i1 @test() {\nentry:\n %c18.i308.i.i = shl i32 0, 0\n %c19.i315.i.i = shl i32 0, 0\n %and.19.i316.i.i = and i32 %c18.i308.i.i, %c19.i315.i.i\n %c20.i322.i.i = shl i32 0, 0\n %and.20.i323.i.i = and i32 %and.19.i316.i.i, %c20.i322.i.i\n %c21.i329.i.i = shl i32 0, 0\n %and.21.i330.i.i = and i32 %and.20.i323.i.i, %c21.i329.i.i\n %0 = trunc i64 0 to i32\n %conv85.22.i333.i.i = or i32 0, %0\n %cmp3.i.22.i334.i.i = icmp ugt i32 %conv85.22.i333.i.i, 0\n %shl.i111.22.i335.i.i = select i1 %cmp3.i.22.i334.i.i, i32 0, i32 0\n %c22.i336.i.i = shl i32 %conv85.22.i333.i.i, %shl.i111.22.i335.i.i\n %and.22.i337.i.i = and i32 %and.21.i330.i.i, %c22.i336.i.i\n %1 = trunc i64 0 to i32\n %conv85.23.i340.i.i = or i32 0, %1\n %cmp3.i.23.i341.i.i = icmp ugt i32 %conv85.23.i340.i.i, 0\n %shl.i111.23.i342.i.i = select i1 %cmp3.i.23.i341.i.i, i32 0, i32 0\n %c23.i343.i.i = shl i32 %conv85.23.i340.i.i, %shl.i111.23.i342.i.i\n %and.23.i344.i.i = and i32 %and.22.i337.i.i, %c23.i343.i.i\n %2 = trunc i64 0 to i32\n %conv85.24.i347.i.i = or i32 0, %2\n %cmp3.i.24.i348.i.i = icmp ugt i32 %conv85.24.i347.i.i, 0\n %shl.i111.24.i349.i.i = select i1 %cmp3.i.24.i348.i.i, i32 0, i32 0\n %c24.i350.i.i = shl i32 %conv85.24.i347.i.i, %shl.i111.24.i349.i.i\n %and.24.i351.i.i = and i32 %and.23.i344.i.i, %c24.i350.i.i\n %3 = trunc i64 0 to i32\n %conv85.25.i354.i.i = or i32 0, %3\n %cmp3.i.25.i355.i.i = icmp ugt i32 %conv85.25.i354.i.i, 0\n %shl.i111.25.i356.i.i = select i1 %cmp3.i.25.i355.i.i, i32 0, i32 0\n %c25.i357.i.i = shl i32 %conv85.25.i354.i.i, %shl.i111.25.i356.i.i\n %and.25.i358.i.i = and i32 %and.24.i351.i.i, %c25.i357.i.i\n %conv109.i.i = trunc i32 %and.25.i358.i.i to i8\n %cmp.i.i54.i = icmp eq i8 %conv109.i.i, 0\n ret i1 %cmp.i.i54.i\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.", "body": "Reproducer: https://godbolt.org/z/6GbP5f7qa\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 i1 @main() {\r\nentry:\r\n %cond.i112.18.i308.i.i = shl i32 0, 0\r\n %cond.i112.19.i315.i.i = shl i32 0, 0\r\n %and.19.i316.i.i = and i32 %cond.i112.18.i308.i.i, %cond.i112.19.i315.i.i\r\n %cond.i112.20.i322.i.i = shl i32 0, 0\r\n %and.20.i323.i.i = and i32 %and.19.i316.i.i, %cond.i112.20.i322.i.i\r\n %cond.i112.21.i329.i.i = shl i32 0, 0\r\n %and.21.i330.i.i = and i32 %and.20.i323.i.i, %cond.i112.21.i329.i.i\r\n %0 = trunc i64 0 to i32\r\n %conv85.22.i333.i.i = or i32 0, %0\r\n %cmp3.i.22.i334.i.i = icmp ugt i32 %conv85.22.i333.i.i, 0\r\n %shl.i111.22.i335.i.i = select i1 %cmp3.i.22.i334.i.i, i32 0, i32 0\r\n %cond.i112.22.i336.i.i = shl i32 %conv85.22.i333.i.i, %shl.i111.22.i335.i.i\r\n %and.22.i337.i.i = and i32 %and.21.i330.i.i, %cond.i112.22.i336.i.i\r\n %1 = trunc i64 0 to i32\r\n %conv85.23.i340.i.i = or i32 0, %1\r\n %cmp3.i.23.i341.i.i = icmp ugt i32 %conv85.23.i340.i.i, 0\r\n %shl.i111.23.i342.i.i = select i1 %cmp3.i.23.i341.i.i, i32 0, i32 0\r\n %cond.i112.23.i343.i.i = shl i32 %conv85.23.i340.i.i, %shl.i111.23.i342.i.i\r\n %and.23.i344.i.i = and i32 %and.22.i337.i.i, %cond.i112.23.i343.i.i\r\n %2 = trunc i64 0 to i32\r\n %conv85.24.i347.i.i = or i32 0, %2\r\n %cmp3.i.24.i348.i.i = icmp ugt i32 %conv85.24.i347.i.i, 0\r\n %shl.i111.24.i349.i.i = select i1 %cmp3.i.24.i348.i.i, i32 0, i32 0\r\n %cond.i112.24.i350.i.i = shl i32 %conv85.24.i347.i.i, %shl.i111.24.i349.i.i\r\n %and.24.i351.i.i = and i32 %and.23.i344.i.i, %cond.i112.24.i350.i.i\r\n %3 = trunc i64 0 to i32\r\n %conv85.25.i354.i.i = or i32 0, %3\r\n %cmp3.i.25.i355.i.i = icmp ugt i32 %conv85.25.i354.i.i, 0\r\n %shl.i111.25.i356.i.i = select i1 %cmp3.i.25.i355.i.i, i32 0, i32 0\r\n %cond.i112.25.i357.i.i = shl i32 %conv85.25.i354.i.i, %shl.i111.25.i356.i.i\r\n %and.25.i358.i.i = and i32 %and.24.i351.i.i, %cond.i112.25.i357.i.i\r\n %conv109.i.i = trunc i32 %and.25.i358.i.i to i8\r\n %cmp.i.i54.i = icmp eq i8 %conv109.i.i, 0\r\n ret i1 %cmp.i.i54.i\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3247: 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. Program arguments: bin/opt -passes=slp-vectorizer reduced.ll\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x000075e591a13b52 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x213b52)\r\n #1 0x000075e591a10a1f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x210a1f)\r\n #2 0x000075e591a10b65 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000075e591442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000075e5914969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000075e5914969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000075e5914969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000075e591442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000075e5914287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000075e59142871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000075e591439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000075e58c574c14 (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x174c14)\r\n#12 0x000075e58c5bcafe llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1bcafe)\r\n#13 0x000075e58c5d0eed llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1d0eed)\r\n#14 0x000075e58c5d68cc (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#15 0x000075e58c5d997a llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1d997a)\r\n#16 0x000075e58c5ddf28 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ddf28)\r\n#17 0x000075e58c5de0cb bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1de0cb)\r\n#18 0x000075e58c5e2299 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1e2299)\r\n#19 0x000075e58c5e8c0f 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+0x1e8c0f)\r\n#20 0x000075e58c5e9876 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1e9876)\r\n#21 0x000075e58ced5195 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+0xd5195)\r\n#22 0x000075e58a15de5d 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+0x35de5d)\r\n#23 0x000075e5904d9d05 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+0xd9d05)\r\n#24 0x000075e58a15bf96 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35bf96)\r\n#25 0x000075e5904da6c5 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+0xda6c5)\r\n#26 0x000075e58a15cb1a 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+0x35cb1a)\r\n#27 0x000075e591c041c1 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+0x2d1c1)\r\n#28 0x000075e591c0f944 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38944)\r\n#29 0x000075e591429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#30 0x000075e591429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#31 0x000075e591429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#32 0x00005b421cc0e095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\nllvm version: 2b84ef06ac55ac8de3c210d059ec3a3c96666a90", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
85536
https://github.com/llvm/llvm-project/issues/85536
miscompilation
f84980570d3f85bdf5c9432647c05bae04a735a0
2024-03-16T15:33:21
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "252d01952c087cf0d141f7f281cf60efeb98be41", "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": [ [ 1650, 1655 ] ], "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": [ "foldOperationIntoSelectOperand" ], "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 252d01952c087cf0d141f7f281cf60efeb98be41 Author: Yingwei Zheng <[email protected]> Date: Sun Mar 17 14:15:27 2024 +0800 [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) When speculating an instruction in `InstCombinerImpl::FoldOpIntoSelect`, the call may result in undefined behavior. This patch drops all UB-implying attrs/metadata to fix this. Fixes #85536. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index edb046defbc1..5d3e41fb5f29 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1650,6 +1650,7 @@ static Value *foldOperationIntoSelectOperand(Instruction &I, SelectInst *SI, Value *NewOp, InstCombiner &IC) { Instruction *Clone = I.clone(); Clone->replaceUsesOfWith(SI, NewOp); + Clone->dropUBImplyingAttrsAndMetadata(); IC.InsertNewInstBefore(Clone, SI->getIterator()); return Clone; }
[ { "file": "llvm/test/Transforms/InstCombine/intrinsic-select.ll", "commands": [ "opt -passes=instcombine -S < %s" ], "tests": [ { "test_name": "test_drop_noundef", "test_body": "define i8 @test_drop_noundef(i1 %cond, i8 %val) {\nentry:\n %sel = select i1 %cond, i8 -1, i8 %val\n %ret = call noundef i8 @llvm.smin.i8(i8 %sel, i8 0)\n ret i8 %ret\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 }, { "test_name": "pr85536", "test_body": "define i1 @pr85536(i32 %a) {\nentry:\n %cmp1 = icmp ugt i32 %a, 30\n %shl1 = shl nsw i32 -1, %a\n %zext = zext i32 %shl1 to i64\n %shl2 = shl i64 %zext, 48\n %shr = ashr exact i64 %shl2, 48\n %sel = select i1 %cmp1, i64 -1, i64 %shr\n %smin = call noundef i64 @llvm.smin.i64(i64 %sel, i64 0)\n %masked = and i64 %smin, 65535\n %ret = icmp eq i64 %masked, 0\n ret i1 %ret\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.smin.i64(i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "vec_to_scalar_select_vector", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #0\n\ndefine i32 @vec_to_scalar_select_vector(<2 x i1> %b) {\n %s = select <2 x i1> %b, <2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 4>\n %c = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %s)\n ret i32 %c\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Miscompile at -O1", "body": "Reduced test case: https://godbolt.org/z/z1a3665hd\r\n```\r\n#include <stdio.h>\r\n#include <stdint.h>\r\nstatic uint16_t\r\n(safe_lshift_func_uint16_t_u_s)(uint16_t left, int right )\r\n{\r\n return\r\n ((((int)right) < 0) || (((int)right) >= 32) || (left > ((65535) >> ((int)right)))) ?\r\n ((left)) :\r\n (left << ((int)right));\r\n}\r\nstatic int16_t\r\n(safe_unary_minus_func_int16_t_s)(int16_t si )\r\n{\r\n return\r\n -si;\r\n}\r\nstatic int32_t\r\n(safe_lshift_func_int32_t_s_u)(int32_t left, unsigned int right )\r\n{\r\n return\r\n ((left < 0) || (((unsigned int)right) >= 32) || (left > ((2147483647) >> ((unsigned int)right)))) ?\r\n ((left)) :\r\n (left << ((unsigned int)right));\r\n}\r\nlong smin(long d, long p) { return d < p ? d : p; }\r\nstruct e { uint32_t f; } static g[] = {1, 36};\r\nint64_t h, i;\r\nuint8_t j(uint64_t m) {\r\n if (safe_lshift_func_uint16_t_u_s(\r\n smin(m, safe_unary_minus_func_int16_t_s(\r\n safe_lshift_func_int32_t_s_u(1, g[1].f))),\r\n 3))\r\n h = 0;\r\n return m;\r\n}\r\nint8_t k() {\r\n j(0);\r\n struct e *l[] = {&g[1], &g[1], &g[1], &g[1], &g[1],\r\n &g[1], &g[1], &g[1], &g[1]};\r\n return i;\r\n}\r\nint main() {\r\n printf(\"%d\\n\", k());\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\n> gcc -O0 -fsanitize=address,undefined -w test.c && ./a.out\r\n0\r\n> clang -O3 -w test.c && ./a.out\r\n; no output\r\n```\r\n\r\nReduced LLVM IR: https://alive2.llvm.org/ce/z/hWuhFG\r\n```\r\n%struct.e = type { i32 }\r\n\r\n@g = internal global [2 x %struct.e] [%struct.e { i32 1 }, %struct.e { i32 36 }], align 4\r\n@h = dso_local local_unnamed_addr global i64 0, align 8\r\n@i = dso_local local_unnamed_addr global i64 0, align 8\r\n\r\ndefine i8 @src() {\r\nentry:\r\n %0 = load i32, ptr getelementptr inbounds ([2 x %struct.e], ptr @g, i64 0, i64 1), align 4\r\n %or.cond.i.i = icmp ult i32 %0, 31\r\n %shl.i.neg.i = shl nsw i32 -1, %0\r\n %.neg.i = zext i32 %shl.i.neg.i to i64\r\n %sext.i = shl i64 %.neg.i, 48\r\n %1 = ashr exact i64 %sext.i, 48\r\n %2 = call i64 @llvm.smin.i64(i64 %1, i64 0)\r\n %3 = and i64 %2, 65535\r\n %tobool.not9.i1 = icmp eq i64 %3, 0\r\n %tobool.not9.i = and i1 %or.cond.i.i, %tobool.not9.i1\r\n br i1 %tobool.not9.i, label %j.exit, label %if.then.i\r\n\r\nif.then.i:\r\n store i64 0, ptr @h, align 8\r\n br label %j.exit\r\n\r\nj.exit:\r\n %4 = load i64, ptr @i, align 8\r\n %conv = trunc i64 %4 to i8\r\n ret i8 %conv\r\n}\r\n\r\n==>\r\n\r\ndefine i8 @tgt() {\r\n ret i8 poison\r\n}\r\n```\r\n\r\nLLVM version: 74d1a40915834cbf0629f8d34a7265734d4d9073\r\n\r\ncc @nikic ", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced IR: https://alive2.llvm.org/ce/z/Gv9zkm\r\n```\r\n@g = internal global [1 x i32] [i32 1], align 4\r\n\r\ndefine i32 @k() {\r\nentry:\r\n %ret = load i32, ptr getelementptr inbounds ([1 x i32], ptr @g, i64 0), align 4\r\n ret i32 %ret\r\n}\r\n\r\n==>\r\ndefine i32 @k() {\r\nentry:\r\n ret i32 1\r\n}\r\n```\r\n" }, { "author": "nikic", "body": "@dtcxzyw That last transform is correct for GlobalOpt, alive2 does not support IPO transforms." }, { "author": "dtcxzyw", "body": "> @dtcxzyw That last transform is correct for GlobalOpt, alive2 does not support IPO transforms.\r\n\r\nOh, sorry about my mistake. I will provide a godbolt link.\r\n\r\n\r\n" }, { "author": "dtcxzyw", "body": "The root cause: https://alive2.llvm.org/ce/z/ThJs3Y\r\n```\r\ndefine i1 @src(i32 %a) {\r\nentry:\r\n %or.cond.i.i = icmp ugt i32 %a, 30\r\n %shl.i.neg.i = shl nsw i32 -1, %a\r\n %.neg.i = zext i32 %shl.i.neg.i to i64\r\n %sext.i = shl i64 %.neg.i, 48\r\n %1 = ashr exact i64 %sext.i, 48\r\n %conv2.i = select i1 %or.cond.i.i, i64 -1, i64 %1\r\n %cond.i8.i = call noundef i64 @llvm.smin.i64(i64 0, i64 %conv2.i)\r\n %2 = and i64 %cond.i8.i, 65535\r\n %tobool.not9.i = icmp eq i64 %2, 0\r\n ret i1 %tobool.not9.i\r\n}\r\n\r\n==> \r\n\r\ndefine i1 @tgt(i32 %a) {\r\nentry:\r\n %or.cond.i.i = icmp ult i32 %a, 31\r\n %shl.i.neg.i = shl nsw i32 -1, %a\r\n %.neg.i = zext i32 %shl.i.neg.i to i64\r\n %sext.i = shl i64 %.neg.i, 48\r\n %0 = ashr exact i64 %sext.i, 48\r\n %1 = call noundef i64 @llvm.smin.i64(i64 %0, i64 0)\r\n %2 = and i64 %1, 65535\r\n %tobool.not9.i1 = icmp eq i64 %2, 0\r\n %tobool.not9.i = and i1 %or.cond.i.i, %tobool.not9.i1\r\n ret i1 %tobool.not9.i\r\n}\r\n```" }, { "author": "dtcxzyw", "body": "We forget to drop the `noundef` attribute for `smin` :(\r\n" }, { "author": "dtcxzyw", "body": "Minimal reproducer: https://alive2.llvm.org/ce/z/aBubZ4\r\n```\r\ndefine i8 @src(i1 %cond, i8 %val) {\r\nentry:\r\n %sel = select i1 %cond, i8 -1, i8 %val\r\n %ret = call noundef i8 @llvm.smin.i8(i8 %sel, i8 0)\r\n ret i8 %ret\r\n}\r\n\r\n==>\r\n\r\ndefine i8 @tgt(i1 %cond, i8 %val) {\r\n %min = call noundef i8 @llvm.smin.i8(i8 %val, i8 0)\r\n %ret = select i1 %cond, i8 -1, i8 %min\r\n ret i8 %ret\r\n}\r\n```\r\n\r\n" }, { "author": "nikic", "body": "@dtcxzyw We're probably missing a call to dropUBImplyingAttrsAndMetadata in FoldOpIntoSelect." } ] }
true
null
87410
https://github.com/llvm/llvm-project/issues/87410
crash
0bbe953aa3289a32cd816647820c8676bb3a61bc
2024-04-02T21:05:28
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "c83698367125703827f1b739393f006c399cb213", "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": [ [ 8233, 8238 ] ], "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": [ [ 1513, 1518 ] ], "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": [ [ 1932, 1945 ], [ 1949, 1963 ] ], "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": [ "VPRecipeBuilder::tryToBlend" ], "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": [ "VPBlendRecipe::print" ], "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": [ "VPBlendRecipe", "clone", "getIncomingValue", "getMask", "getNumIncomingValues" ], "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 c83698367125703827f1b739393f006c399cb213 Author: Florian Hahn <[email protected]> Date: Tue Apr 9 11:14:05 2024 +0100 [VPlan] Remove unused first mask op from VPBlendRecipe. (#87770) VPBlendRecipe does not use the first mask operand. Removing it allows VPlan-based DCE to remove unused mask computations. This also fixes #87410, where unused Not VPInstructions are considered having only their first lane demanded, but some of their operands providing a vector value due to other users. Fixes https://github.com/llvm/llvm-project/issues/87410 PR: https://github.com/llvm/llvm-project/pull/87770 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index fd54faf17ca3..5535cc55e932 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8221,6 +8221,8 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi, // builder. At this point we generate the predication tree. There may be // duplications since this is a simple recursive scan, but future // optimizations will clean it up. + // TODO: At the moment the first mask is always skipped, but it would be + // better to skip the most expensive mask. SmallVector<VPValue *, 2> OperandsWithMask; for (unsigned In = 0; In < NumIncoming; In++) { @@ -8233,6 +8235,8 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi, "Distinct incoming values with one having a full mask"); break; } + if (In == 0) + continue; OperandsWithMask.push_back(EdgeMask); } return new VPBlendRecipe(Phi, OperandsWithMask); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 5f6334b974cf..5dc905a3c407 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1932,14 +1932,12 @@ public: class VPBlendRecipe : public VPSingleDefRecipe { public: /// The blend operation is a User of the incoming values and of their - /// respective masks, ordered [I0, M0, I1, M1, ...]. Note that a single value - /// might be incoming with a full mask for which there is no VPValue. + /// respective masks, ordered [I0, I1, M1, I2, M2, ...]. Note that the first + /// incoming value does not have a mask associated. VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands) : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, Phi->getDebugLoc()) { - assert(Operands.size() > 0 && - ((Operands.size() == 1) || (Operands.size() % 2 == 0)) && - "Expected either a single incoming value or a positive even number " - "of operands"); + assert((Operands.size() + 1) % 2 == 0 && + "Expected an odd number of operands"); } VPRecipeBase *clone() override { @@ -1949,15 +1947,20 @@ public: VP_CLASSOF_IMPL(VPDef::VPBlendSC) - /// Return the number of incoming values, taking into account that a single + /// Return the number of incoming values, taking into account that the first /// incoming value has no mask. unsigned getNumIncomingValues() const { return (getNumOperands() + 1) / 2; } /// Return incoming value number \p Idx. - VPValue *getIncomingValue(unsigned Idx) const { return getOperand(Idx * 2); } + VPValue *getIncomingValue(unsigned Idx) const { + return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - 1); + } /// Return mask number \p Idx. - VPValue *getMask(unsigned Idx) const { return getOperand(Idx * 2 + 1); } + VPValue *getMask(unsigned Idx) const { + assert(Idx > 0 && "First index has no mask associated."); + return getOperand(Idx * 2); + } /// Generate the phi/select nodes. void execute(VPTransformState &State) override; diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 2438e4dae3eb..625319954e9b 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -1513,6 +1513,8 @@ void VPBlendRecipe::print(raw_ostream &O, const Twine &Indent, for (unsigned I = 0, E = getNumIncomingValues(); I < E; ++I) { O << " "; getIncomingValue(I)->printAsOperand(O, SlotTracker); + if (I == 0) + continue; O << "/"; getMask(I)->printAsOperand(O, SlotTracker); }
[ { "file": "llvm/test/Transforms/LoopVectorize/unused-blend-mask-for-first-operand.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test_not_first_lane_only_constant", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_not_first_lane_only_constant(ptr %A, ptr noalias %B) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.A = getelementptr inbounds i16, ptr %A, i16 %iv\n br i1 false, label %loop.latch, label %else.1\n\nelse.1: ; preds = %loop.header\n br i1 false, label %then.2, label %else.2\n\nthen.2: ; preds = %else.1\n br label %else.2\n\nelse.2: ; preds = %then.2, %else.1\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %loop.header\n %merge = phi ptr [ %B, %else.2 ], [ poison, %loop.header ]\n %l = load i16, ptr %merge, align 2\n %iv.next = add i16 %iv, 1\n store i16 %l, ptr %gep.A, align 2\n %c.2 = icmp eq i16 %iv.next, 1000\n br i1 %c.2, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_not_first_lane_only_wide_compare", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_not_first_lane_only_wide_compare(ptr %A, ptr noalias %B, i16 %x, i16 %y) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.A = getelementptr inbounds i16, ptr %A, i16 %iv\n %l.0 = load i16, ptr %gep.A, align 2\n %c.0 = icmp ult i16 %l.0, %x\n br i1 %c.0, label %loop.latch, label %else.1\n\nelse.1: ; preds = %loop.header\n %c.1 = icmp ult i16 %l.0, %y\n br i1 %c.1, label %then.2, label %else.2\n\nthen.2: ; preds = %else.1\n br label %else.2\n\nelse.2: ; preds = %then.2, %else.1\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %loop.header\n %merge = phi ptr [ %B, %else.2 ], [ poison, %loop.header ]\n %l = load i16, ptr %merge, align 2\n %iv.next = add i16 %iv, 1\n store i16 %l, ptr %gep.A, align 2\n %c.2 = icmp eq i16 %iv.next, 1000\n br i1 %c.2, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize][VPlan] Assertion \"Trying to access a single scalar per part but has multiple scalars per part.\" failed.", "body": "Reduced LLVM IR\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.i\r\n\r\nfor.body.i: ; preds = %if.end.i, %entry\r\n %q.0139.i = phi i16 [ 0, %entry ], [ %add.i, %if.end.i ]\r\n %idxprom.i = sext i16 0 to i64\r\n br i1 false, label %if.end.i, label %if.then.i\r\n\r\nif.then.i: ; preds = %for.body.i\r\n br i1 false, label %cond.end41.i, label %cond.end41.i\r\n\r\ncond.end41.i: ; preds = %if.then.i, %if.then.i\r\n br label %if.end.i\r\n\r\nif.end.i: ; preds = %cond.end41.i, %for.body.i\r\n %.in.i = phi ptr [ null, %cond.end41.i ], [ poison, %for.body.i ]\r\n %0 = load i16, ptr %.in.i, align 2\r\n %add.i = add i16 %q.0139.i, 1\r\n %tobool.not.i = icmp eq i16 %add.i, 0\r\n br i1 %tobool.not.i, label %m.exit, label %for.body.i\r\n\r\nm.exit: ; preds = %if.end.i\r\n %.lcssa = phi i16 [ %0, %if.end.i ]\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\r\n```\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-2/llvm/llvm/lib/Transforms/Vectorize/VPlan.cpp:249: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt --passes=loop-vectorize reduced.ll\r\n #0 0x00005ed60f56eb60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)\r\n #1 0x00005ed60f56bf6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)\r\n #2 0x00005ed60f56c0c5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f973de42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007f973de969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007f973de969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007f973de969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007f973de42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007f973de287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007f973de2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007f973de39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005ed60e6cbb72 llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ee1b72)\r\n#12 0x00005ed60e6fa9a6 llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f109a6)\r\n#13 0x00005ed60e6fbbdf llvm::VPInstruction::execute(llvm::VPTransformState&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f11bdf)\r\n#14 0x00005ed60e6d74ff llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1eed4ff)\r\n#15 0x00005ed60e6cd9e0 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ee39e0)\r\n#16 0x00005ed60e6d90e6 llvm::VPlan::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1eef0e6)\r\n#17 0x00005ed60e5d76f3 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ded6f3)\r\n#18 0x00005ed60e5e9718 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dff718)\r\n#19 0x00005ed60e5eb73e 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0173e)\r\n#20 0x00005ed60e5ec88d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0288d)\r\n#21 0x00005ed60d4f3276 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09276)\r\n#22 0x00005ed60f395141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)\r\n#23 0x00005ed60d4eabd6 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)\r\n#24 0x00005ed60f393e3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)\r\n#25 0x00005ed60d4f2dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)\r\n#26 0x00005ed60f391cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)\r\n#27 0x00005ed60cd6cce5 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)\r\n#28 0x00005ed60cd5f316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)\r\n#29 0x00007f973de29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#30 0x00007f973de29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#31 0x00007f973de29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#32 0x00005ed60cd54f95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt\r\n```\r\nGodbolt: https://godbolt.org/z/jYWea8z4q\r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
111887
https://github.com/llvm/llvm-project/issues/111887
crash
195486950fa64938e62f6d85d31222fa41d0ee09
2024-10-10T18:31:43
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "4b5018d2311596778cade4db5177e2ab879cc218", "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": [ [ 1293, 1300 ], [ 6322, 6328 ], [ 18820, 18826 ], [ 18916, 18921 ], [ 18936, 18941 ], [ 19015, 19031 ], [ 19054, 19074 ] ], "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::buildExternalUses", "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 4b5018d2311596778cade4db5177e2ab879cc218 Author: Alexey Bataev <[email protected]> Date: Thu Oct 10 13:40:22 2024 -0700 [SLP]Track repeated reduced value as it might be vectorized Need to track changes with the repeated reduced value, since it might be vectorized in the next attempt for reduction vectorization, to correctly generate the code and avoid compiler crash. Fixes #111887 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 94de520a2715..e2958c49b8ca 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1293,8 +1293,7 @@ public: using InstrList = SmallVector<Instruction *, 16>; using ValueSet = SmallPtrSet<Value *, 16>; using StoreList = SmallVector<StoreInst *, 8>; - using ExtraValueToDebugLocsMap = - MapVector<Value *, SmallVector<Instruction *, 2>>; + using ExtraValueToDebugLocsMap = SmallDenseSet<Value *, 4>; using OrdersType = SmallVector<unsigned, 4>; BoUpSLP(Function *Func, ScalarEvolution *Se, TargetTransformInfo *Tti, @@ -6322,7 +6321,7 @@ void BoUpSLP::buildExternalUses( continue; // Check if the scalar is externally used as an extra arg. - const auto *ExtI = ExternallyUsedValues.find(Scalar); + const auto ExtI = ExternallyUsedValues.find(Scalar); if (ExtI != ExternallyUsedValues.end()) { int FoundLane = Entry->findLaneForValue(Scalar); LLVM_DEBUG(dbgs() << "SLP: Need to extract: Extra arg from lane " @@ -18820,7 +18819,7 @@ public: // List of the values that were reduced in other trees as part of gather // nodes and thus requiring extract if fully vectorized in other trees. SmallPtrSet<Value *, 4> RequiredExtract; - Value *VectorizedTree = nullptr; + WeakTrackingVH VectorizedTree = nullptr; bool CheckForReusedReductionOps = false; // Try to vectorize elements based on their type. SmallVector<InstructionsState> States; @@ -18916,6 +18915,7 @@ public: bool SameScaleFactor = false; bool OptReusedScalars = IsSupportedHorRdxIdentityOp && SameValuesCounter.size() != Candidates.size(); + BoUpSLP::ExtraValueToDebugLocsMap ExternallyUsedValues; if (OptReusedScalars) { SameScaleFactor = (RdxKind == RecurKind::Add || RdxKind == RecurKind::FAdd || @@ -18936,6 +18936,7 @@ public: emitScaleForReusedOps(Candidates.front(), Builder, Cnt); VectorizedTree = GetNewVectorizedTree(VectorizedTree, RedVal); VectorizedVals.try_emplace(OrigV, Cnt); + ExternallyUsedValues.insert(OrigV); continue; } } @@ -19015,17 +19016,18 @@ public: V.reorderBottomToTop(/*IgnoreReorder=*/true); // Keep extracted other reduction values, if they are used in the // vectorization trees. - BoUpSLP::ExtraValueToDebugLocsMap LocalExternallyUsedValues; + BoUpSLP::ExtraValueToDebugLocsMap LocalExternallyUsedValues( + ExternallyUsedValues); // The reduction root is used as the insertion point for new // instructions, so set it as externally used to prevent it from being // deleted. - LocalExternallyUsedValues[ReductionRoot]; + LocalExternallyUsedValues.insert(ReductionRoot); for (unsigned Cnt = 0, Sz = ReducedVals.size(); Cnt < Sz; ++Cnt) { if (Cnt == I || (ShuffledExtracts && Cnt == I - 1)) continue; for (Value *V : ReducedVals[Cnt]) if (isa<Instruction>(V)) - LocalExternallyUsedValues[TrackedVals[V]]; + LocalExternallyUsedValues.insert(TrackedVals[V]); } if (!IsSupportedHorRdxIdentityOp) { // Number of uses of the candidates in the vector of values. @@ -19054,21 +19056,21 @@ public: // Check if the scalar was vectorized as part of the vectorization // tree but not the top node. if (!VLScalars.contains(RdxVal) && V.isVectorized(RdxVal)) { - LocalExternallyUsedValues[RdxVal]; + LocalExternallyUsedValues.insert(RdxVal); continue; } Value *OrigV = TrackedToOrig.at(RdxVal); unsigned NumOps = VectorizedVals.lookup(OrigV) + At(SameValuesCounter, OrigV); if (NumOps != ReducedValsToOps.at(OrigV).size()) - LocalExternallyUsedValues[RdxVal]; + LocalExternallyUsedValues.insert(RdxVal); } // Do not need the list of reused scalars in regular mode anymore. if (!IsSupportedHorRdxIdentityOp) SameValuesCounter.clear(); for (Value *RdxVal : VL) if (RequiredExtract.contains(RdxVal)) - LocalExternallyUsedValues[RdxVal]; + LocalExternallyUsedValues.insert(RdxVal); V.buildExternalUses(LocalExternallyUsedValues); V.computeMinimumValueSizes();
[ { "file": "llvm/test/Transforms/SLPVectorizer/RISCV/reduced-value-repeated-and-vectorized.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr=+v < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nentry:\n %0 = load i16, ptr null, align 2\n %1 = xor i16 %0, 0\n %2 = tail call i16 @llvm.smax.i16(i16 %1, i16 %0)\n %3 = tail call i16 @llvm.smax.i16(i16 0, i16 %2)\n %4 = load i16, ptr getelementptr inbounds (i8, ptr null, i64 6), align 2\n %5 = xor i16 %4, 0\n %6 = tail call i16 @llvm.smax.i16(i16 %5, i16 %0)\n %7 = tail call i16 @llvm.smax.i16(i16 %3, i16 %6)\n %8 = load i16, ptr getelementptr (i8, ptr null, i64 12), align 2\n %9 = xor i16 %8, 0\n %10 = tail call i16 @llvm.smax.i16(i16 %9, i16 %0)\n %11 = tail call i16 @llvm.smax.i16(i16 %7, i16 %10)\n %12 = load i16, ptr getelementptr (i8, ptr null, i64 18), align 2\n %13 = xor i16 %12, 0\n %14 = tail call i16 @llvm.smax.i16(i16 %13, i16 %0)\n %15 = tail call i16 @llvm.smax.i16(i16 %11, i16 %14)\n %16 = tail call i16 @llvm.smax.i16(i16 %15, i16 0)\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.smax.i16(i16, i16) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP-Vectorizer] Segfault in `HorizontalReduction::matchAssociativeReduction`", "body": "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\nfor.body.preheader:\r\n %0 = load i16, ptr null, align 2\r\n %1 = xor i16 %0, 0\r\n %2 = tail call i16 @llvm.smax.i16(i16 %1, i16 %0)\r\n %3 = tail call i16 @llvm.smax.i16(i16 0, i16 %2)\r\n %4 = load i16, ptr getelementptr inbounds (i8, ptr null, i64 6), align 2\r\n %5 = xor i16 %4, 0\r\n %6 = tail call i16 @llvm.smax.i16(i16 %5, i16 %0)\r\n %7 = tail call i16 @llvm.smax.i16(i16 %3, i16 %6)\r\n %8 = load i16, ptr getelementptr (i8, ptr null, i64 12), align 2\r\n %9 = xor i16 %8, 0\r\n %10 = tail call i16 @llvm.smax.i16(i16 %9, i16 %0)\r\n %11 = tail call i16 @llvm.smax.i16(i16 %7, i16 %10)\r\n %12 = load i16, ptr getelementptr (i8, ptr null, i64 18), align 2\r\n %13 = xor i16 %12, 0\r\n %14 = tail call i16 @llvm.smax.i16(i16 %13, i16 %0)\r\n %15 = tail call i16 @llvm.smax.i16(i16 %11, i16 %14)\r\n %16 = tail call i16 @llvm.smax.i16(i16 %15, i16 0)\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i16 @llvm.smax.i16(i16, i16) #1\r\n\r\n; uselistorder directives\r\nuselistorder ptr null, { 3, 2, 1, 0 }\r\nuselistorder ptr @llvm.smax.i16, { 8, 7, 6, 5, 4, 3, 2, 1, 0 }\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-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,-zacas,-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\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\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=slp-vectorizer 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\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=slp-vectorizer reduced.ll\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x0000602da32b35e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x30fe5e0)\r\n #1 0x0000602da32b09ef llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x30fb9ef)\r\n #2 0x0000602da32b0b45 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007ea045842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000602da29cea64 llvm::getUnderlyingObject(llvm::Value const*, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2819a64)\r\n #5 0x0000602da22d706d (anonymous namespace)::HorizontalReduction::matchAssociativeReduction(llvm::slpvectorizer::BoUpSLP&, llvm::Instruction*, llvm::ScalarEvolution&, llvm::DataLayout const&, llvm::TargetLibraryInfo const&)::'lambda0'(unsigned long, llvm::LoadInst*)::operator()(unsigned long, llvm::LoadInst*) const SLPVectorizer.cpp:0:0\r\n #6 0x0000602da22d797e generateKeySubkey(llvm::Value*, llvm::TargetLibraryInfo const*, llvm::function_ref<llvm::hash_code (unsigned long, llvm::LoadInst*)>, bool) (.constprop.0) SLPVectorizer.cpp:0:0\r\n #7 0x0000602da230d085 (anonymous namespace)::HorizontalReduction::matchAssociativeReduction(llvm::slpvectorizer::BoUpSLP&, llvm::Instruction*, llvm::ScalarEvolution&, llvm::DataLayout const&, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n #8 0x0000602da231f7cc llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x216a7cc)\r\n #9 0x0000602da2323ec2 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#10 0x0000602da2327dfb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2172dfb)\r\n#11 0x0000602da232e400 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#12 0x0000602da232ef62 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2179f62)\r\n#13 0x0000602da1071366 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, 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+0xebc366)\r\n#14 0x0000602da30bc88f 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+0x2f0788f)\r\n#15 0x0000602da1073bb6 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+0xebebb6)\r\n#16 0x0000602da30bac1b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f05c1b)\r\n#17 0x0000602da106fcc6 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+0xebacc6)\r\n#18 0x0000602da30bb77d 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+0x2f0677d)\r\n#19 0x0000602da088061b 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+0x6cb61b)\r\n#20 0x0000602da0872331 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6bd331)\r\n#21 0x00007ea045829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#22 0x00007ea045829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#23 0x00007ea045829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#24 0x0000602da0868855 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6b3855)\r\nzsh: segmentation fault (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/nbar8q6ej\r\n\r\nFound via fuzzer (C program before reduction).", "author": "patrick-rivos", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
121745
https://github.com/llvm/llvm-project/issues/121745
miscompilation
3874c64418d2a7e36eab9af9253d905b48b36078
2025-01-06T10:26:21
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "f9369cc602272796c15de1065a782f812e791df3", "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": [ [ 562, 582 ], [ 1086, 1103 ] ], "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": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::adjustFixedOrderRecurrences", "VPlanTransforms::clearReductionWrapFlags", "collectUsersRecursively", "createScalarIVSteps", "legalizeAndOptimizeInductions" ], "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 f9369cc602272796c15de1065a782f812e791df3 Author: Florian Hahn <[email protected]> Date: Mon Jan 6 22:40:41 2025 +0000 [VPlan] Make sure last IV increment value is available if needed. Legalize extract-from-ends using uniform VPReplicateRecipe of wide inductions to use regular VPReplicateRecipe, so the correct end value is available. Fixes https://github.com/llvm/llvm-project/issues/121745. diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 395287bde76f..3e3f5adf73a0 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -562,21 +562,63 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind, return Builder.createScalarIVSteps(InductionOpcode, FPBinOp, BaseIV, Step); } +static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) { + SetVector<VPUser *> Users(V->user_begin(), V->user_end()); + for (unsigned I = 0; I != Users.size(); ++I) { + VPRecipeBase *Cur = cast<VPRecipeBase>(Users[I]); + if (isa<VPHeaderPHIRecipe>(Cur)) + continue; + for (VPValue *V : Cur->definedValues()) + Users.insert(V->user_begin(), V->user_end()); + } + return Users.takeVector(); +} + /// Legalize VPWidenPointerInductionRecipe, by replacing it with a PtrAdd /// (IndStart, ScalarIVSteps (0, Step)) if only its scalar values are used, as /// VPWidenPointerInductionRecipe will generate vectors only. If some users /// require vectors while other require scalars, the scalar uses need to extract /// the scalars from the generated vectors (Note that this is different to how -/// int/fp inductions are handled). Also optimize VPWidenIntOrFpInductionRecipe, -/// if any of its users needs scalar values, by providing them scalar steps -/// built on the canonical scalar IV and update the original IV's users. This is -/// an optional optimization to reduce the needs of vector extracts. +/// int/fp inductions are handled). Legalize extract-from-ends using uniform +/// VPReplicateRecipe of wide inductions to use regular VPReplicateRecipe, so +/// the correct end value is available. Also optimize +/// VPWidenIntOrFpInductionRecipe, if any of its users needs scalar values, by +/// providing them scalar steps built on the canonical scalar IV and update the +/// original IV's users. This is an optional optimization to reduce the needs of +/// vector extracts. static void legalizeAndOptimizeInductions(VPlan &Plan) { + using namespace llvm::VPlanPatternMatch; SmallVector<VPRecipeBase *> ToRemove; VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock(); bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1)); VPBuilder Builder(HeaderVPBB, HeaderVPBB->getFirstNonPhi()); for (VPRecipeBase &Phi : HeaderVPBB->phis()) { + auto *PhiR = dyn_cast<VPHeaderPHIRecipe>(&Phi); + if (!PhiR) + break; + + // Check if any uniform VPReplicateRecipes using the phi recipe are used by + // ExtractFromEnd. Those must be replaced by a regular VPReplicateRecipe to + // ensure the final value is available. + // TODO: Remove once uniformity analysis is done on VPlan. + for (VPUser *U : collectUsersRecursively(PhiR)) { + auto *ExitIRI = dyn_cast<VPIRInstruction>(U); + VPValue *Op; + if (!ExitIRI || !match(ExitIRI->getOperand(0), + m_VPInstruction<VPInstruction::ExtractFromEnd>( + m_VPValue(Op), m_VPValue()))) + continue; + auto *RepR = dyn_cast<VPReplicateRecipe>(Op); + if (!RepR || !RepR->isUniform()) + continue; + assert(!RepR->isPredicated() && "RepR must not be predicated"); + Instruction *I = RepR->getUnderlyingInstr(); + auto *Clone = + new VPReplicateRecipe(I, RepR->operands(), /*IsUniform*/ false); + Clone->insertAfter(RepR); + RepR->replaceAllUsesWith(Clone); + } + // Replace wide pointer inductions which have only their scalars used by // PtrAdd(IndStart, ScalarIVSteps (0, Step)). if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) { @@ -1086,18 +1128,6 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan, return true; } -static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) { - SetVector<VPUser *> Users(V->user_begin(), V->user_end()); - for (unsigned I = 0; I != Users.size(); ++I) { - VPRecipeBase *Cur = cast<VPRecipeBase>(Users[I]); - if (isa<VPHeaderPHIRecipe>(Cur)) - continue; - for (VPValue *V : Cur->definedValues()) - Users.insert(V->user_begin(), V->user_end()); - } - return Users.takeVector(); -} - void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) { for (VPRecipeBase &R : Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
[ { "file": "llvm/test/Transforms/LoopVectorize/iv_outside_user.ll", "commands": [ "opt -S -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s", "opt -S -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 < %s" ], "tests": [ { "test_name": "test_iv_uniform_with_outside_use_scev_simplification", "test_body": "define i32 @test_iv_uniform_with_outside_use_scev_simplification(ptr %dst) {\nentry:\n %step.1 = sext i8 0 to i32\n %step.2 = add nsw i32 %step.1, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.dst = getelementptr inbounds i16, ptr %dst, i32 %iv\n store i16 0, ptr %gep.dst, align 2\n %iv.next = add i32 %step.2, %iv\n %cmp.i = icmp slt i32 %iv.next, 8\n br i1 %cmp.i, label %loop, label %e.exit\n\ne.exit: ; preds = %loop\n %res = phi i32 [ %iv.next, %loop ]\n ret i32 %res\n}\n", "additional_args": "-src-unroll=8 -tgt-unroll=8", "lli_expected_out": null } ] } ]
{ "title": "[clang] Miscompilation at -O2/3", "body": "This code prints 8 at `-O0/1` and prints 1 at `-O2/3`:\n\n```c\nint printf(const char *, ...);\nstatic char a;\nstatic char *b = &a;\nstatic int c;\nshort d;\nvoid e() {\n short f[8];\n char **g[] = {&b, &b};\n c = 0;\n for (; c < 8; c = 81 + 462704684 + *b - 462704765 + c + 1)\n f[c] = 0;\n d = f[5];\n}\nint main() {\n e();\n printf(\"%d\\n\", c);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/MEKz8oncP\n\nBisected to https://github.com/llvm/llvm-project/commit/df4a615c988f3ae56f7e68a7df86acb60f16493a, which was committed by @fhahn ", "author": "cardigan1008", "labels": [ "miscompilation", "vectorizers" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced testcase: https://alive2.llvm.org/ce/z/6Bg63G\n```\n; bin/opt -passes=loop-vectorize 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 @src() {\nentry:\n %f.i = alloca [8 x i16], align 16\n %conv.i = sext i8 0 to i32\n %invariant.op.i = add nsw i32 %conv.i, 1\n br label %for.body.i\n\nfor.body.i: ; preds = %for.body.i, %entry\n %0 = phi i32 [ 0, %entry ], [ %add2.reass.i, %for.body.i ]\n %idxprom.i = sext i32 %0 to i64\n %arrayidx.i = getelementptr [8 x i16], ptr %f.i, i64 0, i64 %idxprom.i\n store i16 0, ptr %arrayidx.i, align 2\n %add2.reass.i = add i32 %invariant.op.i, %0\n %cmp.i = icmp slt i32 %add2.reass.i, 8\n br i1 %cmp.i, label %for.body.i, label %e.exit\n\ne.exit: ; preds = %for.body.i\n %add2.reass.i.lcssa = phi i32 [ %add2.reass.i, %for.body.i ]\n ret i32 %add2.reass.i.lcssa\n}\n```" }, { "author": "fhahn", "body": "Looking into it now, thanks" }, { "author": "yaoxinliu", "body": "Thank God! clang19 works as expected." } ] }
true
null
94328
https://github.com/llvm/llvm-project/issues/94328
crash
098bd842a7e50853fa231f8b73c24ec5006fe063
2024-06-04T09:16:11
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "008df3cf85e9bb1532c079bfd7a7a00e90e0a3c6", "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": [ [ 3914, 3932 ], [ 9516, 9521 ] ], "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::collectLoopUniforms", "VPReplicateRecipe::execute" ], "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 008df3cf85e9bb1532c079bfd7a7a00e90e0a3c6 Author: Florian Hahn <[email protected]> Date: Fri Jul 19 12:02:25 2024 +0100 [LV] Check isPredInst instead of isScalarWithPred in uniform analysis. (#98892) Any instruction marked as uniform will result in a uniform VPReplicateRecipe. If it requires predication, it will be placed in a replicate region, even if isScalarWithPredication returns false. Check isPredicatedInst instead of isScalarWithPredication to avoid generating uniform VPReplicateRecipes placed inside a replicate region. This fixes an assertion when using scalable VFs. Fixes https://github.com/llvm/llvm-project/issues/80416. Fixes https://github.com/llvm/llvm-project/issues/94328. Fixes https://github.com/llvm/llvm-project/issues/99625. PR: https://github.com/llvm/llvm-project/pull/98892 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index fbca4cdcbcfc..cceed75aa50b 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -3914,19 +3914,19 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) { SetVector<Instruction *> Worklist; // Add uniform instructions demanding lane 0 to the worklist. Instructions - // that are scalar with predication must not be considered uniform after + // that require predication must not be considered uniform after // vectorization, because that would create an erroneous replicating region // where only a single instance out of VF should be formed. - // TODO: optimize such seldom cases if found important, see PR40816. auto addToWorklistIfAllowed = [&](Instruction *I) -> void { if (isOutOfScope(I)) { LLVM_DEBUG(dbgs() << "LV: Found not uniform due to scope: " << *I << "\n"); return; } - if (isScalarWithPredication(I, VF)) { - LLVM_DEBUG(dbgs() << "LV: Found not uniform being ScalarWithPredication: " - << *I << "\n"); + if (isPredicatedInst(I)) { + LLVM_DEBUG( + dbgs() << "LV: Found not uniform due to requiring predication: " << *I + << "\n"); return; } LLVM_DEBUG(dbgs() << "LV: Found uniform instruction: " << *I << "\n"); @@ -9516,6 +9516,8 @@ void VPInterleaveRecipe::execute(VPTransformState &State) { void VPReplicateRecipe::execute(VPTransformState &State) { Instruction *UI = getUnderlyingInstr(); if (State.Instance) { // Generate a single instance. + assert((State.VF.isScalar() || !isUniform()) && + "uniform recipe shouldn't be predicated"); assert(!State.VF.isScalable() && "Can't scalarize a scalable vector"); State.ILV->scalarizeInstruction(UI, this, *State.Instance, State); // Insert scalar instance packing it into a vector.
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/divs-with-scalable-vfs.ll", "commands": [ "opt -p loop-vectorize -mtriple aarch64 -mcpu=neoverse-v1 -S %s" ], "tests": [ { "test_name": "udiv_urem_feeding_gep", "test_body": "define void @udiv_urem_feeding_gep(i64 %x, ptr %dst, i64 %N) {\nentry:\n %mul.1.i = mul i64 %x, %x\n %mul.2.i = mul i64 %mul.1.i, %x\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %div.i = udiv i64 %iv, %mul.2.i\n %rem.i = urem i64 %iv, %mul.2.i\n %div.1.i = udiv i64 %rem.i, %mul.1.i\n %rem.1.i = urem i64 %rem.i, %mul.1.i\n %div.2.i = udiv i64 %rem.1.i, %x\n %rem.2.i = urem i64 %rem.1.i, %x\n %mul.i = mul i64 %x, %div.i\n %add.i = add i64 %mul.i, %div.1.i\n %mul.1.i9 = mul i64 %add.i, %x\n %add.1.i = add i64 %mul.1.i9, %div.2.i\n %mul.2.i11 = mul i64 %add.1.i, %x\n %add.2.i = add i64 %mul.2.i11, %rem.2.i\n %sext.i = shl i64 %add.2.i, 32\n %conv6.i = ashr i64 %sext.i, 32\n %gep = getelementptr i64, ptr %dst, i64 %conv6.i\n store i64 %div.i, ptr %gep, align 4\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, %N\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sdiv_feeding_gep_predicated", "test_body": "define void @sdiv_feeding_gep_predicated(ptr %dst, i32 %x, i64 %M, i64 %conv6, i64 %N) {\nentry:\n %conv61 = zext i32 %x to i64\n br label %loop\n\nloop: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c = icmp ule i64 %iv, %M\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop\n %div18 = sdiv i64 %M, %conv6\n %conv20 = trunc i64 %div18 to i32\n %mul30 = mul i64 %div18, %conv61\n %sub31 = sub i64 %iv, %mul30\n %conv34 = trunc i64 %sub31 to i32\n %mul35 = mul i32 %x, %conv20\n %add36 = add i32 %mul35, %conv34\n %idxprom = sext i32 %add36 to i64\n %gep = getelementptr double, ptr %dst, i64 %idxprom\n store double 0.000000e+00, ptr %gep, align 8\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop\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.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "sdiv_feeding_gep", "test_body": "define void @sdiv_feeding_gep(ptr %dst, i32 %x, i64 %M, i64 %conv6, i64 %N) {\nentry:\n %conv61 = zext i32 %x to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %div18 = sdiv i64 %M, %conv6\n %conv20 = trunc i64 %div18 to i32\n %mul30 = mul i64 %div18, %conv61\n %sub31 = sub i64 %iv, %mul30\n %conv34 = trunc i64 %sub31 to i32\n %mul35 = mul i32 %x, %conv20\n %add36 = add i32 %mul35, %conv34\n %idxprom = sext i32 %add36 to i64\n %gep = getelementptr double, ptr %dst, i64 %idxprom\n store double 0.000000e+00, ptr %gep, align 8\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 } ] } ]
{ "title": "[VPlan] Report \"Assertion `!State->VF.isScalable() && \"VF is assumed to be non scalable.\"' failed\"", "body": "The IR is put at the end.\r\n\r\nCompile command is `opt -passes=loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue`\r\n\r\nThe error is\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:734: virtual void llvm::VPRegionBlock::execute(llvm::VPTransformState*): Assertion `!State->VF.isScalable() && \"VF is assumed to be non scalable.\"' failed.\r\n```\r\n\r\nIt can be seen at https://godbolt.org/z/s4bqzdKPP\r\n\r\n```\r\n; ModuleID = 'test.cpp'\r\nsource_filename = \"test.cpp\"\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"aarch64-unknown-linux-gnu\"\r\n\r\n%struct.ident_t = type { i32, i32, i32, i32, ptr }\r\n\r\n@0 = private unnamed_addr constant [23 x i8] c\";unknown;unknown;0;0;;\\00\", align 1\r\n@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 514, i32 0, i32 22, ptr @0 }, align 8\r\n@2 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8\r\n\r\n; Function Attrs: mustprogress nounwind uwtable vscale_range(1,16)\r\ndefine dso_local void @_Z4testiiPdS_(i32 noundef %nx, i32 noundef %ik, ptr noundef %out, ptr noundef %rspace) local_unnamed_addr #0 {\r\nentry:\r\n %nx.addr = alloca i32, align 4\r\n %ik.addr = alloca i32, align 4\r\n %out.addr = alloca ptr, align 8\r\n %rspace.addr = alloca ptr, align 8\r\n store i32 %nx, ptr %nx.addr, align 4\r\n store i32 %ik, ptr %ik.addr, align 4\r\n store ptr %out, ptr %out.addr, align 8\r\n store ptr %rspace, ptr %rspace.addr, align 8\r\n call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr nonnull @2, i32 4, ptr nonnull @_Z4testiiPdS_.omp_outlined, ptr nonnull %nx.addr, ptr nonnull %ik.addr, ptr nonnull %out.addr, ptr nonnull %rspace.addr)\r\n ret void\r\n}\r\n\r\n; Function Attrs: alwaysinline norecurse nounwind uwtable vscale_range(1,16)\r\ndefine internal void @_Z4testiiPdS_.omp_outlined(ptr noalias nocapture noundef readonly %.global_tid., ptr noalias nocapture noundef readnone %.bound_tid., ptr noalias nocapture noundef nonnull readonly align 4 dereferenceable(4) %nx, ptr noalias nocapture noundef nonnull readonly align 4 dereferenceable(4) %ik, ptr noalias nocapture noundef nonnull readonly align 8 dereferenceable(8) %out, ptr noalias nocapture noundef nonnull readonly align 8 dereferenceable(8) %rspace) #1 {\r\nentry:\r\n %.omp.lb = alloca i64, align 8\r\n %.omp.ub = alloca i64, align 8\r\n %.omp.stride = alloca i64, align 8\r\n %.omp.is_last = alloca i32, align 4\r\n %0 = load i32, ptr %nx, align 4\r\n %1 = load i32, ptr %ik, align 4\r\n %cmp = icmp sgt i32 %0, 0\r\n %cmp8 = icmp sgt i32 %1, 0\r\n %or.cond = select i1 %cmp, i1 %cmp8, i1 false\r\n br i1 %or.cond, label %omp.precond.then, label %omp.precond.end\r\n\r\nomp.precond.then: ; preds = %entry\r\n %conv = zext i32 %0 to i64\r\n %conv6 = zext i32 %1 to i64\r\n %mul = mul nuw nsw i64 %conv6, %conv\r\n %sub7 = add nsw i64 %mul, -1\r\n call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %.omp.lb) #3\r\n store i64 0, ptr %.omp.lb, align 8\r\n call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %.omp.ub) #3\r\n store i64 %sub7, ptr %.omp.ub, align 8\r\n call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %.omp.stride) #3\r\n store i64 1, ptr %.omp.stride, align 8\r\n call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %.omp.is_last) #3\r\n store i32 0, ptr %.omp.is_last, align 4\r\n %2 = load i32, ptr %.global_tid., align 4\r\n call void @__kmpc_for_static_init_8(ptr nonnull @1, i32 %2, i32 33, ptr nonnull %.omp.is_last, ptr nonnull %.omp.lb, ptr nonnull %.omp.ub, ptr nonnull %.omp.stride, i64 1, i64 512)\r\n %3 = load i64, ptr %.omp.ub, align 8\r\n %cond60 = call i64 @llvm.smin.i64(i64 %3, i64 %sub7)\r\n store i64 %cond60, ptr %.omp.ub, align 8\r\n %4 = load i64, ptr %.omp.lb, align 8\r\n %cmp12.not61 = icmp sgt i64 %4, %cond60\r\n br i1 %cmp12.not61, label %omp.dispatch.end, label %omp.inner.for.cond.preheader.lr.ph\r\n\r\nomp.inner.for.cond.preheader.lr.ph: ; preds = %omp.precond.then\r\n br label %omp.inner.for.cond.preheader\r\n\r\nomp.inner.for.cond.preheader: ; preds = %omp.inner.for.cond.preheader.lr.ph, %omp.dispatch.inc\r\n %5 = phi i64 [ %4, %omp.inner.for.cond.preheader.lr.ph ], [ %add42, %omp.dispatch.inc ]\r\n %cond62 = phi i64 [ %cond60, %omp.inner.for.cond.preheader.lr.ph ], [ %cond, %omp.dispatch.inc ]\r\n %smax = call i64 @llvm.smax.i64(i64 %cond62, i64 %5)\r\n %6 = add i64 %smax, 1\r\n %7 = load ptr, ptr %rspace, align 8\r\n %8 = load ptr, ptr %out, align 8\r\n br label %omp.inner.for.body\r\n\r\nomp.inner.for.body: ; preds = %omp.inner.for.cond.preheader, %omp.inner.for.body\r\n %.omp.iv.059 = phi i64 [ %5, %omp.inner.for.cond.preheader ], [ %add41, %omp.inner.for.body ]\r\n %div18 = sdiv i64 %.omp.iv.059, %conv6\r\n %conv20 = trunc i64 %div18 to i32\r\n %mul30 = mul nsw i64 %div18, %conv6\r\n %sub31 = sub nsw i64 %.omp.iv.059, %mul30\r\n %conv34 = trunc i64 %sub31 to i32\r\n %mul35 = mul nsw i32 %1, %conv20\r\n %add36 = add nsw i32 %mul35, %conv34\r\n %idxprom = sext i32 %add36 to i64\r\n %arrayidx = getelementptr inbounds double, ptr %7, i64 %idxprom\r\n %9 = load double, ptr %arrayidx, align 8\r\n %arrayidx40 = getelementptr inbounds double, ptr %8, i64 %idxprom\r\n store double %9, ptr %arrayidx40, align 8\r\n %add41 = add i64 %.omp.iv.059, 1\r\n %exitcond = icmp ne i64 %add41, %6\r\n br i1 %exitcond, label %omp.inner.for.body, label %omp.dispatch.inc\r\n\r\nomp.dispatch.inc: ; preds = %omp.inner.for.body\r\n %10 = load i64, ptr %.omp.stride, align 8\r\n %add42 = add nsw i64 %10, %5\r\n store i64 %add42, ptr %.omp.lb, align 8\r\n %add43 = add nsw i64 %10, %cond62\r\n %cond = call i64 @llvm.smin.i64(i64 %add43, i64 %sub7)\r\n store i64 %cond, ptr %.omp.ub, align 8\r\n %cmp12.not = icmp sgt i64 %add42, %cond\r\n br i1 %cmp12.not, label %omp.dispatch.cond.omp.dispatch.end_crit_edge, label %omp.inner.for.cond.preheader\r\n\r\nomp.dispatch.cond.omp.dispatch.end_crit_edge: ; preds = %omp.dispatch.inc\r\n br label %omp.dispatch.end\r\n\r\nomp.dispatch.end: ; preds = %omp.dispatch.cond.omp.dispatch.end_crit_edge, %omp.precond.then\r\n call void @__kmpc_for_static_fini(ptr nonnull @1, i32 %2)\r\n call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %.omp.is_last) #3\r\n call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %.omp.stride) #3\r\n call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %.omp.ub) #3\r\n call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %.omp.lb) #3\r\n br label %omp.precond.end\r\n\r\nomp.precond.end: ; preds = %omp.dispatch.end, %entry\r\n ret void\r\n}\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2\r\n\r\n; Function Attrs: nounwind\r\ndeclare void @__kmpc_for_static_init_8(ptr, i32, i32, ptr, ptr, ptr, ptr, i64, i64) local_unnamed_addr #3\r\n\r\n; Function Attrs: nounwind\r\ndeclare void @__kmpc_for_static_fini(ptr, i32) local_unnamed_addr #3\r\n\r\n; Function Attrs: nounwind\r\ndeclare void @__kmpc_fork_call(ptr, i32, ptr, ...) local_unnamed_addr #3\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.smin.i64(i64, i64) #4\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.smax.i64(i64, i64) #4\r\n\r\nattributes #0 = { mustprogress nounwind uwtable vscale_range(1,16) \"frame-pointer\"=\"non-leaf\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic\" \"target-features\"=\"+fp-armv8,+fullfp16,+neon,+sve,+v8a,-fmv\" }\r\nattributes #1 = { alwaysinline norecurse nounwind uwtable vscale_range(1,16) \"frame-pointer\"=\"non-leaf\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic\" \"target-features\"=\"+fp-armv8,+fullfp16,+neon,+sve,+v8a,-fmv\" }\r\nattributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }\r\nattributes #3 = { nounwind }\r\nattributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n\r\n```", "author": "eastB233", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "eastB233", "body": "Simpler test case is\r\n```c\r\nextern const int npy;\r\nextern const int nx;\r\ndouble* rspace;\r\n\r\nvoid recip2real(double* out, const double factor)\r\n{\r\n#ifdef _OPENMP\r\n#pragma omp parallel for collapse(2)\r\n#endif\r\n for (int ix = 0; ix < nx; ++ix)\r\n {\r\n for (int ipy = 0; ipy < npy; ++ipy) {\r\n out[ix * npy + ipy] += factor * rspace[ix * npy + ipy];\r\n }\r\n }\r\n}\r\n```\r\n\r\nCommand is `clang -O3 -march=armv9-a -fopenmp -mllvm -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S`\r\n\r\nIt can be seen at https://godbolt.org/z/6MGsecEr5" }, { "author": "eastB233", "body": "I don't know much about VPlan, and as far as I understand by tracing the code,\r\n\r\n### first, it fails at the following VPlan\r\n```\r\nVPlan 'Initial VPlan for VF={vscale x 1,vscale x 2},UF>=1' {\r\nvp<%2> = original trip-count\r\n\r\nph:\r\n EMIT vp<%2> = EXPAND SCEV (1 + (-1 * %5) + ((-1 + ((zext i32 %0 to i64) * (sext i32 %1 to i64)))<nsw> smin %4))\r\nNo successors\r\n\r\nvector.ph:\r\n EMIT vp<%3> = TC > VF ? TC - VF : 0 vp<%2>\r\n EMIT vp<%4> = VF * Part + ir<0>\r\n EMIT vp<%5> = active lane mask vp<%4>, vp<%2>\r\nSuccessor(s): vector loop\r\n\r\n<x1> vector loop: {\r\n vector.body:\r\n EMIT vp<%6> = CANONICAL-INDUCTION\r\n ACTIVE-LANE-MASK-PHI vp<%7> = phi vp<%5>, vp<%27>\r\n vp<%8> = DERIVED-IV ir<%5> + vp<%6> * ir<1>\r\n vp<%9> = SCALAR-STEPS vp<%8>, ir<1>\r\n Successor(s): pred.sdiv\r\n\r\n <xVFxUF> pred.sdiv: {\r\n pred.sdiv.entry:\r\n BRANCH-ON-MASK vp<%7>\r\n Successor(s): pred.sdiv.if, pred.sdiv.continue\r\n\r\n pred.sdiv.if:\r\n CLONE ir<%div24> = sdiv vp<%9>, ir<%conv6>\r\n Successor(s): pred.sdiv.continue\r\n\r\n pred.sdiv.continue:\r\n PHI-PREDICATED-INSTRUCTION vp<%11> = ir<%div24>\r\n No successors\r\n }\r\n Successor(s): omp.inner.for.body.0\r\n\r\n omp.inner.for.body.0:\r\n CLONE ir<%conv26> = trunc vp<%11>\r\n CLONE ir<%mul36> = mul nsw vp<%11>, ir<%conv6>\r\n CLONE ir<%sub37> = sub nsw vp<%9>, ir<%mul36>\r\n CLONE ir<%conv40> = trunc ir<%sub37>\r\n CLONE ir<%mul41> = mul nsw ir<%1>, ir<%conv26>\r\n CLONE ir<%add42> = add nsw ir<%mul41>, ir<%conv40>\r\n CLONE ir<%idxprom> = sext ir<%add42>\r\n CLONE ir<%arrayidx> = getelementptr inbounds ir<%6>, ir<%idxprom>\r\n WIDEN ir<%8> = load ir<%arrayidx>, vp<%7>\r\n WIDEN ir<%mul43> = fmul contract ir<%2>, ir<%8>\r\n CLONE ir<%arrayidx47> = getelementptr inbounds ir<%7>, ir<%idxprom>\r\n WIDEN ir<%9> = load ir<%arrayidx47>, vp<%7>\r\n WIDEN ir<%add48> = fadd contract ir<%mul43>, ir<%9>\r\n WIDEN store ir<%arrayidx47>, ir<%add48>, vp<%7>\r\n EMIT vp<%25> = VF * UF + vp<%6>\r\n EMIT vp<%26> = VF * Part + vp<%6>\r\n EMIT vp<%27> = active lane mask vp<%26>, vp<%3>\r\n EMIT vp<%28> = not vp<%27>\r\n EMIT branch-on-cond vp<%28>\r\n No successors\r\n}\r\nSuccessor(s): middle.block\r\n```\r\n\r\nVPRegion `pred.sdiv` fails at assertion\r\n```c++\r\nvoid VPRegionBlock::execute(VPTransformState *State) {\r\n...\r\n if (!isReplicator()) {\r\n...\r\n return;\r\n }\r\n...\r\n for (...) {\r\n assert(!State->VF.isScalable() && \"VF is assumed to be non scalable.\");\r\n }\r\n}\r\n```\r\nI think VPRegion `pred.sdiv` should have `isReplicator() == false` or `pred.sdiv` just should not exist.\r\n\r\n### second, I find VPRegion `pred.sdiv` is splitted from `WorkList`\r\n```c++\r\nstatic void addReplicateRegions(VPlan &Plan) {\r\n SmallVector<VPReplicateRecipe *> WorkList;\r\n for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(\r\n vp_depth_first_deep(Plan.getEntry()))) {\r\n for (VPRecipeBase &R : *VPBB)\r\n if (auto *RepR = dyn_cast<VPReplicateRecipe>(&R)) {\r\n if (RepR->isPredicated())\r\n WorkList.push_back(RepR);\r\n }\r\n }\r\n...\r\n}\r\n```\r\nby VPRecipe `CLONE ir<%div24> = sdiv ir<%.omp.iv.065>, ir<%conv6>, vp<%7>`, where the instruction is `%div24 = sdiv i64 %.omp.iv.065, %conv6`\r\nI think this VPRecipe should have `isPredicated() == false` here, so it will not be splitted.\r\n\r\n### third, I find this VPRecipe is created here\r\n```c++\r\nVPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(...) {\r\n bool IsUniform = LoopVectorizationPlanner::getDecisionAndClampRange(\r\n [&](ElementCount VF) { return CM.isUniformAfterVectorization(I, VF); },\r\n Range);\r\n\r\n bool IsPredicated = CM.isPredicatedInst(I);\r\n...\r\n VPValue *BlockInMask = nullptr;\r\n if (!IsPredicated) {\r\n // Finalize the recipe for Instr, first if it is not predicated.\r\n LLVM_DEBUG(dbgs() << \"LV: Scalarizing:\" << *I << \"\\n\");\r\n } else {\r\n LLVM_DEBUG(dbgs() << \"LV: Scalarizing and predicating:\" << *I << \"\\n\");\r\n // Instructions marked for predication are replicated and a mask operand is\r\n // added initially. Masked replicate recipes will later be placed under an\r\n // if-then construct to prevent side-effects. Generate recipes to compute\r\n // the block mask for this region.\r\n BlockInMask = createBlockInMask(I->getParent(), Plan);\r\n }\r\n\r\n auto *Recipe = new VPReplicateRecipe(I, Plan.mapToVPValues(I->operands()),\r\n IsUniform, BlockInMask);\r\n return toVPRecipeResult(Recipe);\r\n}\r\n```\r\nI notice that instruction `I` (`%div24 = sdiv i64 %.omp.iv.065, %conv6`) do not need to vectorize, because function `isScalarAfterVectorization` returns true and `I` is just used to calculate the index.\r\nIt seems reasonable that a `scalar` instruction does not need `Predicated`.\r\n\r\n### So I try the following modification,\r\n```diff\r\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\r\nindex 907b8ce002e8..76a5704a61c5 100644\r\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\r\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\r\n@@ -9819,7 +9819,9 @@ VPRecipeOrVPValueTy VPRecipeBuilder::handleReplication(Instruction *I,\r\n [&](ElementCount VF) { return CM.isUniformAfterVectorization(I, VF); },\r\n Range);\r\n\r\n- bool IsPredicated = CM.isPredicatedInst(I);\r\n+ bool IsPredicated = LoopVectorizationPlanner::getDecisionAndClampRange(\r\n+ [&](ElementCount VF) { return CM.isPredicatedInst(I) && !CM.isScalarAfterVectorization(I, VF); },\r\n+ Range);\r\n\r\n // Even if the instruction is not marked as uniform, there are certain\r\n // intrinsic calls that can be effectively treated as such, so we check for\r\n```\r\n\r\nJust my guess, I'm not sure if it is correct direction." }, { "author": "eastB233", "body": "Ping @fhahn " }, { "author": "eastB233", "body": "I think I misunderstand something, and the changes above may be wrong.\r\n\r\nAnd I have another way. In instruction `%div24 = sdiv i64 %.omp.iv.065, %conv6`, `%conv6` is invariant in loop, so it seems we do not need `Predicated`.\r\n\r\nI try the following patch,\r\n```diff\r\ndiff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\r\nindex c7c19ef456c7..f294703e1529 100644\r\n--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\r\n+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp\r\n@@ -3856,21 +3856,21 @@ bool LoopVectorizationCostModel::isPredicatedInst(Instruction *I) const {\r\n !Legal->blockNeedsPredication(I->getParent()))\r\n return false;\r\n return true;\r\n }\r\n case Instruction::UDiv:\r\n case Instruction::SDiv:\r\n case Instruction::SRem:\r\n case Instruction::URem:\r\n // TODO: We can use the loop-preheader as context point here and get\r\n // context sensitive reasoning\r\n- return !isSafeToSpeculativelyExecute(I);\r\n+ return !isSafeToSpeculativelyExecute(I) && !Legal->isInvariant(I->getOperand(1));\r\n case Instruction::Call:\r\n return Legal->isMaskRequired(I);\r\n }\r\n }\r\n\r\n std::pair<InstructionCost, InstructionCost>\r\n LoopVectorizationCostModel::getDivRemSpeculationCost(Instruction *I,\r\n ElementCount VF) const {\r\n assert(I->getOpcode() == Instruction::UDiv ||\r\n I->getOpcode() == Instruction::SDiv ||\r\n\r\n```" }, { "author": "eastB233", "body": "ping @sdesmalen-arm @davemgreen @paulwalker-arm " }, { "author": "fhahn", "body": "@eastB233 unfortunately I don't think this change is correct, e.g. consider https://github.com/llvm/llvm-project/blob/967eba07549d64f15e7a91e798aa46214704f62b/llvm/test/Transforms/LoopVectorize/X86/divs-with-tail-folding.ll#L251 when the sdiv/udiv is executed conditionally in the loop" } ] }
true
null
80113
https://github.com/llvm/llvm-project/issues/80113
miscompilation
24a804101b67676aa9fa7f1097043ddd9e2ac1b6
2024-01-31T08:09:28
[ "llvm/test/Transforms/BDCE" ]
{ "fix_commit": "b210cbbd0eb8ef7cd2735e99570474e6e53ee00b", "components": [ "BDCE" ], "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": 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": [ [ 45, 59 ], [ 79, 90 ] ], "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": 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": [ "clearAssumptionsOfUsers" ], "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 b210cbbd0eb8ef7cd2735e99570474e6e53ee00b Author: Nikita Popov <[email protected]> Date: Wed Jan 31 11:01:03 2024 +0100 [BDCE] Fix clearing of poison-generating flags If the demanded bits of an instruction are full, we don't have to recurse to its users, but we may still have to clear flags on the instruction itself. Fixes https://github.com/llvm/llvm-project/issues/80113. diff --git a/llvm/lib/Transforms/Scalar/BDCE.cpp b/llvm/lib/Transforms/Scalar/BDCE.cpp index e99210ce2f22..6e6fa6c8ffc4 100644 --- a/llvm/lib/Transforms/Scalar/BDCE.cpp +++ b/llvm/lib/Transforms/Scalar/BDCE.cpp @@ -45,15 +45,17 @@ static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB) { assert(I->getType()->isIntOrIntVectorTy() && "Trivializing a non-integer value?"); + // If all bits of a user are demanded, then we know that nothing below that + // in the def-use chain needs to be changed. + if (DB.getDemandedBits(I).isAllOnes()) + return; + // Initialize the worklist with eligible direct users. SmallPtrSet<Instruction *, 16> Visited; SmallVector<Instruction *, 16> WorkList; for (User *JU : I->users()) { - // If all bits of a user are demanded, then we know that nothing below that - // in the def-use chain needs to be changed. - auto *J = dyn_cast<Instruction>(JU); - if (J && J->getType()->isIntOrIntVectorTy() && - !DB.getDemandedBits(J).isAllOnes()) { + auto *J = cast<Instruction>(JU); + if (J->getType()->isIntOrIntVectorTy()) { Visited.insert(J); WorkList.push_back(J); } @@ -79,12 +81,14 @@ static void clearAssumptionsOfUsers(Instruction *I, DemandedBits &DB) { // 1. llvm.assume demands its operand, so trivializing can't change it. // 2. range metadata only applies to memory accesses which demand all bits. + // If all bits of a user are demanded, then we know that nothing below + // that in the def-use chain needs to be changed. + if (DB.getDemandedBits(J).isAllOnes()) + continue; + for (User *KU : J->users()) { - // If all bits of a user are demanded, then we know that nothing below - // that in the def-use chain needs to be changed. - auto *K = dyn_cast<Instruction>(KU); - if (K && Visited.insert(K).second && K->getType()->isIntOrIntVectorTy() && - !DB.getDemandedBits(K).isAllOnes()) + auto *K = cast<Instruction>(KU); + if (Visited.insert(K).second && K->getType()->isIntOrIntVectorTy()) WorkList.push_back(K); } }
[ { "file": "llvm/test/Transforms/BDCE/invalidate-assumptions.ll", "commands": [ "opt -passes=bdce %s -S" ], "tests": [ { "test_name": "disjoint_indirect", "test_body": "define i32 @disjoint_indirect(i64 %x) {\n %and = and i64 %x, 1\n %trunc = trunc i64 %and to i32\n %or = or disjoint i32 %trunc, -2\n ret i32 %or\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "disjoint", "test_body": "define i64 @disjoint(i64 %x) {\n %and = and i64 %x, 1\n %or = or disjoint i64 %and, -2\n ret i64 %or\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Wrong code at -O2/3 on x86-64_linux-gnu (recent regression)", "body": "clang at -O2/3 produced the wrong code. This is a recent regression.\r\n\r\nBisected to 20737825c9122b6e0a8912731cfa7e0558fe025d, which was committed by @antoniofrighetto \r\n\r\nCompiler explorer: https://godbolt.org/z/55z1WT3MM\r\n\r\n```console\r\n% cat reduced.c\r\nint printf(const char *, ...);\r\nshort a, f = 6;\r\nint b, e, g;\r\nint c[7][1];\r\nstatic int *d = &b;\r\nlong h;\r\nint *const *i;\r\nstatic unsigned char j(long k, short *n) {\r\n int *l = &c[5][0];\r\n int *const **m = &i;\r\n i = &l;\r\n *d = 0;\r\n for (; e < 60; e++)\r\n ***m = ((h = *d == (1 ^ k)) & *n + f) - 2;\r\n return 0;\r\n}\r\nint main() {\r\n j(1, &a);\r\n printf(\"%d\\n\", c[5][0]);\r\n}\r\n%\r\n% clang -O0 reduced.c &&./a.out\r\n-2\r\n% clang -O2 reduced.c &&./a.out\r\n4\r\n%\r\n```", "author": "shao-hua-li", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "nikic", "body": "Looks like poison flags don't get cleared as expected." }, { "author": "nikic", "body": "Minimized:\r\n```llvm\r\ndefine i32 @test(i64 %x) {\r\n %and = and i64 %x, 1\r\n %trunc = trunc i64 %and to i32\r\n %or = or disjoint i32 %trunc, -2\r\n ret i32 %or\r\n}\r\n```\r\nThe `%and` gets dropped but `disjoint` is kept." }, { "author": "antoniofrighetto", "body": "@nikic, could you kindly elaborate this? I'm having a hard time getting this, the transformation looks correct with simple `or` (https://alive2.llvm.org/ce/z/ui3yFf). Semantics for `disjoint`:\r\n> If the disjoint flag is set, and the or has a one and the same bit in both arguments, the result is poison.\r\n\r\nHowever, here:\r\n```llvm\r\n %add = add nuw nsw i64 %conv5, %conv4\r\n %and = and i64 %add, 1\r\n %2 = trunc i64 %and to i32\r\n %conv7 = or disjoint i32 %2, -2\r\n```\r\nThe two or operands do not seem to have any same bit in both arguments." }, { "author": "antoniofrighetto", "body": "OK, I got it now, the `disjoint` should not be there at all after the transformation. Makes sense, thank you." }, { "author": "nikic", "body": "Fixed another issue I noticed in this code in https://github.com/llvm/llvm-project/commit/cb6240d247b3419dea29eb99261171ea239b1c5c." } ] }
true
null
117308
https://github.com/llvm/llvm-project/issues/117308
crash
6655c53ff02f0ffca0fcaa3261e14c2a6417d3da
2024-11-22T09:51:05
[ "llvm/test/Transforms/FunctionAttrs" ]
{ "fix_commit": "5a90168fa34e15b544d7749ca4d247a16d360119", "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": [ [ 6886, 6892 ] ], "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::getUnderlyingObjectAggressive" ], "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 5a90168fa34e15b544d7749ca4d247a16d360119 Author: Heejin Ahn <[email protected]> Date: Wed Jan 15 11:53:51 2025 -0800 [ValueTracking] Provide getUnderlyingObjectAggressive fallback (#123019) This callsite assumes `getUnderlyingObjectAggressive` returns a non-null pointer: https://github.com/llvm/llvm-project/blob/273a94b3d5a78cd9122c7b3bbb5d5a87147735d2/llvm/lib/Transforms/IPO/FunctionAttrs.cpp#L124 But it can return null when there are cycles in the value chain so there is no more `Worklist` item anymore to explore, in which case it just returns `Object` at the end of the function without ever setting it: https://github.com/llvm/llvm-project/blob/9b5857a68381652dbea2a0c9efa734b6c4cf38c9/llvm/lib/Analysis/ValueTracking.cpp#L6866-L6867 https://github.com/llvm/llvm-project/blob/9b5857a68381652dbea2a0c9efa734b6c4cf38c9/llvm/lib/Analysis/ValueTracking.cpp#L6889 `getUnderlyingObject` does not seem to return null either judging by looking at its code and its callsites, so I think it is not likely to be the author's intention that `getUnderlyingObjectAggressive` returns null. So this checks whether `Object` is null at the end, and if so, falls back to the original first value. --- The test case here was reduced by bugpoint and further reduced manually, but I find it hard to reduce it further. To trigger this bug, the memory operation should not be reachable from the entry BB, because the `phi`s should form a cycle without introducing another value from the entry. I tried a minimal `phi` cycle with three BBs (entry BB + two BBs in a cycle), but it was skipped here: https://github.com/llvm/llvm-project/blob/273a94b3d5a78cd9122c7b3bbb5d5a87147735d2/llvm/lib/Transforms/IPO/FunctionAttrs.cpp#L121-L122 To get the result that's not `ModRefInfo::NoModRef`, the length of `phi` chain needed to be greater than the `MaxLookup` value set in this function: https://github.com/llvm/llvm-project/blob/02403f4e450b86d93197dd34045ff40a34b21494/llvm/lib/Analysis/BasicAliasAnalysis.cpp#L744 But just lengthening the `phi` chain to 8 didn't trigger the same error in `getUnderlyingObjectAggressive` because `getUnderlyingObject` here passes through a single-chain `phi`s so not all `phi`s end up in `Visited`: https://github.com/llvm/llvm-project/blob/9b5857a68381652dbea2a0c9efa734b6c4cf38c9/llvm/lib/Analysis/ValueTracking.cpp#L6863 So I just submit here the smallest test case I managed to create. --- Fixes #117308 and fixes #122166. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 1bab9b32525c..1853b1c67159 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6886,7 +6886,7 @@ const Value *llvm::getUnderlyingObjectAggressive(const Value *V) { return FirstObject; } while (!Worklist.empty()); - return Object; + return Object ? Object : FirstObject; } /// This is the function that does the work of looking through basic
[ { "file": "llvm/test/Transforms/FunctionAttrs/phi_cycle.ll", "commands": [ "opt -passes=function-attrs -S < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Regression test for a null-returning bug of getUnderlyingObjectAggressive().\n; This should not crash.\ndefine void @phi_cycle() {\nbb:\n unreachable\n\nbb1: ; preds = %bb17\n br label %bb2\n\nbb2: ; preds = %bb5, %bb1\n %phi = phi ptr [ %phi6, %bb1 ], [ %phi6, %bb5 ]\n br i1 poison, label %bb4, label %bb3\n\nbb3: ; preds = %bb2\n %getelementptr = getelementptr inbounds i8, ptr %phi, i32 poison\n br label %bb5\n\nbb4: ; preds = %bb2\n br label %bb7\n\nbb5: ; preds = %bb15, %bb3\n %phi6 = phi ptr [ %getelementptr, %bb3 ], [ %phi16, %bb15 ]\n br i1 poison, label %bb17, label %bb2\n\nbb7: ; preds = %bb15, %bb4\n %phi8 = phi ptr [ %phi, %bb4 ], [ %phi16, %bb15 ]\n br i1 poison, label %bb11, label %bb9\n\nbb9: ; preds = %bb7\n %getelementptr10 = getelementptr inbounds i8, ptr %phi8, i32 1\n store i8 poison, ptr %phi8, align 1\n br label %bb15\n\nbb11: ; preds = %bb7\n br i1 poison, label %bb13, label %bb12\n\nbb12: ; preds = %bb11\n br label %bb13\n\nbb13: ; preds = %bb12, %bb11\n %getelementptr14 = getelementptr inbounds i8, ptr %phi8, i32 poison\n br label %bb15\n\nbb15: ; preds = %bb13, %bb9\n %phi16 = phi ptr [ %getelementptr14, %bb13 ], [ %getelementptr10, %bb9 ]\n br i1 poison, label %bb5, label %bb7\n\nbb17: ; preds = %bb5\n br label %bb1\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Crash on wasm-ld (failed Received SIGSEGV (-11))", "body": "I came across this error when trying to build wasm artifact of [this repository](https://github.com/daquexian/onnx-simplifier) ( branch `v0.4.36` ) using ninja.\r\n\r\nThe `emsdk` version that I used was 3.1.72.\r\n\r\n```\r\n: && /home/yogisalomo/emsdk/upstream/emscripten/em++ -O3 -DNDEBUG -s ALLOW_MEMORY_GROWTH=1 -s EXIT_RUNTIME=1 -s FORCE_FILESYSTEM=1 -s MODULARIZE=1 -s 'EXPORT_NAME=\"create_onnxsim\"' -s 'EXPORTED_RUNTIME_METHODS=[FS,ccall,cwrap,callMain]' -s EXPORTED_FUNCTIONS=[_main] CMakeFiles/onnxsim_bin.dir/onnxsim/bin/onnxsim_bin.cpp.o CMakeFiles/onnxsim_bin.dir/onnxsim/bin/onnxsim_option.cpp.o -o onnxsim.js libonnxsim.a third_party/onnx-optimizer/libonnx_optimizer.a libonnxruntime_webassembly.a && :\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: /home/yogisalomo/emsdk/upstream/bin/wasm-ld -o onnxsim.wasm -L/home/yogisalomo/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten CMakeFiles/onnxsim_bin.dir/onnxsim/bin/onnxsim_bin.cpp.o CMakeFiles/onnxsim_bin.dir/onnxsim/bin/onnxsim_option.cpp.o libonnxsim.a third_party/onnx-optimizer/libonnx_optimizer.a libonnxruntime_webassembly.a -lGL-getprocaddr -lal -lhtml5 -lstubs -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmpuew4mr6alibemscripten_js_symbols.so --strip-debug --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__funcs_on_exit --export=__wasm_call_ctors --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --max-memory=2147483648 --initial-heap=16777216 --no-entry --table-base=1 --global-base=1024\r\n1. Running pass \"cgscc(function-attrs)\" on module \"ld-temp.o\"\r\n #0 0x00005a6692b63088 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x1083088)\r\n #1 0x00005a6692b603ee llvm::sys::RunSignalHandlers() (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x10803ee)\r\n #2 0x00005a6692b63c7f SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000079f165242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00005a66941e9d3c checkFunctionMemoryAccess(llvm::Function&, bool, llvm::AAResults&, llvm::SmallSetVector<llvm::Function*, 8u> const&) (.llvm.13958950707188126733) FunctionAttrs.cpp:0:0\r\n #5 0x00005a66941eb09a llvm::SmallSet<llvm::Function*, 8u, std::__2::less<llvm::Function*>> deriveAttrsInPostOrder<llvm::PostOrderFunctionAttrsPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)::$_0&>(llvm::ArrayRef<llvm::Function*>, llvm::PostOrderFunctionAttrsPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&)::$_0&, bool) FunctionAttrs.cpp:0:0\r\n #6 0x00005a66941ea819 llvm::PostOrderFunctionAttrsPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x270a819)\r\n #7 0x00005a6693a8370d 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&) PassBuilder.cpp:0:0\r\n #8 0x00005a6694de42f3 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x33042f3)\r\n #9 0x00005a6693a605fd llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilder.cpp:0:0\r\n#10 0x00005a6695695c9a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x3bb5c9a)\r\n#11 0x00005a66939ba386 llvm::lto::opt(llvm::lto::Config const&, llvm::TargetMachine*, unsigned int, llvm::Module&, bool, llvm::ModuleSummaryIndex*, llvm::ModuleSummaryIndex const*, std::__2::vector<unsigned char, std::__2::allocator<unsigned char>> const&) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x1eda386)\r\n#12 0x00005a66939bc7e3 llvm::lto::backend(llvm::lto::Config const&, std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, unsigned int, llvm::Module&, llvm::ModuleSummaryIndex&) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x1edc7e3)\r\n#13 0x00005a66939a602f llvm::lto::LTO::runRegularLTO(std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x1ec602f)\r\n#14 0x00005a66939a52ad llvm::lto::LTO::run(std::__2::function<llvm::Expected<std::__2::unique_ptr<llvm::CachedFileStream, std::__2::default_delete<llvm::CachedFileStream>>> (unsigned int, llvm::Twine const&)>, llvm::FileCache) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x1ec52ad)\r\n#15 0x00005a6693014dd3 lld::wasm::BitcodeCompiler::compile() (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x1534dd3)\r\n#16 0x00005a66930184b4 lld::wasm::SymbolTable::compileBitcodeFiles() (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x15384b4)\r\n#17 0x00005a6692ffe90c lld::wasm::(anonymous namespace)::LinkerDriver::linkerMain(llvm::ArrayRef<char const*>) Driver.cpp:0:0\r\n#18 0x00005a6692ff88f8 lld::wasm::link(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, bool, bool) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x15188f8)\r\n#19 0x00005a6692b660f0 lld::unsafeLldMain(llvm::ArrayRef<char const*>, llvm::raw_ostream&, llvm::raw_ostream&, llvm::ArrayRef<lld::DriverDef>, bool) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0x10860f0)\r\n#20 0x00005a6692aa64d1 lld_main(int, char**, llvm::ToolContext const&) (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0xfc64d1)\r\n#21 0x00005a6692aa6ec4 main (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0xfc6ec4)\r\n#22 0x000079f165229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x000079f165229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x000079f165229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x00005a6692a1336a _start (/home/yogisalomo/emsdk/upstream/bin/wasm-ld+0xf3336a)\r\nem++: error: '/home/yogisalomo/emsdk/upstream/bin/wasm-ld -o onnxsim.wasm -L/home/yogisalomo/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten CMakeFiles/onnxsim_bin.dir/onnxsim/bin/onnxsim_bin.cpp.o CMakeFiles/onnxsim_bin.dir/onnxsim/bin/onnxsim_option.cpp.o libonnxsim.a third_party/onnx-optimizer/libonnx_optimizer.a libonnxruntime_webassembly.a -lGL-getprocaddr -lal -lhtml5 -lstubs -lc -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /tmp/tmpuew4mr6alibemscripten_js_symbols.so --strip-debug --export=_emscripten_stack_alloc --export=__get_temp_ret --export=__set_temp_ret --export=__funcs_on_exit --export=__wasm_call_ctors --export=emscripten_stack_get_current --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --max-memory=2147483648 --initial-heap=16777216 --no-entry --table-base=1 --global-base=1024' failed (received SIGSEGV (-11))\r\nninja: build stopped: subcommand failed.\r\n```\r\n\r\nPlease let me know if there's any other detail that I need to add to help solving this issue. Thank you.", "author": "yogisalomo", "labels": [ "crash", "llvm:analysis" ], "comments": [ { "author": "aheejin", "body": "How can I reproduce it? I can't find any instructions in that repo. I cloned the repo and ran `./build_wasm.sh`, but it says\r\n```console\r\naheejin@aheejin:~/test/onnx-simplifier$ ./build_wasm.sh \r\n+ command -v emcmake\r\n+++ dirname -- ./build_wasm.sh\r\n++ cd -- .\r\n++ pwd\r\n+ SCRIPT_DIR=/usr/local/google/home/aheejin/test/onnx-simplifier\r\n+ WITH_NODE_RAW_FS=OFF\r\n+ cd /usr/local/google/home/aheejin/test/onnx-simplifier\r\n+ pushd third_party/onnxruntime/cmake/external/protobuf/cmake\r\n./build_wasm.sh: line 11: pushd: third_party/onnxruntime/cmake/external/protobuf/cmake: No such file or directory\r\n```" }, { "author": "yogisalomo", "body": "@aheejin thank you for responding. From the error message, seems like you didn't clone the repository recursively and therefore missing the files of the third_party repositories. Can you please try that?" }, { "author": "aheejin", "body": "Sorry for the long wait! In case you use emscripten releases, 4.0.1 release contains the fix: https://github.com/emscripten-core/emsdk/releases/tag/4.0.1" } ] }
true
null
131465
https://github.com/llvm/llvm-project/issues/131465
miscompilation
baab447aadd59b34bd838584b16d11475329853f
2025-03-15T18:15:27
[ "llvm/test/Analysis/ScalarEvolution", "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "c5a491e9ea22014b65664b6e09134b4f055933e2", "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": [ [ 10635, 10644 ] ], "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::howFarToZero" ], "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 c5a491e9ea22014b65664b6e09134b4f055933e2 Author: Yingwei Zheng <[email protected]> Date: Mon Mar 17 13:59:16 2025 +0800 [SCEV] Check whether the start is non-zero in `ScalarEvolution::howFarToZero` (#131522) https://github.com/llvm/llvm-project/pull/94525 assumes that the loop will be infinite when the stride is zero. However, it doesn't hold when the start value of addrec is also zero. Closes https://github.com/llvm/llvm-project/issues/131465. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 8f74c1c398ce..314baa7c7aee 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -10635,10 +10635,11 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V, if (ControlsOnlyExit && AddRec->hasNoSelfWrap() && loopHasNoAbnormalExits(AddRec->getLoop())) { - // If the stride is zero, the loop must be infinite. In C++, most loops - // are finite by assumption, in which case the step being zero implies - // UB must execute if the loop is entered. - if (!loopIsFiniteByAssumption(L) && !isKnownNonZero(StepWLG)) + // If the stride is zero and the start is non-zero, the loop must be + // infinite. In C++, most loops are finite by assumption, in which case the + // step being zero implies UB must execute if the loop is entered. + if (!(loopIsFiniteByAssumption(L) && isKnownNonZero(Start)) && + !isKnownNonZero(StepWLG)) return getCouldNotCompute(); const SCEV *Exact =
[ { "file": "llvm/test/Analysis/ScalarEvolution/trip-count-unknown-stride.ll", "commands": [ "opt < %s -disable-output \"-passes=print<scalar-evolution>\" -scalar-evolution-classify-expressions=0 2>&1" ], "tests": [ { "test_name": "ne_nuw_nonneg_step", "test_body": "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\"\n\n; Function Attrs: mustprogress\ndefine void @ne_nuw_nonneg_step(ptr captures(none) %A, i32 %n, i32 %s) #0 {\nentry:\n %nonneg_step = icmp sge i32 %s, 0\n call void @llvm.assume(i1 %nonneg_step)\n %cmp4 = icmp sgt i32 %n, 0\n br i1 %cmp4, label %for.body, label %for.end\n\nfor.body: ; preds = %for.body, %entry\n %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]\n %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05\n %0 = load i32, ptr %arrayidx, align 4\n %inc = add nuw i32 %0, 1\n store i32 %inc, ptr %arrayidx, align 4\n %add = add nuw i32 %i.05, %s\n %cmp = icmp ne i32 %add, %n\n br i1 %cmp, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body, %entry\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { mustprogress }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr131465", "test_body": "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\"\n\n; Function Attrs: mustprogress\ndefine i32 @pr131465(i1 %x) #0 {\nentry:\n %inc = zext i1 %x to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvar = phi i32 [ 2, %entry ], [ %next, %for.body ]\n %next = add nsw i32 %indvar, %inc\n %exitcond = icmp eq i32 %next, 2\n br i1 %exitcond, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret i32 0\n}\n\nattributes #0 = { mustprogress }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ne_nsw_nonneg_step", "test_body": "target datalayout = \"e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128\"\n\n; Function Attrs: mustprogress\ndefine void @ne_nsw_nonneg_step(ptr captures(none) %A, i32 %n, i32 %s) #0 {\nentry:\n %nonneg_step = icmp sge i32 %s, 0\n call void @llvm.assume(i1 %nonneg_step)\n %cmp4 = icmp sgt i32 %n, 0\n br i1 %cmp4, label %for.body, label %for.end\n\nfor.body: ; preds = %for.body, %entry\n %i.05 = phi i32 [ %add, %for.body ], [ 0, %entry ]\n %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.05\n %0 = load i32, ptr %arrayidx, align 4\n %inc = add nsw i32 %0, 1\n store i32 %inc, ptr %arrayidx, align 4\n %add = add nsw i32 %i.05, %s\n %cmp = icmp ne i32 %add, %n\n br i1 %cmp, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body, %entry\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { mustprogress }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopUnroll/pr131465.ll", "commands": [ "opt -S -passes=loop-unroll -unroll-runtime %s" ], "tests": [ { "test_name": "pr131465", "test_body": "; Function Attrs: mustprogress\ndefine i32 @pr131465(i1 %x) #0 {\nentry:\n %inc = zext i1 %x to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvar = phi i32 [ 2, %entry ], [ %next, %for.body ]\n %next = add nsw i32 %indvar, %inc\n %exitcond = icmp eq i32 %next, 2\n br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0\n\nfor.end: ; preds = %for.body\n ret i32 0\n}\n\nattributes #0 = { mustprogress }\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.unroll.count\", i32 2}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Miscompilation at -O2/3", "body": "This code prints 80 at `-O2/3` and 0 at `-O0/1`:\n\n```c\nint printf(const char *, ...);\nint a, b;\nvoid c(char d) { a = d; }\nint main() {\n int e = 82, f = 20;\n for (; 85 + 20 + e - 187 + f; f = 65535 + 20 + e - 65637)\n if (b)\n e++;\n c(e >> 24);\n printf(\"%X\\n\", a);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/6WP1aT6ba\n\nBisected to https://github.com/llvm/llvm-project/commit/04cd06906288dcb148de37d7c3e6c009c3e3b726, which was committed by @preames ", "author": "cardigan1008", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/bvhdjdMc7 https://alive2.llvm.org/ce/z/sSLNUX\n```\n; bin/opt -passes=loop-unroll 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(i1 %tobool2.not) #0 {\nentry:\n %inc = zext i1 %tobool2.not to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %e.08 = phi i32 [ 2, %entry ], [ %spec.select, %for.body ]\n %spec.select = add nsw i32 %e.08, %inc\n %tobool.not = icmp eq i32 %spec.select, 2\n br i1 %tobool.not, label %for.end, label %for.body, !llvm.loop !0\n\nfor.end: ; preds = %for.body\n ret i32 0\n}\n\nattributes #0 = { \"target-cpu\"=\"x86-64\" }\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.mustprogress\"}\n\n```" }, { "author": "antoniofrighetto", "body": "@dtcxzyw May I ask whether llubi was used to get such a reduced reproducer? Having a hard time reducing this one, this time: am using [test.sh](https://github.com/dtcxzyw/llvm-ub-aware-interpreter?tab=readme-ov-file#automatic-ub-free-test-case-reduction-for-middle-end-miscompilation-bugs) with:\n1) Custom pipelines & O2 in order to have some proper interestingness test;\n2) `--ir-passes` with the default one, fine-tuning the pipeline by adjusting/removing passes.\n\nHowever, by the time I obtain the reduced IR, it looks already invalid (i.e., unreachable). Any suggestions / idea what I may be missing?" }, { "author": "dtcxzyw", "body": "1. Manually bisect\n```\n#!/usr/bin/bash\n\nFILE=$1\nBISECT=$2\n../../LLVM/llvm-build/bin/clang -O3 -mllvm -inline-threshold=1000000 $FILE -mllvm -opt-bisect-limit=$BISECT -DNDEBUG -g0 -w -emit-llvm -S -I/home/dtcxzyw/WorkSpace/Projects/compilers/csmith/install/include -o test.ll -mllvm -print-changed -mllvm -print-module-scope 2>log\n# ../../LLVM/llvm-build/bin/lli test.ll\n./llubi --max-steps 1000000 test.ll\n# ../../LLVM/llvm-build/bin/opt -O3 $FILE -o out.ll -S -opt-bisect-limit=$BISECT -print-changed -print-module-scope 2>log\n# ./llubi out.ll\n```\n```\n# Correct one\n./bisect.sh test.c 175\n# Miscompilation\n./bisect.sh test.c 174\n```\nAfter the bisection, we got a single-pass reproducer:\n```\n; bin/opt -passes=loop-unroll test.ll -S\n; ModuleID = 'test.c'\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\n@a = dso_local local_unnamed_addr global i32 0, align 4\n@b = dso_local local_unnamed_addr global i32 0, align 4\[email protected] = private unnamed_addr constant [4 x i8] c\"%X\\0A\\00\", align 1\n\n; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable\ndefine dso_local void @c(i8 noundef signext %d) local_unnamed_addr #0 {\nentry:\n %conv = sext i8 %d to i32\n store i32 %conv, ptr @a, align 4, !tbaa !5\n ret void\n}\n\n; Function Attrs: nofree nounwind uwtable\ndefine dso_local noundef i32 @main() local_unnamed_addr #1 {\nentry:\n %0 = load i32, ptr @b, align 4, !tbaa !5\n %tobool2.not = icmp ne i32 %0, 0\n %inc = zext i1 %tobool2.not to i32\n br label %for.body\n\nfor.body: ; preds = %entry, %for.body\n %e.08 = phi i32 [ 82, %entry ], [ %spec.select, %for.body ]\n %spec.select = add nuw nsw i32 %e.08, %inc\n %sub = add nsw i32 %spec.select, -82\n %add1 = sub nsw i32 82, %spec.select\n %tobool.not = icmp eq i32 %sub, %add1\n br i1 %tobool.not, label %for.end, label %for.body, !llvm.loop !9\n\nfor.end: ; preds = %for.body\n %shr = lshr i32 %spec.select, 24\n store i32 %shr, ptr @a, align 4, !tbaa !5\n %call = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %shr)\n ret i32 0\n}\n\n; Function Attrs: nofree nounwind\ndeclare noundef i32 @printf(ptr noundef readonly captures(none), ...) local_unnamed_addr #2\n\nattributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\nattributes #1 = { nofree nounwind uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\nattributes #2 = { nofree nounwind \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\n\n!llvm.module.flags = !{!0, !1, !2, !3}\n!llvm.ident = !{!4}\n\n!0 = !{i32 1, !\"wchar_size\", i32 4}\n!1 = !{i32 8, !\"PIC Level\", i32 2}\n!2 = !{i32 7, !\"PIE Level\", i32 2}\n!3 = !{i32 7, !\"uwtable\", i32 2}\n!4 = !{!\"clang version 21.0.0git\"}\n!5 = !{!6, !6, i64 0}\n!6 = !{!\"int\", !7, i64 0}\n!7 = !{!\"omnipotent char\", !8, i64 0}\n!8 = !{!\"Simple C/C++ TBAA\"}\n!9 = distinct !{!9, !10}\n!10 = !{!\"llvm.loop.mustprogress\"}\n```\n2. reduce\n```\n#!/usr/bin/bash\n# /home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/clang -Os -Xclang -disable-llvm-passes -emit-llvm -S test.c -o test.ll -I/home/dtcxzyw/WorkSpace/Projects/compilers/csmith/install/include -w\n# llvm-reduce --test=ubi_reduce.sh --ir-passes=\"function(sroa,instcombine<no-verify-fixpoint>,gvn,simplifycfg,infer-address-spaces),inline\" test.ll\n\na=$(/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-ub-aware-interpreter/build/llubi --max-steps 1000000 --reduce-mode $1)\nif [ $? -ne 0 ]; then\n exit 1\nfi\n/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/opt -passes=loop-unroll $1 -o $1.tmp -S\nif [ $? -ne 0 ]; then\n exit 1\nfi\nb=$(/home/dtcxzyw/WorkSpace/Projects/compilers/llvm-ub-aware-interpreter/build/llubi --max-steps 1000000 --reduce-mode $1.tmp)\nif [ $? -ne 0 ]; then\n exit 0\n # exit 1\nfi\nif [[ \"$a\" == \"$b\" ]]; then\n exit 2\nfi\n# echo $a\n# echo $b\nexit 0\n```\n```\nllvm-reduce --test=ubi_reduce.sh test.ll\n```\nThen we got the final reproducer.\n\nIn general, I will run `creduce w/ sanitizers` and the bisection first to avoid falling into some long-outstanding undef bugs.\n\nBTW, an automatic reproducer reduction pipeline will be available soon :)\n" }, { "author": "antoniofrighetto", "body": "@dtcxzyw Thanks a lot for clarifying that :)" } ] }
true
null
113516
https://github.com/llvm/llvm-project/issues/113516
crash
0aec4d2b78a08f5f3e4b0ad0340a99e486d00110
2024-10-24T03:05:37
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554", "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": [ [ 16118, 16124 ] ], "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" ], "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 d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554 Author: Alexey Bataev <[email protected]> Date: Thu Oct 24 08:15:21 2024 -0700 [SLP]Do not check for clustered loads only Since SLP support "clusterization" of the non-load instructions, the restriction for reduced values for loads only should be removed to avoid compiler crash. Fixes #113516 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index f76e913a57d5..012d85353f08 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -16118,7 +16118,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, for (Instruction *I : RemovedInsts) { const TreeEntry *IE = getTreeEntry(I); if (IE->Idx != 0 && - !(VectorizableTree.front()->isGather() && isa<LoadInst>(I) && + !(VectorizableTree.front()->isGather() && !IE->UserTreeIndices.empty() && any_of(IE->UserTreeIndices, [&](const EdgeInfo &EI) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/non-load-reduced-as-part-of-bv.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "foo", "test_body": "define i1 @foo() {\nentry:\n %tobool.not.not509.i.1311.i.i = icmp ne i32 0, 0\n %cmp80.1319.i.i189 = icmp sgt i32 0, 0\n %tobool.not.not509.i.1.1.i.i = icmp ne i32 0, 0\n %cmp80.1.1.i.i190 = icmp sgt i32 0, 0\n %tobool.not.not509.i.2329.i.i = icmp ne i32 0, 0\n %storemerge.2333.i.i = select i1 %tobool.not.not509.i.2329.i.i, i32 0, i32 0\n %cmp80.2337.i.i192 = icmp sgt i32 0, 0\n %tobool.not.not509.i.1.2.i.i = icmp ne i32 %storemerge.2333.i.i, 0\n %cmp80.1.2.i.i193 = icmp sgt i32 0, 0\n %cmp80.1.2.i.i = select i1 %tobool.not.not509.i.1.2.i.i, i1 %cmp80.1.2.i.i193, i1 false\n %0 = select i1 %cmp80.1.2.i.i, i1 %tobool.not.not509.i.2329.i.i, i1 false\n %1 = select i1 %0, i1 %cmp80.2337.i.i192, i1 false\n %2 = select i1 %1, i1 false, i1 false\n %3 = select i1 %2, i1 %tobool.not.not509.i.1.1.i.i, i1 false\n %4 = select i1 %3, i1 %cmp80.1.1.i.i190, i1 false\n %5 = select i1 %4, i1 %tobool.not.not509.i.1311.i.i, i1 false\n %6 = select i1 %5, i1 %cmp80.1319.i.i189, i1 false\n ret i1 %6\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.", "body": "Reduced reproducer: https://godbolt.org/z/azEc6zjod\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 i1 @foo() {\r\nentry:\r\n %tobool.not.not509.i.1311.i.i = icmp ne i32 0, 0\r\n %cmp80.1319.i.i189 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.1.1.i.i = icmp ne i32 0, 0\r\n %cmp80.1.1.i.i190 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.2329.i.i = icmp ne i32 0, 0\r\n %storemerge.2333.i.i = select i1 %tobool.not.not509.i.2329.i.i, i32 0, i32 0\r\n %cmp80.2337.i.i192 = icmp sgt i32 0, 0\r\n %tobool.not.not509.i.1.2.i.i = icmp ne i32 %storemerge.2333.i.i, 0\r\n %cmp80.1.2.i.i193 = icmp sgt i32 0, 0\r\n %cmp80.1.2.i.i = select i1 %tobool.not.not509.i.1.2.i.i, i1 %cmp80.1.2.i.i193, i1 false\r\n %0 = select i1 %cmp80.1.2.i.i, i1 %tobool.not.not509.i.2329.i.i, i1 false\r\n %1 = select i1 %0, i1 %cmp80.2337.i.i192, i1 false\r\n %2 = select i1 %1, i1 false, i1 false\r\n %3 = select i1 %2, i1 %tobool.not.not509.i.1.1.i.i, i1 false\r\n %4 = select i1 %3, i1 %cmp80.1.1.i.i190, i1 false\r\n %5 = select i1 %4, i1 %tobool.not.not509.i.1311.i.i, i1 false\r\n %6 = select i1 %5, i1 %cmp80.1319.i.i189, i1 false\r\n ret i1 %6\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2748: void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef<U*>) [with T = llvm::Instruction]: Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' 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 \"foo\"\r\n #0 0x00000000050d8608 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50d8608)\r\n #1 0x00000000050d5fbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000071afd7642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000071afd76969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000071afd7642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000071afd76287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000071afd762871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000071afd7639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000414e3af void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x414e3af)\r\n #9 0x00000000041aa335 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41aa335)\r\n#10 0x00000000041bcd90 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x00000000041bfb71 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41bfb71)\r\n#12 0x00000000041c431b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#13 0x00000000041c8ae8 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c8ae8)\r\n#14 0x00000000041cf231 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#15 0x00000000041cfedb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41cfedb)\r\n#16 0x0000000002f64f0e 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+0x2f64f0e)\r\n#17 0x0000000004ed9788 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed9788)\r\n#18 0x0000000000e2773e 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+0xe2773e)\r\n#19 0x0000000004ed81ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed81ae)\r\n#20 0x0000000000e26e8e 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+0xe26e8e)\r\n#21 0x0000000004ed7be0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed7be0)\r\n#22 0x000000000090a07a 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+0x90a07a)\r\n#23 0x00000000008fce7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce7c)\r\n#24 0x000071afd7629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x000071afd7629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008f493e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f493e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: 33363521ca24f912cc25530f6cecbca53acce8a3", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
110787
https://github.com/llvm/llvm-project/issues/110787
crash
8805ff72a04308562ea9e962415d238dd356be69
2024-10-02T04:16:44
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "4dede756f25b153a81ea883ef84064f5a1eaaec2", "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": [ [ 18848, 18853 ], [ 18877, 18883 ] ], "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 4dede756f25b153a81ea883ef84064f5a1eaaec2 Author: Alexey Bataev <[email protected]> Date: Wed Oct 2 05:50:20 2024 -0700 [SLP]Transform nodes before building externally used values transformNodes function may create new vector nodes, so the reduced values might be vectorized later. Need to build the list of the externally used values after the transformNodes() function call to avoid compiler crash. Fixe #110787 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 15e798bd6c98..ce1e5753c0c8 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -18848,6 +18848,7 @@ public: ++SameValuesCounter.try_emplace(OrigV).first->second; } } + V.transformNodes(); SmallPtrSet<Value *, 4> VLScalars(VL.begin(), VL.end()); // Gather externally used values. SmallPtrSet<Value *, 4> Visited; @@ -18877,7 +18878,6 @@ public: for (Value *RdxVal : VL) if (RequiredExtract.contains(RdxVal)) LocalExternallyUsedValues[RdxVal]; - V.transformNodes(); V.buildExternalUses(LocalExternallyUsedValues); V.computeMinimumValueSizes();
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-val-vectorized-in-transform.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(i1 %cond) {\nentry:\n br label %bb\n\nbb: ; preds = %bb, %entry\n %p1 = phi i32 [ %or92, %bb ], [ 0, %entry ]\n %p2 = phi i32 [ %0, %bb ], [ 0, %entry ]\n %p3 = phi i32 [ %4, %bb ], [ 0, %entry ]\n %0 = or i32 1, 0\n %or8.i = or i32 0, 0\n %or9.i = or i32 0, 0\n %or91 = or i32 %p1, 0\n %or12.i = or i32 %p2, 0\n %or92 = or i32 1, 0\n %1 = xor i32 %or91, %or12.i\n %2 = xor i32 %1, %or9.i\n %3 = xor i32 %2, %or8.i\n %4 = xor i32 %3, %or92\n br i1 %cond, label %exit, label %bb\n\nexit: ; preds = %bb\n ret i32 %4\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.", "body": "Reproducer: https://godbolt.org/z/b8cz56M9z\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 i32 @test(i1 %cond) {\r\nentry:\r\n br label %for.end14.i.i.i.us.i\r\n\r\nfor.end14.i.i.i.us.i:\r\n %.promoted10921110.i.i.i.us.i = phi i32 [ %inc229.1.2.i.i.i.us.us.12.i, %for.end14.i.i.i.us.i ], [ 0, %entry ]\r\n %.promoted1106.i.i.i.us.i = phi i32 [ %0, %for.end14.i.i.i.us.i ], [ 0, %entry ]\r\n %g_276.promoted956960.i.i.i.us.i = phi i32 [ %4, %for.end14.i.i.i.us.i ], [ 0, %entry ]\r\n %0 = or i32 1, 0\r\n %inc229.1974.i.i.i.us.us.8.i = or i32 0, 0\r\n %inc229.1974.i.i.i.us.us.9.i = or i32 0, 0\r\n %inc229.1.2.i.i.i.us.us.9.i = or i32 %.promoted10921110.i.i.i.us.i, 0\r\n %inc229.1974.i.i.i.us.us.12.i = or i32 %.promoted1106.i.i.i.us.i, 0\r\n %inc229.1.2.i.i.i.us.us.12.i = or i32 1, 0\r\n %1 = xor i32 %inc229.1.2.i.i.i.us.us.9.i, %inc229.1974.i.i.i.us.us.12.i\r\n %2 = xor i32 %1, %inc229.1974.i.i.i.us.us.9.i\r\n %3 = xor i32 %2, %inc229.1974.i.i.i.us.us.8.i\r\n %4 = xor i32 %3, %inc229.1.2.i.i.i.us.us.12.i\r\n br i1 %cond, label %exit, label %for.end14.i.i.i.us.i\r\n\r\nexit:\r\n ret i32 %4\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2720: void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef<U*>) [with T = llvm::Instruction]: Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' 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 0x000000000507e338 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x507e338)\r\n #1 0x000000000507bcec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f54a0842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f54a08969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f54a0842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f54a08287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f54a082871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f54a0839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004102d6f void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4102d6f)\r\n #9 0x000000000415dea2 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::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x415dea2)\r\n#10 0x0000000004167819 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x000000000416a302 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+0x416a302)\r\n#12 0x000000000416ebb8 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x416ebb8)\r\n#13 0x0000000004172da1 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4172da1)\r\n#14 0x00000000041796b1 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#15 0x000000000417a33b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x417a33b)\r\n#16 0x0000000002f33c8e 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+0x2f33c8e)\r\n#17 0x0000000004e81158 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e81158)\r\n#18 0x0000000000e15bde 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+0xe15bde)\r\n#19 0x0000000004e7fb7e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7fb7e)\r\n#20 0x0000000000e1538e 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+0xe1538e)\r\n#21 0x0000000004e7f5b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7f5b0)\r\n#22 0x0000000000904102 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+0x904102)\r\n#23 0x00000000008f6f8c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6f8c)\r\n#24 0x00007f54a0829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x00007f54a0829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008eea5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8eea5e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: e379094328e49731a606304f7e3559d4f1fa96f9", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "alexey-bataev", "body": "Fixed in 4dede756f25b153a81ea883ef84064f5a1eaaec2" } ] }
true
null
76986
https://github.com/llvm/llvm-project/issues/76986
crash
71c17424b5d5c22c0ce6b4c41acaa0401515baca
2024-01-04T18:14:09
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2ab5c47c8752b444885d6bfaf6f570a482fb4cdf", "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": [ [ 829, 843 ] ], "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": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "simplifyRecipe" ], "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 2ab5c47c8752b444885d6bfaf6f570a482fb4cdf Author: Florian Hahn <[email protected]> Date: Thu Jan 4 20:39:44 2024 +0000 [VPlan] Don't replace scalarizing recipe with VPWidenCastRecipe. Don't replace a scalarizing recipe with a VPWidenCastRecipe. This would introduce wide (vectorizing) recipes when interleaving only. Fixes https://github.com/llvm/llvm-project/issues/76986 diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 33132880d5a4..5c430620a2dc 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -829,15 +829,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) { Type *ATy = TypeInfo.inferScalarType(A); if (TruncTy == ATy) { Trunc->replaceAllUsesWith(A); - } else if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) { - auto *VPC = - new VPWidenCastRecipe(Instruction::CastOps(ExtOpcode), A, TruncTy); - VPC->insertBefore(&R); - Trunc->replaceAllUsesWith(VPC); - } else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) { - auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy); - VPC->insertBefore(&R); - Trunc->replaceAllUsesWith(VPC); + } else { + // Don't replace a scalarizing recipe with a widened cast. + if (isa<VPReplicateRecipe>(&R)) + break; + if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) { + auto *VPC = + new VPWidenCastRecipe(Instruction::CastOps(ExtOpcode), A, TruncTy); + VPC->insertBefore(&R); + Trunc->replaceAllUsesWith(VPC); + } else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) { + auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy); + VPC->insertBefore(&R); + Trunc->replaceAllUsesWith(VPC); + } } #ifndef NDEBUG // Verify that the cached type info is for both A and its users is still
[ { "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": "test_scalarize_call", "test_body": "define void @test_scalarize_call(i32 %start, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]\n %min = tail call i32 @llvm.smin.i32(i32 %iv, i32 65535)\n %arrayidx = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %min, ptr %arrayidx, align 8\n %iv.next = add nsw i32 %iv, 1\n %tobool.not = icmp eq i32 %iv.next, 1000\n br i1 %tobool.not, 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 i32 @llvm.smin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "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, 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": "first_order_recurrence_using_induction", "test_body": "define void @first_order_recurrence_using_induction(i32 %n, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %for, ptr %dst, align 4\n %iv.next = add nuw nsw i64 %iv, 1\n %iv.next.trunc = trunc i64 %iv.next to i32\n %ec = icmp slt i32 %iv.next.trunc, %n\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "reduction_with_casts", "test_body": "define i16 @reduction_with_casts() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %count.0.in1 = phi i32 [ 0, %entry ], [ %add, %loop ]\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %conv1 = and i32 %count.0.in1, 65535\n %add = add nuw nsw i32 %conv1, 1\n %iv.next = add i16 %iv, 1\n %cmp = icmp eq i16 %iv.next, 10000\n br i1 %cmp, label %exit, label %loop\n\nexit: ; preds = %loop\n %add.lcssa = phi i32 [ %add, %loop ]\n %count.0 = trunc i32 %add.lcssa to i16\n ret i16 %count.0\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr76986_trunc_sext_interleaving_only", "test_body": "define void @pr76986_trunc_sext_interleaving_only(i16 %arg, ptr noalias %src, ptr noalias %dst) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i8, ptr %src, i64 %iv\n %l = load i8, ptr %gep.src, align 1\n %sext = sext i8 %l to i32\n %trunc = trunc i32 %sext to i16\n %sdiv = sdiv i16 %trunc, %arg\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %sdiv, ptr %gep.dst, align 2\n %iv.next = add i64 %iv, 1\n %icmp = icmp ult i64 %iv, 14933\n br i1 %icmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_scalarize_with_branch_cond", "test_body": "define void @test_scalarize_with_branch_cond(ptr %src, ptr %dst) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %d = phi i1 [ false, %entry ], [ %d.next, %loop.latch ]\n %d.next = xor i1 %d, true\n br i1 %d, label %cond.false, label %loop.latch\n\ncond.false: ; preds = %loop.header\n %gep.src = getelementptr inbounds i32, ptr %src, i64 %iv\n %gep.dst = getelementptr inbounds i32, ptr %dst, i64 %iv\n %l = load i32, ptr %gep.src, align 4\n store i32 %l, ptr %gep.dst, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %cond.false, %loop.header\n %iv.next = add nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `State.VF.isVector() && \"Not vectorizing?\"' failed.", "body": "Run opt with -passes=loop-vectorize\r\n\r\nhttps://godbolt.org/z/xdrTfEddx\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"aarch64-none-linux-gnu\"\r\n\r\ndefine void @wombat(i16 %arg) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb1 ]\r\n %sext = sext i8 0 to i32\r\n %add = add i64 %phi, 1\r\n %trunc = trunc i32 %sext to i16\r\n %sdiv = sdiv i16 0, %arg\r\n %sext2 = sext i16 %trunc to i32\r\n %sext3 = sext i32 %sext2 to i64\r\n %icmp = icmp ult i64 %phi, 14933\r\n br i1 %icmp, label %bb1, label %bb4\r\n\r\nbb4: ; preds = %bb1\r\n %phi5 = phi i64 [ %sext3, %bb1 ]\r\n ret void\r\n}\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Taking a look now!" } ] }
true
null
87394
https://github.com/llvm/llvm-project/issues/87394
crash
d5022d9ad4aec250f77d21c819a9810a97b8b6a8
2024-04-02T18:48:53
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "adb0126ef11b0083d5a78be1534ccefa53def1cf", "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": 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": [ [ 35, 40 ], [ 44, 49 ] ], "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": 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": [ "VPTypeAnalysis::inferScalarTypeForRecipe" ], "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 adb0126ef11b0083d5a78be1534ccefa53def1cf Author: Patrick O'Neill <[email protected]> Date: Tue Apr 23 07:48:43 2024 -0700 [VPlan] Add scalar inferencing support for Not and Or insns (#89160) Fixes #87394. PR: https://github.com/llvm/llvm-project/pull/89160 diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp index ad4ea648cd61..5f93339083f0 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp @@ -35,6 +35,7 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) { CachedTypes[OtherV] = ResTy; return ResTy; } + case Instruction::Or: case Instruction::ICmp: case VPInstruction::FirstOrderRecurrenceSplice: { Type *ResTy = inferScalarType(R->getOperand(0)); @@ -44,6 +45,12 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) { CachedTypes[OtherV] = ResTy; return ResTy; } + case VPInstruction::Not: { + Type *ResTy = inferScalarType(R->getOperand(0)); + assert(IntegerType::get(Ctx, 1) == ResTy && + "unexpected scalar type inferred for operand"); + return ResTy; + } case VPInstruction::PtrAdd: // Return the type based on the pointer argument (i.e. first operand). return inferScalarType(R->getOperand(0));
[ { "file": "llvm/test/Transforms/LoopVectorize/vplan-infer-not-or-type.ll", "commands": [ "opt < %s -passes=loop-vectorize -S" ], "tests": [ { "test_name": "foo", "test_body": "define void @foo(i8 %arg.0, i8 %arg.1) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %latch, %entry\n %incrementor = phi i8 [ %add, %latch ], [ 0, %entry ]\n %and = and i8 %arg.0, %arg.1\n %extract.t = trunc i8 %and to i1\n br i1 %extract.t, label %latch, label %indirect.latch\n\nindirect.latch: ; preds = %loop.header\n br label %latch\n\nlatch: ; preds = %indirect.latch, %loop.header\n %add = add i8 %incrementor, 1\n %conv = zext i8 %incrementor to i32\n %cmp = icmp ult i32 %conv, 1\n br i1 %cmp, label %loop.header, label %loop.exit\n\nloop.exit: ; preds = %latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize][VPlan] Unreachable executed \"Unhandled opcode!\"", "body": "Reduced LLVM IR:\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.loopexit: ; preds = %cond.end\r\n ret i32 0\r\n\r\nfor.body: ; preds = %cond.end, %entry\r\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %cond.end ]\r\n %conv3 = zext i1 false to i64\r\n %conv4 = trunc i64 %conv3 to i16\r\n br i1 false, label %cond.false, label %cond.end\r\n\r\ncond.false: ; preds = %for.body\r\n br label %cond.end\r\n\r\ncond.end: ; preds = %cond.false, %for.body\r\n %indvars.iv.next = add i64 %indvars.iv, 1\r\n %cmp = icmp ult i64 %indvars.iv, 1\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\r\n```\r\n\r\nBacktrace:\r\n```\r\nUnhandled opcode!\r\nUNREACHABLE executed at /scratch/tc-testing/tc-apr-2/llvm/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp:58!\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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt --passes=loop-vectorize reduced.ll\r\n #0 0x00005f05c836eb60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)\r\n #1 0x00005f05c836bf6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)\r\n #2 0x00005f05c836c0c5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000071a702442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000071a7024969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000071a7024969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000071a7024969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000071a702442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000071a7024287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00005f05c82a2afe (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2cb8afe)\r\n#10 0x00005f05c74dfe67 llvm::VPTypeAnalysis::inferScalarTypeForRecipe(llvm::VPInstruction const*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ef5e67)\r\n#11 0x00005f05c74dc88c llvm::VPTypeAnalysis::inferScalarType(llvm::VPValue const*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ef288c)\r\n#12 0x00005f05c750790e simplifyRecipes(llvm::VPlan&, llvm::LLVMContext&) VPlanTransforms.cpp:0:0\r\n#13 0x00005f05c750e606 llvm::VPlanTransforms::optimize(llvm::VPlan&, llvm::ScalarEvolution&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f24606)\r\n#14 0x00005f05c73ded66 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4d66)\r\n#15 0x00005f05c73e5319 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfb319)\r\n#16 0x00005f05c73e88a9 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfe8a9)\r\n#17 0x00005f05c73eb73e 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0173e)\r\n#18 0x00005f05c73ec88d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0288d)\r\n#19 0x00005f05c62f3276 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09276)\r\n#20 0x00005f05c8195141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)\r\n#21 0x00005f05c62eabd6 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)\r\n#22 0x00005f05c8193e3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)\r\n#23 0x00005f05c62f2dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)\r\n#24 0x00005f05c8191cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)\r\n#25 0x00005f05c5b6cce5 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-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)\r\n#26 0x00005f05c5b5f316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)\r\n#27 0x000071a702429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#28 0x000071a702429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#29 0x000071a702429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#30 0x00005f05c5b54f95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt\r\n```\r\nGodbolt: https://godbolt.org/z/bvY138WfG\r\n\r\nTriggered assertion: https://github.com/llvm/llvm-project/blob/f5991161529511ca6ebc058da2a0507c2fc5283e/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp#L58\r\n\r\nFound via fuzzer", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
98665
https://github.com/llvm/llvm-project/issues/98665
crash
662c6fc74c1ae7fdefd27524dfaeb7f3e9a1f553
2024-07-12T17:30:32
[ "llvm/test/Transforms/EarlyCSE" ]
{ "fix_commit": "34bfed63313d1340378fc1be931253333db8c36c", "components": [ "ConstantFold" ], "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": 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": [ [ 2754, 2780 ] ], "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": 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": [ "ConstantFoldIntrinsicCall2" ], "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 34bfed63313d1340378fc1be931253333db8c36c Author: Yingwei Zheng <[email protected]> Date: Mon Jul 15 13:00:25 2024 +0800 [ConstantFold] Fix result type when folding powi.f16 (#98681) Fixes #98665. diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 962880f68f07..6c52091cd5d7 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2754,27 +2754,28 @@ static Constant *ConstantFoldIntrinsicCall2(Intrinsic::ID IntrinsicID, Type *Ty, ((Mask & fcPosInf) && Op1V.isPosInfinity()); return ConstantInt::get(Ty, Result); } + case Intrinsic::powi: { + int Exp = static_cast<int>(Op2C->getSExtValue()); + switch (Ty->getTypeID()) { + case Type::HalfTyID: + case Type::FloatTyID: { + APFloat Res(std::pow(Op1V.convertToFloat(), Exp)); + if (Ty->isHalfTy()) { + bool Unused; + Res.convert(APFloat::IEEEhalf(), APFloat::rmNearestTiesToEven, + &Unused); + } + return ConstantFP::get(Ty->getContext(), Res); + } + case Type::DoubleTyID: + return ConstantFP::get(Ty, std::pow(Op1V.convertToDouble(), Exp)); + default: + return nullptr; + } + } default: break; } - - if (!Ty->isHalfTy() && !Ty->isFloatTy() && !Ty->isDoubleTy()) - return nullptr; - if (IntrinsicID == Intrinsic::powi && Ty->isHalfTy()) - return ConstantFP::get( - Ty->getContext(), - APFloat((float)std::pow((float)Op1V.convertToDouble(), - (int)Op2C->getZExtValue()))); - if (IntrinsicID == Intrinsic::powi && Ty->isFloatTy()) - return ConstantFP::get( - Ty->getContext(), - APFloat((float)std::pow((float)Op1V.convertToDouble(), - (int)Op2C->getZExtValue()))); - if (IntrinsicID == Intrinsic::powi && Ty->isDoubleTy()) - return ConstantFP::get( - Ty->getContext(), - APFloat((double)std::pow(Op1V.convertToDouble(), - (int)Op2C->getZExtValue()))); } return nullptr; }
[ { "file": "llvm/test/Transforms/EarlyCSE/math-2.ll", "commands": [ "opt -passes=early-cse -earlycse-debug-hash -S -o - %s" ], "tests": [ { "test_name": "i_powi", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare double @llvm.powi.f64.i32(double, i32) #0\n\ndefine double @i_powi() {\n %res = tail call fast double @llvm.powi.f64.i32(double 1.000000e+00, i32 2)\n ret double %res\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr98665", "test_body": "define half @pr98665() {\n %x = call half @llvm.powi.f16.i32(half 0xH3C00, i32 1)\n ret half %x\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare half @llvm.powi.f16.i32(half, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Misoptimization: `EarlyCSEPass` uses replaces `powi.f16` with `float` result", "body": "It looks like EarlyCSEPass is transformin the following:\r\n\r\n```llvm\r\n %_6 = alloca [48 x i8], align 8\r\n %_3 = alloca [2 x i8], align 2\r\n %0 = call half @llvm.powi.f16.i32(half 0xH3C00, i32 1) ; 0xH3C00 = 1.0f16\r\n store half %0, ptr %_3, align 2\r\n %1 = load half, ptr %_3, align 2\r\n %_4 = fcmp oeq half %1, 0xH3C00\r\n br i1 %_4, label %bb1, label %bb2\r\n```\r\n\r\nInto this:\r\n\r\n```llvm\r\n %_6 = alloca [48 x i8], align 8\r\n %_3 = alloca [2 x i8], align 2\r\n store float 1.000000e+00, ptr %_3, align 2\r\n %0 = load half, ptr %_3, align 2\r\n %_4 = fcmp oeq half %0, 0xH3C00\r\n br i1 %_4, label %bb1, label %bb2\r\n```\r\n\r\nAnd later InstCombine folds further into:\r\n\r\n```llvm\r\n %_6 = alloca [48 x i8], align 8\r\n %_3 = alloca [2 x i8], align 2\r\n store float 1.000000e+00, ptr %_3, align 2\r\n br i1 false, label %bb1, label %bb2\r\n```\r\n\r\nEarlyCSE seems to be doing an incorrect transformation: the result of `powi.f16(1.0, 1)` should be `half` 1.0 (0x3c00), but it is returning `float` 1.0 (0x3f800000). This is incorrect and an OOB write.\r\n\r\nThis comes from the following rust code, which asserts only when optimizations are enabled:\r\n\r\n```rust\r\n#![feature(f16)]\r\n#![allow(unused)]\r\n\r\n#[inline(never)]\r\npub fn check_pow(a: f16) {\r\n assert_eq!(1.0f16.powi(1), 1.0);\r\n}\r\n\r\npub fn main() {\r\n check_pow(1.0);\r\n println!(\"finished\");\r\n}\r\n```\r\n\r\nLink to compiler explorer: https://rust.godbolt.org/z/zsbzzxGvj\r\n\r\nI'm not sure how to reduce to a llc example since the passes appear different. I have been testing on aarch64 since x86 has other f16 ABI bugs, but I don't think this is limited to aarch64.", "author": "tgross35", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/jhM834G3z\r\n```\r\ndefine half @test() {\r\n %x = call half @llvm.powi.f16.i32(half 0xH3C00, i32 1)\r\n ret half %x\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/IR/Value.cpp:507: void llvm::Value::doRAUW(llvm::Value*, llvm::Value::ReplaceMetadataUses): Assertion `New->getType() == getType() && \"replaceAllUses of value with new value of different 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=early-cse <source>\r\n1.\tRunning pass \"function(early-cse<>)\" on module \"<source>\"\r\n2.\tRunning pass \"early-cse<>\" on function \"test\"\r\n #0 0x0000000004e9b948 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e9b948)\r\n #1 0x0000000004e990bc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000078ad4b442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000078ad4b4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000078ad4b442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000078ad4b4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000078ad4b42871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000078ad4b439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004cce094 llvm::Value::doRAUW(llvm::Value*, llvm::Value::ReplaceMetadataUses) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cce094)\r\n #9 0x0000000003ae3b58 (anonymous namespace)::EarlyCSE::processNode(llvm::DomTreeNodeBase<llvm::BasicBlock>*) EarlyCSE.cpp:0:0\r\n#10 0x0000000003ae5a85 (anonymous namespace)::EarlyCSE::run() EarlyCSE.cpp:0:0\r\n#11 0x0000000003ae81f8 llvm::EarlyCSEPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ae81f8)\r\n#12 0x0000000002ac11be llvm::detail::PassModel<llvm::Function, llvm::EarlyCSEPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2ac11be)\r\n#13 0x0000000004c9f2d8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9f2d8)\r\n#14 0x0000000000dc9bee 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+0xdc9bee)\r\n#15 0x0000000004c9dd46 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9dd46)\r\n#16 0x0000000000dca1fe 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+0xdca1fe)\r\n#17 0x0000000004c9bf10 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c9bf10)\r\n#18 0x00000000008db1d2 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+0x8db1d2)\r\n#19 0x00000000008ce0fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce0fc)\r\n#20 0x000078ad4b429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#21 0x000078ad4b429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#22 0x00000000008c556e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c556e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n\r\nThere is a bug in constant folding.\r\n\r\n" } ] }
true
null
105988
https://github.com/llvm/llvm-project/issues/105988
miscompilation
4b0c0ec6b8065e611640f44adce94e2da12b3a3a
2024-08-25T14:54:29
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e1d22512906e69846c8f6a2d29b30832b7c12b46", "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": [ [ 15975, 15980 ] ], "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 e1d22512906e69846c8f6a2d29b30832b7c12b46 Author: Alexey Bataev <[email protected]> Date: Mon Aug 26 11:30:13 2024 -0700 [SLP]Fix minbitwidth analysis for gather nodes with icmp users. If the node is not in MinBWs container and the user node is icmp node, the compiler should not check the type size of the user instruction, it is always 1 and is not good for actual bitwidth analysis. Fixes https://github.com/llvm/llvm-project/issues/105988 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index def73e8d0c0d..ed47ed661ab9 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -15975,6 +15975,10 @@ void BoUpSLP::computeMinimumValueSizes() { auto It = MinBWs.find(TE); if (It != MinBWs.end() && It->second.first > UserTESz) return true; + // The size of icmp is always 1 and should not be + // considered. + if (TE->getOpcode() == Instruction::ICmp) + return true; return DL->getTypeSizeInBits(U->getType()) > UserTESz; })); })) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/gather-with-cmp-user.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i1 @test(i32 %g, i16 %d) {\nentry:\n %0 = and i16 %d, 1\n %xor.i.i = xor i32 %g, 1\n %conv1.i.i = trunc i32 %xor.i.i to i8\n %notsub.i = add i8 %conv1.i.i, -1\n %cmp.i.i = icmp sgt i8 %notsub.i, -3\n %conv3.i.i = zext i1 %cmp.i.i to i32\n %cmp4.i.i = icmp sgt i32 %xor.i.i, %conv3.i.i\n %conv1.1.i.i = trunc i32 %g to i8\n %notsub25.i = add i8 %conv1.1.i.i, -1\n %cmp.1.i.i = icmp sgt i8 %notsub25.i, -3\n %conv3.1.i.i = zext i1 %cmp.1.i.i to i32\n %cmp4.1.i.i = icmp sgt i32 %g, %conv3.1.i.i\n %notsub26.i = add i8 %conv1.1.i.i, -9\n %cmp.i17.i = icmp sgt i8 %notsub26.i, -3\n %conv3.i18.i = zext i1 %cmp.i17.i to i32\n %cmp4.i19.i = icmp sgt i32 %g, %conv3.i18.i\n %notsub27.i = add i8 %conv1.i.i, -9\n %cmp.1.i22.i = icmp sgt i8 %notsub27.i, -3\n %conv3.1.i23.i = zext i1 %cmp.1.i22.i to i32\n %cmp4.1.i24.i = icmp sgt i32 %xor.i.i, %conv3.1.i23.i\n %1 = and i1 %cmp4.i19.i, %cmp4.1.i24.i\n %2 = and i1 %cmp4.i.i, %1\n %3 = and i1 %cmp4.1.i.i, %2\n ret i1 %3\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Miscompile at O3", "body": "Reproducer: https://gist.github.com/dtcxzyw/117dc735db97658ea852d30fd896242a\r\n```console\r\n> bin/clang -O0 test.c -w -I/usr/include/csmith && ./a.out\r\nchecksum = BDCB7A78\r\n> bin/clang -O3 test.c -w -mllvm -inline-threshold=100000 -I/usr/include/csmith && ./a.out\r\nchecksum = 9198FC41\r\n```\r\n\r\nllvm version: 1193f7d6487d2d94009f8d8d27da3907136482b9\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/GCXoe9\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\n\r\ntarget datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i1 @main(i32 %g.promoted.i.i, i16 %d.promoted.i.i) {\r\nentry:\r\n %0 = and i16 %d.promoted.i.i, 1\r\n %xor.i.i = xor i32 %g.promoted.i.i, 1\r\n %conv1.i.i = trunc i32 %xor.i.i to i8\r\n %notsub.i = add i8 %conv1.i.i, -1\r\n %cmp.i.i = icmp sgt i8 %notsub.i, -3\r\n %conv3.i.i = zext i1 %cmp.i.i to i32\r\n %cmp4.i.i = icmp sgt i32 %xor.i.i, %conv3.i.i\r\n %conv1.1.i.i = trunc i32 %g.promoted.i.i to i8\r\n %notsub25.i = add i8 %conv1.1.i.i, -1\r\n %cmp.1.i.i = icmp sgt i8 %notsub25.i, -3\r\n %conv3.1.i.i = zext i1 %cmp.1.i.i to i32\r\n %cmp4.1.i.i = icmp sgt i32 %g.promoted.i.i, %conv3.1.i.i\r\n %notsub26.i = add i8 %conv1.1.i.i, -9\r\n %cmp.i17.i = icmp sgt i8 %notsub26.i, -3\r\n %conv3.i18.i = zext i1 %cmp.i17.i to i32\r\n %cmp4.i19.i = icmp sgt i32 %g.promoted.i.i, %conv3.i18.i\r\n %notsub27.i = add i8 %conv1.i.i, -9\r\n %cmp.1.i22.i = icmp sgt i8 %notsub27.i, -3\r\n %conv3.1.i23.i = zext i1 %cmp.1.i22.i to i32\r\n %cmp4.1.i24.i = icmp sgt i32 %xor.i.i, %conv3.1.i23.i\r\n %1 = and i1 %cmp4.i19.i, %cmp4.1.i24.i\r\n %2 = and i1 %cmp4.i.i, %1\r\n %3 = and i1 %cmp4.1.i.i, %2\r\n ret i1 %3\r\n}\r\n```\r\nOutput:\r\n```\r\ndefine i1 @main(i32 %g.promoted.i.i, i16 %d.promoted.i.i) {\r\nentry:\r\n %0 = and i16 %d.promoted.i.i, 1\r\n %xor.i.i = xor i32 %g.promoted.i.i, 1\r\n %1 = trunc i32 %g.promoted.i.i to i8\r\n %2 = insertelement <2 x i8> poison, i8 %1, i32 0\r\n %3 = trunc i32 %xor.i.i to i8\r\n %4 = insertelement <2 x i8> %2, i8 %3, i32 1\r\n %5 = shufflevector <2 x i8> %4, <2 x i8> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>\r\n %6 = add <4 x i8> %5, <i8 -9, i8 -9, i8 -1, i8 -1>\r\n %7 = icmp sgt <4 x i8> %6, <i8 -3, i8 -3, i8 -3, i8 -3>\r\n %8 = zext <4 x i1> %7 to <4 x i8>\r\n %9 = sext <2 x i8> %4 to <2 x i32>\r\n %10 = shufflevector <2 x i32> %9, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>\r\n %11 = zext <4 x i8> %8 to <4 x i32>\r\n %12 = icmp sgt <4 x i32> %10, %11\r\n %13 = call i1 @llvm.vector.reduce.and.v4i1(<4 x i1> %12)\r\n ret i1 %13\r\n}\r\n```\r\n\r\ncc @alexey-bataev " } ] }
true
null
88297
https://github.com/llvm/llvm-project/issues/88297
crash
9ec6c5d26321f5d32d97218f850ae7cafda32b2e
2024-04-10T16:52:41
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "34777c238b117b52dd41a9d12e8b54fb83677a12", "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": 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": [ [ 361, 368 ], [ 376, 382 ] ], "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": 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 34777c238b117b52dd41a9d12e8b54fb83677a12 Author: Florian Hahn <[email protected]> Date: Tue Apr 16 21:24:24 2024 +0100 [VPlan] Don't mark VPBlendRecipe as phi-like. VPBlendRecipes don't get lowered to phis and usually do not appear at the beginning of blocks, due to their masks appearing before them. This effectively relaxes an over-eager verifier message. Fixes https://github.com/llvm/llvm-project/issues/88297. Fixes https://github.com/llvm/llvm-project/issues/88804. diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h index da3a768552fc..3f8d4f4fe7d6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanValue.h +++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h @@ -361,8 +361,8 @@ public: VPWidenMemoryInstructionSC, VPWidenSC, VPWidenSelectSC, - // START: Phi-like recipes. Need to be kept together. VPBlendSC, + // START: Phi-like recipes. Need to be kept together. VPWidenPHISC, VPPredInstPHISC, // START: SubclassID for recipes that inherit VPHeaderPHIRecipe. @@ -376,7 +376,7 @@ public: VPReductionPHISC, // END: SubclassID for recipes that inherit VPHeaderPHIRecipe // END: Phi-like recipes - VPFirstPHISC = VPBlendSC, + VPFirstPHISC = VPWidenPHISC, VPFirstHeaderPHISC = VPCanonicalIVPHISC, VPLastHeaderPHISC = VPReductionPHISC, VPLastPHISC = VPReductionPHISC,
[ { "file": "llvm/test/Transforms/LoopVectorize/blend-in-header.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -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-ni:1-p2:32:8:8:32-ni:2\"\n\n; Test with blend recipe in header VPBB, from\n; https://github.com/llvm/llvm-project/issues/88297.\ndefine i64 @pr88297() {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 1, %then ], [ 0, %loop.header ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n\ndefine i64 @pr88297_incoming_ops_reordered() {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 0, %loop.header ], [ 1, %then ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n\ndefine i64 @invar_cond(i1 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 1, %then ], [ 0, %loop.header ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n\ndefine i64 @invar_cond_incoming_ops_reordered(i1 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %then\n\nthen:\n br label %loop.latch\n\nloop.latch:\n %r = phi i64 [ 0, %loop.header ], [ 1, %then ]\n %iv.next = add i32 %iv, 1\n %icmp = icmp sgt i32 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n %r.lcssa = phi i64 [ %r, %loop.latch ]\n ret i64 %r.lcssa\n}\n;.\n;.", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `verifyVPlanIsValid(*Plan) && \"VPlan is invalid\"' failed", "body": "The following test fails when run opt with -passes loop-vectorize\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\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb2, %bb\r\n %phi = phi i32 [ %add, %bb2 ], [ 0, %bb ]\r\n br i1 false, label %bb2, label %bb4\r\n\r\nbb2: ; preds = %bb4, %bb1\r\n %phi3 = phi i64 [ 1, %bb4 ], [ 0, %bb1 ]\r\n %add = add i32 %phi, 1\r\n %icmp = icmp sgt i32 %phi, 0\r\n br i1 %icmp, label %bb5, label %bb1\r\n\r\nbb4: ; preds = %bb1\r\n br label %bb2\r\n\r\nbb5: ; preds = %bb2\r\n %phi6 = phi i64 [ %phi3, %bb2 ]\r\n ret void\r\n}\r\n```\r\nReproducer https://godbolt.org/z/9YW1o7qo6\r\nStack dump:\r\n```\r\nFound non-header PHI recipe in header VPBB: BLEND ir<%phi3> = ir<1> ir<0>/ir<false>\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8555: void llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount): Assertion `verifyVPlanIsValid(*Plan) && \"VPlan is invalid\"' 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 loop-vectorize <source>\r\n #0 0x0000000004d05ee8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d05ee8)\r\n #1 0x0000000004d0363c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7623242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f76232969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f7623242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f76232287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f762322871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f7623239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003de70b8 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3de70b8)\r\n #9 0x0000000003dee731 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3dee731)\r\n#10 0x0000000003df18fe llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df18fe)\r\n#11 0x0000000003df4c6d 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+0x3df4c6d)\r\n#12 0x0000000003df5e7b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3df5e7b)\r\n#13 0x0000000002d67f0e 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+0x2d67f0e)\r\n#14 0x0000000000db3554 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+0xdb3554)\r\n#15 0x0000000004b1663e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b1663e)\r\n#16 0x0000000000d97cce 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+0xd97cce)\r\n#17 0x0000000004b1454c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4b1454c)\r\n#18 0x00000000008c74f2 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+0x8c74f2)\r\n#19 0x00000000008bad45 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8bad45)\r\n#20 0x00007f7623229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#21 0x00007f7623229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#22 0x00000000008b1aee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8b1aee)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
88796
https://github.com/llvm/llvm-project/issues/88796
crash
9ef28cf88ca6e45c3ecb75c649463f8797db68d2
2024-04-15T21:04:00
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "57b9c15227ec15a5e2abf4587d7d0ad536cff9e6", "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": [ [ 1961, 1977 ] ], "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::foldTruncFromReductions" ], "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 57b9c15227ec15a5e2abf4587d7d0ad536cff9e6 Author: Ramkumar Ramachandra <[email protected]> Date: Wed May 8 09:47:55 2024 +0100 VectorCombine: fix logical error after m_Trunc match (#91201) The matcher m_Trunc() matches an Operator with a given Opcode, which could either be an Instruction or ConstExpr. VectorCombine::foldTruncFromReductions() incorrectly assumes that the pattern matched is always an Instruction, and attempts a cast. Fix this. Fixes #88796. diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index bbb70134870a..8573a8adf53b 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1961,17 +1961,17 @@ bool VectorCombine::foldTruncFromReductions(Instruction &I) { if (!match(ReductionSrc, m_OneUse(m_Trunc(m_Value(TruncSrc))))) return false; - auto *Trunc = cast<CastInst>(ReductionSrc); auto *TruncSrcTy = cast<VectorType>(TruncSrc->getType()); auto *ReductionSrcTy = cast<VectorType>(ReductionSrc->getType()); Type *ResultTy = I.getType(); TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; - InstructionCost OldCost = - TTI.getCastInstrCost(Instruction::Trunc, ReductionSrcTy, TruncSrcTy, - TTI::CastContextHint::None, CostKind, Trunc) + - TTI.getArithmeticReductionCost(ReductionOpc, ReductionSrcTy, std::nullopt, - CostKind); + InstructionCost OldCost = TTI.getArithmeticReductionCost( + ReductionOpc, ReductionSrcTy, std::nullopt, CostKind); + if (auto *Trunc = dyn_cast<CastInst>(ReductionSrc)) + OldCost += + TTI.getCastInstrCost(Instruction::Trunc, ReductionSrcTy, TruncSrcTy, + TTI::CastContextHint::None, CostKind, Trunc); InstructionCost NewCost = TTI.getArithmeticReductionCost(ReductionOpc, TruncSrcTy, std::nullopt, CostKind) +
[ { "file": "llvm/test/Transforms/VectorCombine/pr88796.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test() {\nentry:\n %0 = tail call i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16> trunc (<vscale x 8 x i32> splat (i32 268435456) to <vscale x 8 x i16>))\n ret i32 0\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VectorCombine] Assertion 'isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.", "body": "Reduced LLVM IR:\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 %0 = tail call i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16> trunc (<vscale x 8 x i32> shufflevector (<vscale x 8 x i32> insertelement (<vscale x 8 x i32> poison, i32 268435456, i64 0), <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer) to <vscale x 8 x i16>))\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16>) #1\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-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,-za128rs,-za64rs,-zacas,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-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,-zmmul,-zvbb,-zvbc,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\nGodbolt: https://godbolt.org/z/jrEv178Ev\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-15/llvm/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::CastInst; From = llvm::Value]: 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. Program arguments: /scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt --passes=vector-combine reduced.ll\r\n #0 0x00005eb857c5a1b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2da91b0)\r\n #1 0x00005eb857c575bf llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2da65bf)\r\n #2 0x00005eb857c57715 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000071f7d0e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000071f7d0e969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000071f7d0e969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000071f7d0e969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000071f7d0e42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000071f7d0e287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000071f7d0e2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000071f7d0e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005eb856da36eb (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const VectorCombine.cpp:0:0\r\n#12 0x00005eb856da4290 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1ef3290)\r\n#13 0x00005eb855bc7936 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd16936)\r\n#14 0x00005eb857a7f451 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bce451)\r\n#15 0x00005eb855bbec26 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-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd0dc26)\r\n#16 0x00005eb857a7e12b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bcd12b)\r\n#17 0x00005eb855bc6ee6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd15ee6)\r\n#18 0x00005eb857a7bf61 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bcaf61)\r\n#19 0x00005eb855440205 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-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x58f205)\r\n#20 0x00005eb855432836 optMain (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x581836)\r\n#21 0x000071f7d0e29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#22 0x000071f7d0e29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#23 0x000071f7d0e29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#24 0x00005eb8554284b5 _start (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x5774b5)\r\nzsh: IOT instruction /scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/op\r\n```\r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
136650
https://github.com/llvm/llvm-project/issues/136650
miscompilation
2e389cb9aae0e9734fc8e16f6ebc6edb392d79a9
2025-04-22T03:44:35
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "8abc917fe04140b6c6088a67e0398f637efde808", "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": [ [ 1480, 1486 ] ], "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 8abc917fe04140b6c6088a67e0398f637efde808 Author: Yingwei Zheng <[email protected]> Date: Thu Apr 24 00:12:30 2025 +0800 [InstCombine] Do not fold logical is_finite test (#136851) This patch disables the fold for logical is_finite test (i.e., `and (fcmp ord x, 0), (fcmp u* x, inf) -> fcmp o* x, inf`). It is still possible to allow this fold for several logical cases (e.g., `stripSignOnlyFPOps(RHS0)` does not strip any operations). Since this patch has no real-world impact, I decided to disable this fold for all logical cases. Alive2: https://alive2.llvm.org/ce/z/aH4LC7 Closes https://github.com/llvm/llvm-project/issues/136650. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index f1b225c0f238..979a9cbedf2e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1480,7 +1480,9 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS, } } - if (IsAnd && stripSignOnlyFPOps(LHS0) == stripSignOnlyFPOps(RHS0)) { + // This transform is not valid for a logical select. + if (!IsLogicalSelect && IsAnd && + stripSignOnlyFPOps(LHS0) == stripSignOnlyFPOps(RHS0)) { // and (fcmp ord x, 0), (fcmp u* x, inf) -> fcmp o* x, inf // and (fcmp ord x, 0), (fcmp u* fabs(x), inf) -> fcmp o* x, inf if (Value *Left = matchIsFiniteTest(Builder, LHS, RHS))
[ { "file": "llvm/test/Transforms/InstCombine/and-fcmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "clang_builtin_isnormal_inf_check_fabs_nnan_logical_select", "test_body": "define i1 @clang_builtin_isnormal_inf_check_fabs_nnan_logical_select(half %x) {\n %copysign.x = call nnan half @llvm.fabs.f16(half %x)\n %ord = fcmp ord half %x, 0xH0000\n %cmp = fcmp uge half %copysign.x, 0xH7C00\n %and = select i1 %ord, i1 %cmp, i1 false\n ret i1 %and\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare half @llvm.fabs.f16(half) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clang_builtin_isnormal_inf_check_copysign_logical_select", "test_body": "define i1 @clang_builtin_isnormal_inf_check_copysign_logical_select(half %x, half %y) {\n %copysign.x = call half @llvm.copysign.f16(half %x, half %y)\n %ord = fcmp ord half %x, 0xH0000\n %cmp = fcmp uge half %copysign.x, 0xH7C00\n %and = select i1 %ord, i1 %cmp, i1 false\n ret i1 %and\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare half @llvm.copysign.f16(half, half) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "isnormal_logical_select_0", "test_body": "define i1 @isnormal_logical_select_0(half %x) {\n %fabs.x = call half @llvm.fabs.f16(half %x)\n %ord = fcmp ord half %fabs.x, 0xH0000\n %cmp.inf = fcmp uge half %fabs.x, 0xH7C00\n %and = select i1 %ord, i1 %cmp.inf, i1 false\n ret i1 %and\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare half @llvm.fabs.f16(half) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "clang_builtin_isnormal_inf_check_copysign", "test_body": "define i1 @clang_builtin_isnormal_inf_check_copysign(half %x, half %y) {\n %copysign.x = call half @llvm.copysign.f16(half %x, half %y)\n %ord = fcmp ord half %x, 0xH0000\n %cmp = fcmp uge half %copysign.x, 0xH7C00\n %and = and i1 %ord, %cmp\n ret i1 %and\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare half @llvm.copysign.f16(half, half) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Poison safety violation in `foldLogicOfFCmps`", "body": "Reproducer: https://alive2.llvm.org/ce/z/Qcvvgi\n```\n----------------------------------------\ndefine i1 @src(half %x, half %y) {\n#0:\n %copysign.x = copysign half %x, %y\n %ord = fcmp ord half %x, 0x0000\n %cmp = fcmp uge half %copysign.x, 0x7c00\n %#1 = select i1 %ord, i1 %cmp, i1 0\n ret i1 %#1\n}\n=>\ndefine i1 @src(half %x, half %y) nofree willreturn memory(none) {\n#0:\n %copysign.x = copysign half %x, %y\n %#1 = fcmp oeq half %copysign.x, 0x7c00\n ret i1 %#1\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\nhalf %x = #x7c02 (SNaN)\nhalf %y = poison\n\nSource:\nhalf %copysign.x = poison\ni1 %ord = #x0 (0)\ni1 %cmp = poison\ni1 %#1 = #x0 (0)\n\nTarget:\nhalf %copysign.x = poison\ni1 %#1 = poison\nSource value: #x0 (0)\nTarget value: poison\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
116775
https://github.com/llvm/llvm-project/issues/116775
crash
bdf00e2216280edef1ec91ccc07987db92197b59
2024-11-19T09:53:12
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "03d8831fa8ef5b7e32172c718b550a454645faea", "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": [ [ 997, 1003 ] ], "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 03d8831fa8ef5b7e32172c718b550a454645faea Author: Yingwei Zheng <[email protected]> Date: Tue Nov 19 22:17:24 2024 +0800 [InstCombine] Handle constant GEP expr in `SimplifyDemandedUseBits` (#116794) Closes https://github.com/llvm/llvm-project/issues/116775. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 5eb807dcb76c..392c5c78345c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -997,7 +997,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, uint64_t MaskedGEPIndex = HighBitsGEPIndex | MaskedLowBitsGEPIndex; if (MaskedGEPIndex != GEPIndex) { - auto *GEP = cast<GetElementPtrInst>(II->getArgOperand(0)); + auto *GEP = cast<GEPOperator>(II->getArgOperand(0)); Builder.SetInsertPoint(I); Type *GEPIndexType = DL.getIndexType(GEP->getPointerOperand()->getType());
[ { "file": "llvm/test/Transforms/InstCombine/ptrmask.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "ptrmask_demandedbits_constantexpr", "test_body": "target datalayout = \"p1:64:64:64:32\"\n\n@GC_arrays = external global { i8, i8, i64 }\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare ptr @llvm.ptrmask.p0.i64(ptr, i64) #0\n\ndefine ptr @ptrmask_demandedbits_constantexpr() {\nentry:\n %aligned_result = call ptr @llvm.ptrmask.p0.i64(ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 1), i64 -8)\n ret ptr %aligned_result\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "ptrmask_is_useless_fail1", "test_body": "target datalayout = \"p1:64:64:64:32\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare ptr @llvm.ptrmask.p0.i64(ptr, i64) #0\n\ndefine ptr @ptrmask_is_useless_fail1(i64 %i, i64 %m) {\n %m0 = and i64 %m, 127\n %i0 = and i64 %i, 511\n %p0 = inttoptr i64 %i0 to ptr\n %r = call ptr @llvm.ptrmask.p0.i64(ptr %p0, i64 %m0)\n ret ptr %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Segfault when building https://github.com/ivmai/bdwgc@4fe4238", "body": "Attempting to build [https://github.com/ivmai/bdwgc@4fe4238](https://github.com/ivmai/bdwgc/tree/4fe42389509ff059bad8d4c955a570b34a6bda4b) using\r\n```shell\r\n$ ./autogen.sh\r\n$ ./configure --with-libatomic-ops --enable-cplusplus --enable-large-config\r\n$ make\r\n```\r\nresults in\r\n```text\r\nlibtool: compile: clang -std=gnu23 -DHAVE_CONFIG_H -I./include -I./include -DNDEBUG -fexceptions -DGC_VISIBILITY_HIDDEN_SET -fvisibility=hidden -Wall -Wextra -Wpedantic -Wno-long-long -O2 -march=native -Wno-frame-address -MT extra/gc.lo -MD -MP -MF extra/.deps/gc.Tpo -c extra/gc.c -fno-common -DPIC -o extra/.libs/gc.o\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.\tProgram arguments: clang -std=gnu23 -DHAVE_CONFIG_H -I./include -I./include -DNDEBUG -fexceptions -DGC_VISIBILITY_HIDDEN_SET -fvisibility=hidden -Wall -Wextra -Wpedantic -Wno-long-long -O2 -march=native -Wno-frame-address -MT extra/gc.lo -MD -MP -MF extra/.deps/gc.Tpo -c extra/gc.c -fno-common -DPIC -o extra/.libs/gc.o\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,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>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,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,constraint-elimination,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,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;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 \"extra/gc.c\"\r\n4.\tRunning pass \"cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,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>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,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,constraint-elimination,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,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;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 \"extra/gc.c\"\r\n5.\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"GC_push_finalizer_structures\"\r\n #0 0x0000000112ecda98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x3299a98)\r\n #1 0x0000000112eccb47 llvm::sys::RunSignalHandlers() (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x3298b47)\r\n #2 0x0000000112eccde1 llvm::sys::CleanupOnSignal(unsigned long) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x3298de1)\r\n #3 0x0000000112df2644 CrashRecoverySignalHandler(int) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x31be644)\r\n #4 0x00007ff81abe4fdd (/usr/lib/system/libsystem_platform.dylib+0x7ff80046afdd)\r\n #5 0x0000000112e1d131 computeForAddCarry(llvm::KnownBits const&, llvm::KnownBits const&, bool, bool) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x31e9131)\r\n #6 0x0000000112318cdd llvm::TargetFolder::FoldGEP(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::GEPNoWrapFlags) const (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26e4cdd)\r\n #7 0x00000001102d2177 llvm::IRBuilderBase::CreateGEP(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::GEPNoWrapFlags) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x69e177)\r\n #8 0x000000011209545a llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Instruction*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x246145a)\r\n #9 0x0000000112097524 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&, llvm::KnownBits&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2463524)\r\n#10 0x0000000111ffc58b llvm::InstCombinerImpl::visitCallInst(llvm::CallInst&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x23c858b)\r\n#11 0x0000000111f85788 llvm::InstCombinerImpl::run() (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2351788)\r\n#12 0x0000000111f765e2 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&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x23425e2)\r\n#13 0x0000000111fc1b85 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x238db85)\r\n#14 0x0000000110596272 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x962272)\r\n#15 0x0000000112b6736a llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2f3336a)\r\n#16 0x000000011003f522 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/llvm-project@HEAD/lib/libLLVM.dylib+0x40b522)\r\n#17 0x00000001122fe7db llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26ca7db)\r\n#18 0x0000000110b41712 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/llvm-project@HEAD/lib/libLLVM.dylib+0xf0d712)\r\n#19 0x00000001122fa573 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/llvm-project@HEAD/lib/libLLVM.dylib+0x26c6573)\r\n#20 0x0000000110b3e332 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/llvm-project@HEAD/lib/libLLVM.dylib+0xf0a332)\r\n#21 0x00000001122fcc0e llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26c8c0e)\r\n#22 0x0000000110b413a2 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/llvm-project@HEAD/lib/libLLVM.dylib+0xf0d3a2)\r\n#23 0x00000001122fbe83 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26c7e83)\r\n#24 0x0000000110b3e012 llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0xf0a012)\r\n#25 0x0000000112b65a22 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2f31a22)\r\n#26 0x0000000110d25d8b llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x10f1d8b)\r\n#27 0x0000000110594012 llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x960012)\r\n#28 0x0000000112b65a22 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2f31a22)\r\n#29 0x000000010788b478 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>&, std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x172d478)\r\n#30 0x0000000107883b08 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::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x1725b08)\r\n#31 0x0000000107d037d3 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x1ba57d3)\r\n#32 0x000000010635df1d clang::ParseAST(clang::Sema&, bool, bool) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x1fff1d)\r\n#33 0x000000010877f3d7 clang::FrontendAction::Execute() (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x26213d7)\r\n#34 0x00000001086e0500 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x2582500)\r\n#35 0x00000001087f60e9 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x26980e9)\r\n#36 0x000000010128d4f9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/llvm-project@HEAD/bin/clang-20+0x1000084f9)\r\n#37 0x0000000101289f88 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/opt/llvm-project@HEAD/bin/clang-20+0x100004f88)\r\n#38 0x00000001082b552e void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x215752e)\r\n#39 0x0000000112df288c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x31be88c)\r\n#40 0x00000001082b5431 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x2157431)\r\n#41 0x0000000108262131 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x2104131)\r\n#42 0x00000001082623bf clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x21043bf)\r\n#43 0x00000001082b00c0 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x21520c0)\r\n#44 0x00000001012892b3 clang_main(int, char**, llvm::ToolContext const&) (/opt/llvm-project@HEAD/bin/clang-20+0x1000042b3)\r\n#45 0x00000001012984cb main (/opt/llvm-project@HEAD/bin/clang-20+0x1000134cb)\r\n#46 0x00007ff81a82a345 \r\nclang: error: clang frontend command failed with exit code 139 (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git c25c6c32494c8d1038438b6208d42ba40f25270e)\r\nTarget: x86_64-apple-darwin23.6.0\r\nThread model: posix\r\nInstalledDir: /opt/llvm-project@HEAD/bin\r\nclang: note: diagnostic msg: \r\n********************\r\n```\r\n\r\nFind attached the preprocessed source code at [gc-add69e.c.gz](https://github.com/user-attachments/files/17813033/gc-add69e.c.gz).", "author": "d125q", "labels": [ "llvm:instcombine", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/Ts478aen6\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\n@GC_arrays = external global { i8, i8, i64 }\r\n\r\ndefine ptr @GC_push_finalizer_structures() {\r\nentry:\r\n %aligned_result.i = call ptr @llvm.ptrmask.p0.i64(ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 1), i64 -8)\r\n ret ptr %aligned_result.i\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::GetElementPtrInst; From = llvm::Value]: 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=instcombine <source>\r\n1.\tRunning pass \"function(instcombine<max-iterations=1;verify-fixpoint>)\" on module \"<source>\"\r\n2.\tRunning pass \"instcombine<max-iterations=1;verify-fixpoint>\" on function \"GC_push_finalizer_structures\"\r\n #0 0x0000000005194b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5194b38)\r\n #1 0x000000000519252c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074b7d8442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074b7d84969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074b7d8442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074b7d84287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000074b7d842871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000074b7d8439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000040d9310 decltype(auto) llvm::cast<llvm::GetElementPtrInst, llvm::Value>(llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40d9310)\r\n #9 0x00000000040e2f9e llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Instruction*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40e2f9e)\r\n#10 0x00000000040e6082 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&, llvm::KnownBits&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40e6082)\r\n#11 0x00000000040355a6 llvm::InstCombinerImpl::visitCallInst(llvm::CallInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40355a6)\r\n#12 0x0000000003fe2311 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe2311)\r\n#13 0x0000000003fe3cc6 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&) (.isra.0) InstructionCombining.cpp:0:0\r\n#14 0x0000000003fe504e llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe504e)\r\n#15 0x0000000002c5c24e llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2c5c24e)\r\n#16 0x0000000004f949e8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f949e8)\r\n#17 0x0000000000e4027e 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+0xe4027e)\r\n#18 0x0000000004f9340e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f9340e)\r\n#19 0x0000000000e3f92e 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+0xe3f92e)\r\n#20 0x0000000004f92e40 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f92e40)\r\n#21 0x0000000000909fda 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+0x909fda)\r\n#22 0x00000000008fc70a optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fc70a)\r\n#23 0x000074b7d8429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#24 0x000074b7d8429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#25 0x00000000008f3e9e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f3e9e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```" } ] }
true
null
114905
https://github.com/llvm/llvm-project/issues/114905
miscompilation
1b476ecdcf4b544af1436341fc923c0b73793cbe
2024-11-05T01:11:52
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "889215a30ed60474e573f9632d1fa362dfa1b04e", "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": [ [ 19821, 19841 ] ], "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 889215a30ed60474e573f9632d1fa362dfa1b04e Author: Alexey Bataev <[email protected]> Date: Thu Dec 26 05:09:51 2024 -0800 [SLP]Followup fix for the poisonous logical op in reductions If the VectorizedTree still may generate poisonous value, but it is not the original operand of the reduction op, need to check if Res still the operand, to generate correct code. Fixes #114905 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 57f3016fbe1e..e9fc89fa242a 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -19821,21 +19821,21 @@ public: Builder.SetCurrentDebugLocation( cast<Instruction>(ReductionOps.front().front())->getDebugLoc()); if (AnyBoolLogicOp) { - - if (auto It = ReducedValsToOps.find(VectorizedTree); - It == ReducedValsToOps.end() || + auto It = ReducedValsToOps.find(VectorizedTree); + auto It1 = ReducedValsToOps.find(Res); + if ((It == ReducedValsToOps.end() && It1 == ReducedValsToOps.end()) || isGuaranteedNotToBePoison(VectorizedTree, AC) || - any_of(It->getSecond(), [&](Instruction *I) { - return isBoolLogicOp(I) && - getRdxOperand(I, 0) == VectorizedTree; - })) { + (It != ReducedValsToOps.end() && + any_of(It->getSecond(), [&](Instruction *I) { + return isBoolLogicOp(I) && + getRdxOperand(I, 0) == VectorizedTree; + }))) { ; - } else if (auto It = ReducedValsToOps.find(Res); - It == ReducedValsToOps.end() || - isGuaranteedNotToBePoison(Res, AC) || - any_of(It->getSecond(), [&](Instruction *I) { + } else if (isGuaranteedNotToBePoison(Res, AC) || + (It1 != ReducedValsToOps.end() && + any_of(It1->getSecond(), [&](Instruction *I) { return isBoolLogicOp(I) && getRdxOperand(I, 0) == Res; - })) { + }))) { std::swap(VectorizedTree, Res); } else { VectorizedTree = Builder.CreateFreeze(VectorizedTree);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll", "commands": [ "opt < %s -passes=slp-vectorizer -mtriple=x86_64-- -S", "opt < %s -passes=slp-vectorizer -mtriple=x86_64-- -mattr=avx512vl -S" ], "tests": [ { "test_name": "logical_or_icmp_extra_op", "test_body": "define i1 @logical_or_icmp_extra_op(<4 x i32> %x, <4 x i32> %y, i1 %c) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 1\n %x2 = extractelement <4 x i32> %x, i32 2\n %x3 = extractelement <4 x i32> %x, i32 3\n %y0 = extractelement <4 x i32> %y, i32 0\n %y1 = extractelement <4 x i32> %y, i32 1\n %y2 = extractelement <4 x i32> %y, i32 2\n %y3 = extractelement <4 x i32> %y, i32 3\n %d0 = icmp slt i32 %x0, %y0\n %d1 = icmp slt i32 %x1, %y1\n %d2 = icmp slt i32 %x2, %y2\n %d3 = icmp slt i32 %x3, %y3\n %s3 = select i1 %c, i1 true, i1 %c\n %s4 = select i1 %s3, i1 true, i1 %d0\n %s5 = select i1 %s4, i1 true, i1 %d1\n %s6 = select i1 %s5, i1 true, i1 %d2\n %s7 = select i1 %s6, i1 true, i1 %d3\n ret i1 %s7\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "logical_and_icmp_extra_op", "test_body": "define i1 @logical_and_icmp_extra_op(<4 x i32> %x, <4 x i32> %y, i1 %c) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 1\n %x2 = extractelement <4 x i32> %x, i32 2\n %x3 = extractelement <4 x i32> %x, i32 3\n %y0 = extractelement <4 x i32> %y, i32 0\n %y1 = extractelement <4 x i32> %y, i32 1\n %y2 = extractelement <4 x i32> %y, i32 2\n %y3 = extractelement <4 x i32> %y, i32 3\n %d0 = icmp slt i32 %x0, %y0\n %d1 = icmp slt i32 %x1, %y1\n %d2 = icmp slt i32 %x2, %y2\n %d3 = icmp slt i32 %x3, %y3\n %s3 = select i1 %c, i1 %c, i1 false\n %s4 = select i1 %s3, i1 %d0, i1 false\n %s5 = select i1 %s4, i1 %d1, i1 false\n %s6 = select i1 %s5, i1 %d2, i1 false\n %s7 = select i1 %s6, i1 %d3, i1 false\n ret i1 %s7\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "test", "test_body": "define i1 @test(<4 x i32> %x) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 -1\n %x2 = extractelement <4 x i32> %x, i32 2\n %x3 = extractelement <4 x i32> %x, i32 3\n %1 = icmp ugt i32 %x0, 0\n %c1 = icmp slt i32 %x1, 0\n %c2 = icmp sgt i32 %x2, 0\n %c3 = icmp slt i32 %x3, 0\n %s1 = select i1 %1, i1 %c1, i1 false\n %s2 = select i1 %s1, i1 %c3, i1 false\n %s3 = select i1 %s2, i1 %c3, i1 false\n ret i1 %s3\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "wrong folding of `select`s in slp-vectorizer", "body": "Alive2 report: https://alive2.llvm.org/ce/z/jEopx9\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @logical_and_icmp_diff_preds.2(<4 x i32> %x) {\r\n#0:\r\n %x0 = extractelement <4 x i32> %x, i32 0\r\n %x1 = extractelement <4 x i32> %x, i32 4294967295\r\n %x3 = extractelement <4 x i32> %x, i32 3\r\n %#1 = icmp ugt i32 %x0, 0\r\n %c1 = icmp slt i32 %x1, 0\r\n %c3 = icmp slt i32 %x3, 0\r\n %s1 = select i1 %#1, i1 %c1, i1 0\r\n %s2 = select i1 %s1, i1 %c3, i1 0\r\n %s3 = select i1 %s2, i1 %c3, i1 0\r\n ret i1 %s3\r\n}\r\n=>\r\ndefine i1 @logical_and_icmp_diff_preds.2(<4 x i32> %x) {\r\n#0:\r\n %x0 = extractelement <4 x i32> %x, i32 0\r\n %x1 = extractelement <4 x i32> %x, i32 4294967295\r\n %x3 = extractelement <4 x i32> %x, i32 3\r\n %#1 = icmp ugt i32 %x0, 0\r\n %c1 = icmp slt i32 %x1, 0\r\n %c3 = icmp slt i32 %x3, 0\r\n %op.rdx = select i1 %c3, i1 %c1, i1 0\r\n %op.rdx1 = select i1 %op.rdx, i1 %#1, i1 0\r\n ret i1 %op.rdx1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<4 x i32> %x = < #x00000000 (0), #x00000000 (0), #x00000000 (0), #xffffffff (4294967295, -1) >\r\n\r\nSource:\r\ni32 %x0 = #x00000000 (0)\r\ni32 %x1 = poison\r\ni32 %x3 = #xffffffff (4294967295, -1)\r\ni1 %#1 = #x0 (0)\r\ni1 %c1 = poison\r\ni1 %c3 = #x1 (1)\r\ni1 %s1 = #x0 (0)\r\ni1 %s2 = #x0 (0)\r\ni1 %s3 = #x0 (0)\r\n\r\nTarget:\r\ni32 %x0 = #x00000000 (0)\r\ni32 %x1 = poison\r\ni32 %x3 = #xffffffff (4294967295, -1)\r\ni1 %#1 = #x0 (0)\r\ni1 %c1 = poison\r\ni1 %c3 = #x1 (1)\r\ni1 %op.rdx = poison\r\ni1 %op.rdx1 = 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:SLPVectorizer" ], "comments": [ { "author": "nunoplopes", "body": "Alive2 is still not happy with the fix:\n```llvm\ndefine i1 @test(<4 x i32> %x) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 4294967295\n %x3 = extractelement <4 x i32> %x, i32 3\n %#1 = icmp ugt i32 %x0, 0\n %c1 = icmp slt i32 %x1, 0\n %c3 = icmp slt i32 %x3, 0\n %s1 = select i1 %#1, i1 %c1, i1 0\n %s2 = select i1 %s1, i1 %c3, i1 0\n %s3 = select i1 %s2, i1 %c3, i1 0\n ret i1 %s3\n}\n=>\ndefine i1 @test(<4 x i32> %x) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 4294967295\n %x3 = extractelement <4 x i32> %x, i32 3\n %#1 = icmp ugt i32 %x0, 0\n %c1 = icmp slt i32 %x1, 0\n %c3 = icmp slt i32 %x3, 0\n %#2 = freeze i1 %c3\n %op.rdx = select i1 %#2, i1 %c1, i1 0\n %op.rdx1 = select i1 %op.rdx, i1 %#1, i1 0\n ret i1 %op.rdx1\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\n<4 x i32> %x = < #x00000000 (0), poison, poison, #xffffffff (4294967295, -1) >\n\nSource:\ni32 %x0 = #x00000000 (0)\ni32 %x1 = poison\ni32 %x3 = #xffffffff (4294967295, -1)\ni1 %#1 = #x0 (0)\ni1 %c1 = poison\ni1 %c3 = #x1 (1)\ni1 %s1 = #x0 (0)\ni1 %s2 = #x0 (0)\ni1 %s3 = #x0 (0)\n\nTarget:\ni32 %x0 = #x00000000 (0)\ni32 %x1 = poison\ni32 %x3 = #xffffffff (4294967295, -1)\ni1 %#1 = #x0 (0)\ni1 %c1 = poison\ni1 %c3 = #x1 (1)\ni1 %#2 = #x1 (1)\ni1 %op.rdx = poison\ni1 %op.rdx1 = poison\nSource value: #x0 (0)\nTarget value: poison\n```" } ] }
true
null
87798
https://github.com/llvm/llvm-project/issues/87798
crash
49ef12a08c4c7d7ae4765929e72fe2320a12b08c
2024-04-05T16:02:46
[ "llvm/test/Analysis/ScalarEvolution" ]
{ "fix_commit": "54a9f0007cb4f19d2e9df30405c5027229f5def0", "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": [ [ 928, 938 ] ], "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": [ "BinomialCoefficient" ], "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 54a9f0007cb4f19d2e9df30405c5027229f5def0 Author: annamthomas <[email protected]> Date: Wed Apr 10 09:02:23 2024 -0400 [SCEV] Fix BinomialCoefficient Iteration to fit in W bits (#88010) BinomialCoefficient computes the value of W-bit IV at iteration It of a loop. When W is 1, we can call multiplicative inverse on 0 which triggers an assert since 1b76120. Since the arithmetic is supposed to wrap if It or K does not fit in W bits, do the truncation into W bits after we do the shift. Fixes #87798 diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index e030b9fc7dac..9fcce797f559 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -928,11 +928,9 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K, APInt OddFactorial(W, 1); unsigned T = 1; for (unsigned i = 3; i <= K; ++i) { - APInt Mult(W, i); - unsigned TwoFactors = Mult.countr_zero(); + unsigned TwoFactors = countr_zero(i); T += TwoFactors; - Mult.lshrInPlace(TwoFactors); - OddFactorial *= Mult; + OddFactorial *= (i >> TwoFactors); } // We need at least W + T bits for the multiplication step
[ { "file": "llvm/test/Analysis/ScalarEvolution/pr87798.ll", "commands": [ "opt -disable-output -passes='print<scalar-evolution>' -verify-scev < %s 2>&1" ], "tests": [ { "test_name": "pr87798", "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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @pr87798() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %add4, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb1 ]\n %phi3 = phi i32 [ 0, %bb ], [ %add5, %bb1 ]\n %add = add i32 %phi2, %phi3\n %mul = mul i32 %phi2, %phi3\n %add4 = add i32 %mul, %phi\n %and = and i32 %phi, 1\n %add5 = add i32 %phi3, 1\n br i1 true, label %preheader, label %bb1\n\npreheader: ; preds = %bb1\n %phi9 = phi i32 [ %and, %bb1 ]\n br label %loop\n\nloop: ; preds = %loop, %preheader\n br label %loop\n\nbb7: ; No predecessors!\n %zext = zext i32 %phi9 to i64\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion failure: \"multiplicative inverse is only defined for odd numbers\" exposed through usage in SCEV", "body": "With this change [1b76120](https://github.com/llvm/llvm-project/commit/1b761205f2686516cebadbcbc37f798197d9c482) landed in https://github.com/llvm/llvm-project/pull/87610, we started seeing an assertion failure on the introduced API.\r\n\r\nThis change caused an assertion failure in usage of multiplicativeInverse in SCEV's BinomialCoefficient algorithm (which was also updated by the change to use this overloaded API). The `oddFactorial` in this algorithm becomes 0 and the assertion in newly introduced API gets triggered. Note that the old API for multiplicativeInverse (which passed in the explicit modulo) returned 0 when the input was also 0, and probably hid this bug in SCEV. \r\n\r\nHere's a minimal reproducer for trunk:\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-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i32 @\"static jint Test.iMeth(jlong, jint, jint)2272037699586\"() {\r\nbci_0:\r\n br label %bci_71.preheader\r\n\r\nbci_71.preheader: ; preds = %bci_71.preheader, %bci_0\r\n %local_9_242 = phi i32 [ 0, %bci_0 ], [ %1, %bci_71.preheader ]\r\n %local_7_241 = phi i32 [ 0, %bci_0 ], [ %0, %bci_71.preheader ]\r\n %local_4_239 = phi i32 [ 0, %bci_0 ], [ %3, %bci_71.preheader ]\r\n %0 = add i32 %local_7_241, %local_4_239\r\n %.neg14 = mul i32 %local_7_241, %local_4_239\r\n %1 = add i32 %.neg14, %local_9_242\r\n %2 = and i32 %local_9_242, 1\r\n %3 = add i32 %local_4_239, 1\r\n br i1 true, label %bci_10.i38.preheader, label %bci_71.preheader\r\n\r\nbci_10.i38: ; preds = %bci_10.i38.preheader, %bci_10.i38\r\n br label %bci_10.i38\r\n\r\n\"static jlong FuzzerUtils.checkSum(jobject)2306397437964.exit\": ; No predecessors!\r\n %4 = zext i32 %.lcssa596 to i64\r\n ret i32 0\r\n\r\nbci_10.i38.preheader: ; preds = %bci_71.preheader\r\n %.lcssa596 = phi i32 [ %2, %bci_71.preheader ]\r\n br label %bci_10.i38\r\n}\r\n```\r\n\r\nopt -passes=indvars reduced.ll produces:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Support/APInt.cpp:1245: llvm::APInt llvm::APInt::multiplicativeInverse() const: Assertion `(*this)[0] && \"multiplicative inverse is only defined for odd numbers!\"' 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=indvars <source>\r\n #0 0x0000000004cfc568 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cfc568)\r\n #1 0x0000000004cf9cbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7209e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f7209e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f7209e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f7209e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f7209e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f7209e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004bf9eff llvm::APInt::multiplicativeInverse() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4bf9eff)\r\n #9 0x000000000443a4b5 llvm::SCEVAddRecExpr::evaluateAtIteration(llvm::ArrayRef<llvm::SCEV const*>, llvm::SCEV const*, llvm::ScalarEvolution&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443a4b5)\r\n#10 0x000000000443cb4f llvm::ScalarEvolution::computeSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443cb4f)\r\n#11 0x000000000443cfee llvm::ScalarEvolution::getSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443cfee)\r\n#12 0x000000000443c525 llvm::ScalarEvolution::computeSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443c525)\r\n#13 0x000000000443cfee llvm::ScalarEvolution::getSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443cfee)\r\n#14 0x000000000404eca0 llvm::rewriteLoopExitValues(llvm::Loop*, llvm::LoopInfo*, llvm::TargetLibraryInfo*, llvm::ScalarEvolution*, llvm::TargetTransformInfo const*, llvm::SCEVExpander&, llvm::DominatorTree*, llvm::ReplaceExitVal, llvm::SmallVector<llvm::WeakTrackingVH, 16u>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x404eca0)\r\n#15 0x0000000003a10fd8 (anonymous namespace)::IndVarSimplify::run(llvm::Loop*) IndVarSimplify.cpp:0:0\r\n#16 0x0000000003a11c1a llvm::IndVarSimplifyPass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3a11c1a)\r\n#17 0x00000000029ffd4e llvm::detail::PassModel<llvm::Loop, llvm::IndVarSimplifyPass, 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+0x29ffd4e)\r\n#18 0x0000000003aaef56 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+0x3aaef56)\r\n#19 0x0000000003aaf1ee 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+0x3aaf1ee)\r\n#20 0x0000000003ab05d9 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+0x3ab05d9)\r\n...\r\n```", "author": "annamthomas", "labels": [ "llvm:SCEV", "crash" ], "comments": [ { "author": "topperc", "body": "CC @jayfoad " }, { "author": "annamthomas", "body": "I think the old API (multiplicativeInverse when modulo provided) was hiding this bug since multiplicative inverse shouldn't be asked for 0.\r\nAlso, the reason the `oddFactorial` becomes 0 here is because of this:\r\n```\r\n// Calculate K! / 2^T and T; we divide out the factors of two before\r\n // multiplying for calculating K! / 2^T to avoid overflow.\r\n // Other overflow doesn't matter because we only care about the bottom\r\n // W bits of the result.\r\n APInt OddFactorial(W, 1);\r\n unsigned T = 1;\r\n for (unsigned i = 3; i <= K; ++i) {\r\n APInt Mult(W, i);\r\n unsigned TwoFactors = Mult.countr_zero();\r\n T += TwoFactors;\r\n Mult.lshrInPlace(TwoFactors);\r\n OddFactorial *= Mult; \r\n }\r\n ```\r\n\r\nHere, W is one (bit width = 1 and I believe this is the bug) and we are trying to represent Mult=4 in one bit. That makes `Mult` 0 and hence `OddFactorial` 0.\r\n\r\nOne thing we can obviously do is in the newly introduced API, explicitly check if the APInt is 0 and return 0 (this makes behaviour same as the old API).\r\nBut I think this is hiding the bug. " }, { "author": "jayfoad", "body": "Suggestion:\r\n```diff\r\ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\r\nindex e030b9fc7dac..3f8c390614ff 100644\r\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\r\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\r\n@@ -928,11 +928,9 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K,\r\n APInt OddFactorial(W, 1);\r\n unsigned T = 1;\r\n for (unsigned i = 3; i <= K; ++i) {\r\n- APInt Mult(W, i);\r\n- unsigned TwoFactors = Mult.countr_zero();\r\n+ unsigned TwoFactors = countr_zero(i);\r\n T += TwoFactors;\r\n- Mult.lshrInPlace(TwoFactors);\r\n- OddFactorial *= Mult;\r\n+ OddFactorial *= i >> TwoFactors;\r\n }\r\n \r\n // We need at least W + T bits for the multiplication step\r\n```" }, { "author": "annamthomas", "body": "yes, that would probably work as well (since we avoid representing Mult in W bit width), but how can the bitWidth of the SCEV result`W` be 1 in the first place? " }, { "author": "jayfoad", "body": "> yes, that would probably work as well (since we avoid representing Mult in W bit width), but how can the bitWidth of the SCEV result`W` be 1 in the first place?\r\n\r\nNo idea! I have only looked at `BinomialCoefficient` itself, not at its callers. I assume it is supposed to work for any W > 0 and K > 0. At least I don't see it mentioned that K has to be representable in W bits, or anything like that." }, { "author": "efriedma-quic", "body": "The function is supposed to compute `BC(It, K) mod 2^W`, i.e. the binomial coefficient truncated to fit into a W-bit integer. This is useful for computing the value of a W-bit induction variable at iteration \"It\" of a loop. There isn't any expectation that \"It\" or \"K\" fit losslessly into \"W\": the arithmetic is supposed to wrap.\r\n\r\nGiven the way the function works, truncating \"i\" after the shift looks like the right solution." } ] }
true
null
113520
https://github.com/llvm/llvm-project/issues/113520
miscompilation
907c13638819b36ecc5154775217068b1a1f4cfc
2024-10-24T04:03:39
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e914421d7fbf22059ea2180233add0c914ec80f0", "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": [ [ 12068, 12075 ], [ 15784, 15791 ] ], "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::getTreeCost", "BoUpSLP::vectorizeTree" ], "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 e914421d7fbf22059ea2180233add0c914ec80f0 Author: Alexey Bataev <[email protected]> Date: Thu Oct 24 08:57:07 2024 -0700 [SLP]Do correct signedness analysis for externally used scalars If the scalars is used externally is in the root node, it may have incorrect signedness info because of the conflict with the demanded bits analysis. Need to perform exact signedness analysis and compute it rather than rely on the precomputed value, which might be incorrect for alternate zext/sext nodes. Fixes #113520 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 012d85353f08..2afd02dae3a8 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -12068,8 +12068,9 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { auto It = MinBWs.find(Entry); if (It != MinBWs.end()) { auto *MinTy = IntegerType::get(F->getContext(), It->second.first); - unsigned Extend = - It->second.second ? Instruction::SExt : Instruction::ZExt; + unsigned Extend = isKnownNonNegative(EU.Scalar, SimplifyQuery(*DL)) + ? Instruction::ZExt + : Instruction::SExt; VecTy = getWidenedType(MinTy, BundleWidth); ExtraCost = TTI->getExtractWithExtendCost(Extend, EU.Scalar->getType(), VecTy, EU.Lane); @@ -15784,8 +15785,9 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, // to the larger type. ExV = Ex; if (Scalar->getType() != Ex->getType()) - ExV = Builder.CreateIntCast(Ex, Scalar->getType(), - MinBWs.find(E)->second.second); + ExV = Builder.CreateIntCast( + Ex, Scalar->getType(), + !isKnownNonNegative(Scalar, SimplifyQuery(*DL))); auto *I = dyn_cast<Instruction>(Ex); ScalarToEEs[Scalar].try_emplace(I ? I->getParent() : &F->getEntryBlock(),
[ { "file": "<issue>", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "add3_i96", "test_body": "@0 = external global i1\n\ndefine <3 x i32> @add3_i96.2(<3 x i32> %0, <3 x i32> %1) {\n %4 = extractelement <3 x i32> %0, i64 0\n %5 = sext i32 %4 to i64\n %6 = extractelement <3 x i32> %1, i64 0\n %7 = zext i32 %6 to i64\n %8 = add nuw nsw i64 %7, %5\n %9 = extractelement <3 x i32> %0, i64 1\n %10 = zext i32 %9 to i64\n %11 = extractelement <3 x i32> %1, i64 1\n %12 = zext i32 %11 to i64\n %13 = add nuw nsw i64 %12, %10\n %14 = lshr i64 %8, 32\n %15 = add nuw nsw i64 %13, %14\n %16 = extractelement <3 x i32> %0, i64 2\n %17 = extractelement <3 x i32> %1, i64 2\n %18 = add i32 %17, %16\n %19 = or i64 %15, 32\n %20 = trunc i64 %19 to i32\n %21 = add i32 %18, %17\n %22 = trunc i64 %8 to i32\n %23 = insertelement <3 x i32> %1, i32 %22, i32 0\n ret <3 x i32> %23\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "`slp-vectorizer` miscompilation", "body": "Alive2 report: https://alive2.llvm.org/ce/z/FmxNvP\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <3 x i32> @add3_i96.2(<3 x i32> %#0, <3 x i32> %#1) {\r\n#2:\r\n %#3 = extractelement <3 x i32> %#0, i64 0\r\n %#4 = sext i32 %#3 to i64\r\n %#5 = extractelement <3 x i32> %#1, i64 0\r\n %#6 = zext i32 %#5 to i64\r\n %#7 = add nsw nuw i64 %#6, %#4\r\n %#21 = trunc i64 %#7 to i32\r\n %#22 = insertelement <3 x i32> %#1, i32 %#21, i32 0\r\n ret <3 x i32> %#22\r\n}\r\n=>\r\ndefine <3 x i32> @add3_i96.2(<3 x i32> %#0, <3 x i32> %#1) {\r\n#2:\r\n %#3 = shufflevector <3 x i32> %#1, <3 x i32> %#0, 0, 3\r\n %#4 = extractelement <2 x i32> %#3, i32 0\r\n %#5 = sext i32 %#4 to i64\r\n %#6 = extractelement <2 x i32> %#3, i32 1\r\n %#7 = sext i32 %#6 to i64\r\n %#8 = add nsw nuw i64 %#5, %#7\r\n %#22 = trunc i64 %#8 to i32\r\n %#23 = insertelement <3 x i32> %#1, i32 %#22, i32 0\r\n ret <3 x i32> %#23\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<3 x i32> %#0 = < #x00000008 (8), #x00000000 (0), #x00000000 (0) >\r\n<3 x i32> %#1 = < #xfffffff9 (4294967289, -7), #x00000000 (0), #x00000000 (0) >\r\n\r\nSource:\r\ni32 %#3 = #x00000008 (8)\r\ni64 %#4 = #x0000000000000008 (8)\r\ni32 %#5 = #xfffffff9 (4294967289, -7)\r\ni64 %#6 = #x00000000fffffff9 (4294967289)\r\ni64 %#7 = #x0000000100000001 (4294967297)\r\ni32 %#21 = #x00000001 (1)\r\n<3 x i32> %#22 = < #x00000001 (1), #x00000000 (0), #x00000000 (0) >\r\n\r\nTarget:\r\n<2 x i32> %#3 = < #xfffffff9 (4294967289, -7), #x00000008 (8) >\r\ni32 %#4 = #xfffffff9 (4294967289, -7)\r\ni64 %#5 = #xfffffffffffffff9 (18446744073709551609, -7)\r\ni32 %#6 = #x00000008 (8)\r\ni64 %#7 = #x0000000000000008 (8)\r\ni64 %#8 = poison\r\ni32 %#22 = poison\r\n<3 x i32> %#23 = < poison, #x00000000 (0), #x00000000 (0) >\r\nSource value: < #x00000001 (1), #x00000000 (0), #x00000000 (0) >\r\nTarget value: < poison, #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\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [] }
true
null
137152
https://github.com/llvm/llvm-project/issues/137152
crash
224cd50e005a9215e8c528d5ce68d4fcdfcdb98f
2025-04-24T10:47:46
[ "llvm/test/Transforms/GlobalOpt" ]
{ "fix_commit": "57530c23a53b5e003d389437637f61c5b9814e22", "components": [ "GlobalOpt" ], "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": 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": [ [ 719, 728 ] ], "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": 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": [ "allUsesOfLoadedValueWillTrapIfNull" ], "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 57530c23a53b5e003d389437637f61c5b9814e22 Author: Nikita Popov <[email protected]> Date: Thu Apr 24 15:15:47 2025 +0200 [GlobalOpt] Do not promote malloc if there are atomic loads/stores (#137158) When converting a malloc stored to a global into a global, we will introduce an i1 flag to track whether the global has been initialized. In case of atomic loads/stores, this will result in verifier failures, because atomic ops on i1 are illegal. Even if we changed this to i8, I don't think it is a good idea to change atomic types in that way. Instead, bail out of the transform is we encounter any atomic loads/stores of the global. Fixes https://github.com/llvm/llvm-project/issues/137152. diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index cfba8dcc05b2..3771cccbde17 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -719,10 +719,14 @@ static bool allUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) { const Value *P = Worklist.pop_back_val(); for (const auto *U : P->users()) { if (auto *LI = dyn_cast<LoadInst>(U)) { + if (!LI->isSimple()) + return false; SmallPtrSet<const PHINode *, 8> PHIs; if (!AllUsesOfValueWillTrapIfNull(LI, PHIs)) return false; } else if (auto *SI = dyn_cast<StoreInst>(U)) { + if (!SI->isSimple()) + return false; // Ignore stores to the global. if (SI->getPointerOperand() != P) return false;
[ { "file": "llvm/test/Transforms/GlobalOpt/malloc-promote-atomic.ll", "commands": [ "opt -passes=globalopt -S < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@g = internal global ptr null, align 8\n\ndefine void @init() {\n;\n %alloc = call ptr @malloc(i64 48)\n store atomic ptr %alloc, ptr @g seq_cst, align 8\n ret void\n}\n\ndefine i1 @check() {\n;\n %val = load atomic ptr, ptr @g seq_cst, align 8\n %cmp = icmp eq ptr %val, null\n ret i1 %cmp\n}\n\ndeclare ptr @malloc(i64) allockind(\"alloc,uninitialized\") allocsize(0)", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[GlobalOpt] Incorrect change of atomic type", "body": "```llvm\n; RUN: opt -S -passes=globalopt\n@g = internal global ptr null, align 8\n\ndefine void @init() {\n %alloc = call ptr @malloc(i64 48)\n store atomic ptr %alloc, ptr @g seq_cst, align 8\n ret void\n} \n\ndefine i1 @check() {\n %val = load atomic ptr, ptr @g seq_cst, align 8\n %cmp = icmp eq ptr %val, null\n ret i1 %cmp\n}\n\ndeclare ptr @malloc(i64) allockind(\"alloc,uninitialized\") allocsize(0)\n```\nResults in:\n```\natomic memory access' size must be byte-sized\n i1 store atomic i1 true, ptr @g.init seq_cst, align 1\natomic memory access' size must be byte-sized\n i1 %g.init.val = load atomic i1, ptr @g.init seq_cst, align 1\nLLVM ERROR: Broken module found, compilation aborted!\n```\n", "author": "nikic", "labels": [ "ipo", "release:backport", "crash" ], "comments": [] }
true
null
108697
https://github.com/llvm/llvm-project/issues/108697
crash
848cb21ddca5dc4d8c52e487264936be8f1bfe8d
2024-09-14T13:01:28
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "9de327c94d0c995803b6485fb28ac4cad1e53bbe", "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": [ [ 6551, 6564 ] ], "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 9de327c94d0c995803b6485fb28ac4cad1e53bbe Author: Florian Hahn <[email protected]> Date: Wed Oct 2 20:16:41 2024 +0100 [LV] Generalize predication checks from 2c8836c899 for operands. This fixes another case where the VPlan-based and legacy cost models disagree. If any of the operands is predicated, it can't be trivially hoisted and we should consider the cost for evaluating it each loop iteration. Fixes https://github.com/llvm/llvm-project/issues/108697. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index de3b981a4fe3..6e082b1c134d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6551,14 +6551,17 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, Op2 = cast<SCEVConstant>(PSE.getSCEV(Op2))->getValue(); } auto Op2Info = TTI.getOperandInfo(Op2); - auto IsInvariant = [this](Value *Op) { + std::function<bool(Value *)> IsInvariant = + [this, &IsInvariant](Value *Op) -> bool { if (!Legal->isInvariant(Op)) return false; - // Consider Op2 invariant, if it is not a predicated instruction in the - // loop. In that case, it is not trivially hoistable. + // Consider Op2invariant, if it or its operands aren't predicated + // instruction in the loop. In that case, it is not trivially hoistable. return !isa<Instruction>(Op) || !TheLoop->contains(cast<Instruction>(Op)) || - !isPredicatedInst(cast<Instruction>(Op)); + (!isPredicatedInst(cast<Instruction>(Op)) && + all_of(cast<Instruction>(Op)->operands(), + [&IsInvariant](Value *Op) { return IsInvariant(Op); })); }; if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue && IsInvariant(Op2)) Op2Info.Kind = TargetTransformInfo::OK_UniformValue;
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/predicated-instruction-cost.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "predicated_urem_shl_cost", "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 @predicated_urem_shl_cost(ptr %A, i32 %x, i1 %c) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop.latch ]\n %gep = getelementptr inbounds i32, ptr %A, i32 %iv\n %l = load i32, ptr %gep, align 4\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %rem = urem i32 2, %x\n %shl = shl i32 %l, %rem\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i32 [ 0, %loop.header ], [ %shl, %then ]\n store i32 %p, ptr %gep, align 4\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 0\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_wide_shift_uses_predicated_invariant_instruction", "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 @test_wide_shift_uses_predicated_invariant_instruction(i32 %d, i1 %c, ptr %dst) {\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 %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %rem = urem i32 100, %d\n %sext = shl i32 %rem, 12\n %shl.i = shl i32 999, %sext\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %p = phi i32 [ %shl.i, %else ], [ 0, %loop.header ]\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %p, ptr %gep, align 4\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv.next, 100\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "clang crashes on valid code at -O{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": "Compiler Explorer: https://godbolt.org/z/9K4a3Pr7j\r\n\r\n```\r\n[508] % 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[509] % \r\n[509] % clangtk -O2 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7390: 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.\tProgram arguments: /local/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/20240914-clangtk-m64-O3-build-061621/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240914-clangtk-m64-O3-build-061621/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/20/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 -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-34578e.o -x c small.c\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\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\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000055ba1845c4ff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x43484ff)\r\n #1 0x000055ba18459a34 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fbbfabd4420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007fbbfa60b00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007fbbfa5ea859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007fbbfa5ea729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007fbbfa5ea729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007fbbfa5fbfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x000055ba19db5fcb llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5ca1fcb)\r\n #9 0x000055ba19dd169a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5cbd69a)\r\n#10 0x000055ba19dd42d1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5cc02d1)\r\n#11 0x000055ba19dd4943 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5cc0943)\r\n#12 0x000055ba19946a06 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5832a06)\r\n#13 0x000055ba17dec0d1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3cd80d1)\r\n#14 0x000055ba15926546 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-20+0x1812546)\r\n#15 0x000055ba17deaa3d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3cd6a3d)\r\n#16 0x000055ba15925216 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-20+0x1811216)\r\n#17 0x000055ba17dea471 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3cd6471)\r\n#18 0x000055ba18713673 (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 0x000055ba187167f8 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/suz-local/software/local/clang-trunk/bin/clang-20+0x46027f8)\r\n#20 0x000055ba18decf5c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4cd8f5c)\r\n#21 0x000055ba1ac8966c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6b7566c)\r\n#22 0x000055ba18ded378 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4cd9378)\r\n#23 0x000055ba1908a659 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4f76659)\r\n#24 0x000055ba1900c07e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4ef807e)\r\n#25 0x000055ba191772b6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x50632b6)\r\n#26 0x000055ba154f2b15 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13deb15)\r\n#27 0x000055ba154ebbba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x000055ba154ef58e clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13db58e)\r\n#29 0x000055ba153dd43b main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x12c943b)\r\n#30 0x00007fbbfa5ec083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x000055ba154eb64e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13d764e)\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 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\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-682958.c\r\nclangtk: note: diagnostic msg: /tmp/small-682958.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[510] % \r\n[510] % cat small.c\r\nshort a, b, c, d;\r\nunsigned short e;\r\nint main() {\r\n for (; d; d++) {\r\n e = a + b;\r\n c = b > 3 || e > b ? e : e << b;\r\n c = c ? 2 / c : 0;\r\n b = 1;\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [] }
true
null
122691
https://github.com/llvm/llvm-project/issues/122691
crash
26e13091ea5ac3a53d11b50265a506f88129d6ff
2025-01-13T11:28:13
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "092d6283838dea79670750b9415955c5f0cb5178", "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": [ [ 8091, 8096 ], [ 17818, 17824 ] ], "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::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 092d6283838dea79670750b9415955c5f0cb5178 Author: Alexey Bataev <[email protected]> Date: Mon Jan 13 09:02:56 2025 -0800 [SLP]Check for div/rem instructions before extending with poisons Need to check if the instructions can be safely extended with poison before actually doing this to avoid incorrect transformations. Fixes #122691 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index df46c69ff3ab..4b0ed5b30179 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -8091,6 +8091,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, NonUniqueValueVL.append( PWSz - UniqueValues.size(), PoisonValue::get(UniqueValues.front()->getType())); + // Check that extended with poisons operations are still valid for + // vectorization (div/rem are not allowed). + if (!getSameOpcode(NonUniqueValueVL, *TLI).valid()) { + LLVM_DEBUG(dbgs() << "SLP: Scalar used twice in bundle.\n"); + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx); + return false; + } VL = NonUniqueValueVL; } return true; @@ -17818,7 +17825,7 @@ bool BoUpSLP::collectValuesToDemote( }; if (E.isGather() || !Visited.insert(&E).second || any_of(E.Scalars, [&](Value *V) { - return all_of(V->users(), [&](User *U) { + return !isa<PoisonValue>(V) && all_of(V->users(), [&](User *U) { return isa<InsertElementInst>(U) && !getTreeEntry(U); }); }))
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/div-possibly-extended-with-poisons.ll", "commands": [ "opt -S -O2 < %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\n@g_3 = internal unnamed_addr global i64 0\n@g_127 = external local_unnamed_addr global [3 x i32]\n@g_211 = external local_unnamed_addr global i32\n\ndefine i8 @func_125() {\nentry:\n %call42 = call ptr @func_178()\n ret i8 0\n}\n\ndefine ptr @func_178() {\nentry:\n %0 = load i32, ptr @g_211, align 4\n %tobool158.not = icmp eq i32 %0, 0\n br i1 %tobool158.not, label %for.inc434, label %for.cond166.preheader\n\nfor.cond166.preheader: ; preds = %entry\n br label %for.cond166\n\nfor.cond166: ; preds = %for.cond166.preheader, %for.cond166\n %1 = phi i64 [ %2, %for.cond166 ], [ poison, %for.cond166.preheader ]\n %2 = phi i64 [ %inc255, %for.cond166 ], [ 0, %for.cond166.preheader ]\n %cmp167 = icmp samesign ult i64 %2, 61\n %inc255 = add nuw nsw i64 %2, 1\n br i1 %cmp167, label %for.cond166, label %for.inc434.loopexit\n\nfor.inc434.loopexit: ; preds = %for.cond166\n %.lcssa = phi i64 [ %1, %for.cond166 ]\n store i64 %.lcssa, ptr @g_3, align 8\n br label %for.inc434\n\nfor.inc434: ; preds = %for.inc434.loopexit, %entry\n store i32 1, ptr @g_211, align 4\n %3 = load i64, ptr @g_3, align 8\n %conv.i = trunc nuw nsw i64 %3 to i32\n %4 = load i32, ptr @g_127, align 4\n %and.i = and i32 %4, %conv.i\n %cmp.i = icmp eq i32 %and.i, 0\n %conv8.i = sext i32 %and.i to i64\n %sext = shl i64 %3, 32\n %conv9.i = ashr exact i64 %sext, 32\n %g_211.promoted5 = load i32, ptr @g_211, align 4\n br label %for.body447\n\nfor.body447: ; preds = %for.inc434, %cleanup552\n %p_181.addr.08 = phi i64 [ -13, %for.inc434 ], [ %conv564, %cleanup552 ]\n %and14.i1.lcssa67 = phi i32 [ %g_211.promoted5, %for.inc434 ], [ %and14.i.lcssa, %cleanup552 ]\n br label %if.then489\n\nif.then489: ; preds = %for.body447, %safe_div_func_int64_t_s_s.exit\n %l_317.03 = phi i32 [ 2, %for.body447 ], [ %sub, %safe_div_func_int64_t_s_s.exit ]\n %and14.i12 = phi i32 [ %and14.i1.lcssa67, %for.body447 ], [ %and14.i, %safe_div_func_int64_t_s_s.exit ]\n br i1 %cmp.i, label %safe_div_func_int64_t_s_s.exit, label %lor.lhs.false.i\n\nlor.lhs.false.i: ; preds = %if.then489\n %div.i = sdiv i64 %conv8.i, %conv9.i\n %5 = trunc i64 %div.i to i16\n br label %safe_div_func_int64_t_s_s.exit\n\nsafe_div_func_int64_t_s_s.exit: ; preds = %lor.lhs.false.i, %if.then489\n %cond.i = phi i16 [ %5, %lor.lhs.false.i ], [ 0, %if.then489 ]\n %call12.i = tail call i16 @llvm.bswap.i16(i16 %cond.i)\n %conv13.i = zext i16 %call12.i to i32\n %and14.i = and i32 %and14.i12, %conv13.i\n %call26.i = load volatile ptr, ptr null, align 8\n %sub = add nsw i32 %l_317.03, -1\n %cmp482 = icmp sgt i32 %l_317.03, 0\n br i1 %cmp482, label %if.then489, label %cleanup552\n\ncleanup552: ; preds = %safe_div_func_int64_t_s_s.exit\n %and14.i.lcssa = phi i32 [ %and14.i, %safe_div_func_int64_t_s_s.exit ]\n %add.i = add nsw i64 %p_181.addr.08, 7\n %conv564 = and i64 %add.i, 255\n %6 = and i64 %p_181.addr.08, 255\n %cmp445.not = icmp eq i64 %6, 22\n br i1 %cmp445.not, label %for.end565, label %for.body447\n\nfor.end565: ; preds = %cleanup552\n %and14.i.lcssa.lcssa = phi i32 [ %and14.i.lcssa, %cleanup552 ]\n store i32 %conv.i, ptr getelementptr inbounds nuw (i8, ptr @g_127, i64 8), align 4\n store i32 %and14.i.lcssa.lcssa, ptr @g_211, align 4\n ret ptr null\n}\n\ndefine ptr @func_183(i64 %p_185) {\nentry:\n %call = call i64 @builtin_uaddl_overflow(i64 %p_185, i64 0)\n unreachable\n}\n\ndefine i64 @builtin_uaddl_overflow(i64 %x, i64 %y) {\nentry:\n %0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x, i64 %y)\n %1 = extractvalue { i64, i1 } %0, 1\n %conv = zext i1 %1 to i64\n ret i64 %conv\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.", "body": "Reproducer: https://godbolt.org/z/68MKbnE4W\n```\n; bin/opt -O2 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\n@g_3 = internal unnamed_addr global i64 0\n@g_127 = external local_unnamed_addr global [3 x i32]\n@g_211 = external local_unnamed_addr global i32\n\ndefine i8 @func_125() {\nentry:\n %call42 = call ptr @func_178()\n ret i8 0\n}\n\ndefine ptr @func_178() {\nentry:\n %0 = load i32, ptr @g_211, align 4\n %tobool158.not = icmp eq i32 %0, 0\n br i1 %tobool158.not, label %for.inc434, label %for.cond166.preheader\n\nfor.cond166.preheader: ; preds = %entry\n br label %for.cond166\n\nfor.cond166: ; preds = %for.cond166.preheader, %for.cond166\n %1 = phi i64 [ %2, %for.cond166 ], [ poison, %for.cond166.preheader ]\n %2 = phi i64 [ %inc255, %for.cond166 ], [ 0, %for.cond166.preheader ]\n %cmp167 = icmp samesign ult i64 %2, 61\n %inc255 = add nuw nsw i64 %2, 1\n br i1 %cmp167, label %for.cond166, label %for.inc434.loopexit\n\nfor.inc434.loopexit: ; preds = %for.cond166\n %.lcssa = phi i64 [ %1, %for.cond166 ]\n store i64 %.lcssa, ptr @g_3, align 8\n br label %for.inc434\n\nfor.inc434: ; preds = %for.inc434.loopexit, %entry\n store i32 1, ptr @g_211, align 4\n %3 = load i64, ptr @g_3, align 8\n %conv.i = trunc nuw nsw i64 %3 to i32\n %4 = load i32, ptr @g_127, align 4\n %and.i = and i32 %4, %conv.i\n %cmp.i = icmp eq i32 %and.i, 0\n %conv8.i = sext i32 %and.i to i64\n %sext = shl i64 %3, 32\n %conv9.i = ashr exact i64 %sext, 32\n %g_211.promoted5 = load i32, ptr @g_211, align 4\n br label %for.body447\n\nfor.body447: ; preds = %for.inc434, %cleanup552\n %p_181.addr.08 = phi i64 [ -13, %for.inc434 ], [ %conv564, %cleanup552 ]\n %and14.i1.lcssa67 = phi i32 [ %g_211.promoted5, %for.inc434 ], [ %and14.i.lcssa, %cleanup552 ]\n br label %if.then489\n\nif.then489: ; preds = %for.body447, %safe_div_func_int64_t_s_s.exit\n %l_317.03 = phi i32 [ 2, %for.body447 ], [ %sub, %safe_div_func_int64_t_s_s.exit ]\n %and14.i12 = phi i32 [ %and14.i1.lcssa67, %for.body447 ], [ %and14.i, %safe_div_func_int64_t_s_s.exit ]\n br i1 %cmp.i, label %safe_div_func_int64_t_s_s.exit, label %lor.lhs.false.i\n\nlor.lhs.false.i: ; preds = %if.then489\n %div.i = sdiv i64 %conv8.i, %conv9.i\n %5 = trunc i64 %div.i to i16\n br label %safe_div_func_int64_t_s_s.exit\n\nsafe_div_func_int64_t_s_s.exit: ; preds = %lor.lhs.false.i, %if.then489\n %cond.i = phi i16 [ %5, %lor.lhs.false.i ], [ 0, %if.then489 ]\n %call12.i = tail call i16 @llvm.bswap.i16(i16 %cond.i)\n %conv13.i = zext i16 %call12.i to i32\n %and14.i = and i32 %and14.i12, %conv13.i\n %call26.i = load volatile ptr, ptr null, align 8\n %sub = add nsw i32 %l_317.03, -1\n %cmp482 = icmp sgt i32 %l_317.03, 0\n br i1 %cmp482, label %if.then489, label %cleanup552\n\ncleanup552: ; preds = %safe_div_func_int64_t_s_s.exit\n %and14.i.lcssa = phi i32 [ %and14.i, %safe_div_func_int64_t_s_s.exit ]\n %add.i = add nsw i64 %p_181.addr.08, 7\n %conv564 = and i64 %add.i, 255\n %6 = and i64 %p_181.addr.08, 255\n %cmp445.not = icmp eq i64 %6, 22\n br i1 %cmp445.not, label %for.end565, label %for.body447\n\nfor.end565: ; preds = %cleanup552\n %and14.i.lcssa.lcssa = phi i32 [ %and14.i.lcssa, %cleanup552 ]\n store i32 %conv.i, ptr getelementptr inbounds nuw (i8, ptr @g_127, i64 8), align 4\n store i32 %and14.i.lcssa.lcssa, ptr @g_211, align 4\n ret ptr null\n}\n\ndefine ptr @func_183(i64 %p_185) {\nentry:\n %call = call i64 @builtin_uaddl_overflow(i64 %p_185, i64 0)\n unreachable\n}\n\ndefine i64 @builtin_uaddl_overflow(i64 %x, i64 %y) {\nentry:\n %0 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %x, i64 %y)\n %1 = extractvalue { i64, i1 } %0, 1\n %conv = zext i1 %1 to i64\n ret i64 %conv\n}\n```\n```\nopt: /root/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.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -O2 <source>\n1.\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>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"func_125\"\n #0 0x00000000052803a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52803a8)\n #1 0x000000000527ddac SignalHandler(int) Signals.cpp:0:0\n #2 0x0000776446c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x0000776446c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x0000776446c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x0000776446c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x0000776446c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x0000776446c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x0000000000b6a41a (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xb6a41a)\n #9 0x0000000004253c98 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>>&, llvm::SmallDenseSet<unsigned int, 8u, llvm::DenseMapInfo<unsigned int, void>> const&, unsigned int&, bool&, bool) const::'lambda10'(unsigned int, unsigned int)::operator()(unsigned int, unsigned int) const::'lambda'(llvm::Value*)::operator()(llvm::Value*) const SLPVectorizer.cpp:0:0\n#10 0x0000000004253f67 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>>&, llvm::SmallDenseSet<unsigned int, 8u, llvm::DenseMapInfo<unsigned int, void>> const&, unsigned int&, bool&, bool) const::'lambda10'(unsigned int, unsigned int)>(long, unsigned int, unsigned int) SLPVectorizer.cpp:0:0\n#11 0x00000000042e2312 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>>&, llvm::SmallDenseSet<unsigned int, 8u, llvm::DenseMapInfo<unsigned int, void>> const&, 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#12 0x00000000042deacb 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>>&, llvm::SmallDenseSet<unsigned int, 8u, llvm::DenseMapInfo<unsigned int, void>> const&, unsigned int&, bool&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42deacb)\n#13 0x00000000042df8a0 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#14 0x00000000042e03d0 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42e03d0)\n#15 0x000000000431e02d (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#16 0x000000000432015d llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x432015d)\n#17 0x000000000432494b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x000000000432904f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x432904f)\n#19 0x000000000432fa86 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 0x00000000043305bb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43305bb)\n#21 0x0000000003036f1e 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+0x3036f1e)\n#22 0x000000000507d7f0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x507d7f0)\n#23 0x0000000000e7023e 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+0xe7023e)\n#24 0x000000000507c10b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x507c10b)\n#25 0x0000000000e6f8ce 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+0xe6f8ce)\n#26 0x000000000507bb10 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x507bb10)\n#27 0x000000000094448a 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+0x94448a)\n#28 0x0000000000936a29 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x936a29)\n#29 0x0000776446c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#30 0x0000776446c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#31 0x000000000092e305 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92e305)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n\nllvm version: 7e01a322f850e86be9eefde8ae5a30e532d22cfa\nI am working to provide a single-pass reproducer.\n", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Missing poison check: https://github.com/llvm/llvm-project/blob/6c5941b09fca487efc5000c82bbce6054bf36a7c/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L18000\n" }, { "author": "dtcxzyw", "body": "> I am working to provide a single-pass reproducer.\n\nIt is weird that the single-pass reproducer doesn't work even with `--preserve-ll-uselistorder`.\n" } ] }
true
null
82052
https://github.com/llvm/llvm-project/issues/82052
miscompilation
a45df47375e50914900dcc07abd2fa67bfa0dd3b
2024-02-16T22:14:29
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "d2a26a7bd5fc7cc5752337b7f4f999642feb37dc", "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": [ [ 1870, 1883 ] ], "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::SimplifyDemandedVectorElts" ], "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 d2a26a7bd5fc7cc5752337b7f4f999642feb37dc Author: Antonio Frighetto <[email protected]> Date: Sun Feb 18 18:10:41 2024 +0100 [InstCombine] Do not perform binop-of-shuffle when mask is poison A miscompilation issue has been addressed with refined checking. Shuffle masks operand may be turned into `poison` if this does not lead to observable changes. This however may not guarantee binop to binop-of-shuffle replacement to be sound anymore. Fixes: https://github.com/llvm/llvm-project/issues/82052. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 5f13454089e5..97ae980a7cba 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -1870,14 +1870,16 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V, Value *ShufOp = MatchShufAsOp0 ? X : Y; Value *OtherOp = MatchShufAsOp0 ? Y : X; for (User *U : OtherOp->users()) { - auto Shuf = m_Shuffle(m_Specific(ShufOp), m_Value(), m_ZeroMask()); + ArrayRef<int> Mask; + auto Shuf = m_Shuffle(m_Specific(ShufOp), m_Value(), m_Mask(Mask)); if (BO->isCommutative() ? match(U, m_c_BinOp(Opcode, Shuf, m_Specific(OtherOp))) : MatchShufAsOp0 ? match(U, m_BinOp(Opcode, Shuf, m_Specific(OtherOp))) : match(U, m_BinOp(Opcode, m_Specific(OtherOp), Shuf))) - if (DT.dominates(U, I)) - return U; + if (match(Mask, m_ZeroMask()) && Mask[0] != PoisonMaskElem) + if (DT.dominates(U, I)) + return U; } return nullptr; };
[ { "file": "llvm/test/Transforms/InstCombine/vec_demanded_elts.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "common_binop_demand_via_extelt_op0_mismatch_elt1", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndeclare void @use(<2 x i4>)\n\ndefine i4 @common_binop_demand_via_extelt_op0_mismatch_elt1(<2 x i4> %x, <2 x i4> %y) {\n %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer\n %b_xshuf_y = sub <2 x i4> %xshuf, %y\n %b_xy = sub nsw <2 x i4> %x, %y\n %b_xy0 = extractelement <2 x i4> %b_xy, i32 1\n call void @use(<2 x i4> %b_xshuf_y)\n ret i4 %b_xy0\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "common_binop_demand_via_splat_mask_poison", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine <2 x i8> @common_binop_demand_via_splat_mask_poison(<2 x i8> %x, <2 x i8> %y) {\n %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 0, i32 poison>\n %vv = add <2 x i8> %x, %ysplat\n %m = add <2 x i8> %x, %y\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> zeroinitializer\n %res = add <2 x i8> %vv, %msplat\n ret <2 x i8> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "common_binop_demand_via_splat_mask_poison_2", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine <2 x i8> @common_binop_demand_via_splat_mask_poison_2(<2 x i8> %x, <2 x i8> %y) {\n %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\n %vv = add <2 x i8> %x, %ysplat\n %m = add <2 x i8> %x, %y\n %msplat = shufflevector <2 x i8> %m, <2 x i8> %y, <2 x i32> <i32 0, i32 2>\n %res = add <2 x i8> %vv, %msplat\n ret <2 x i8> %res\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "common_binop_demand_via_splat_mask_poison_3", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine <2 x i8> @common_binop_demand_via_splat_mask_poison_3(<2 x i8> %x, <2 x i8> %y) {\n %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\n %vv = add <2 x i8> %x, %ysplat\n %m = add <2 x i8> %x, %y\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> zeroinitializer\n %res = add <2 x i8> %vv, %msplat\n ret <2 x i8> %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] Replacement of binop with binop-of-shuffle incorrectly adds extra poison value", "body": "The following IR is a minimal repro when run with `opt -passes=instcombine`:\r\n```llvm\r\ndefine i8 @src(<2 x i8> %x, <2 x i8> %y) {\r\n %xsplat = shufflevector <2 x i8> %x, <2 x i8> poison, <2 x i32> <i32 1, i32 0>\r\n %vv = mul <2 x i8> %xsplat, %y\r\n %m = mul <2 x i8> %x, %y ; <<<< Note that %m is later replaced with %vv in the output\r\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 0, i32 0>\r\n %res = add <2 x i8> %vv, %msplat\r\n %vget_lane = extractelement <2 x i8> %res, i64 1\r\n ret i8 %vget_lane\r\n}\r\n```\r\nWhich on 17.x or trunk will give:\r\n```llvm\r\ndefine i8 @src(<2 x i8> %x, <2 x i8> %y) {\r\n %xsplat = shufflevector <2 x i8> %x, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %vv = mul <2 x i8> %xsplat, %y\r\n %msplat = shufflevector <2 x i8> %vv, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %res = add <2 x i8> %vv, %msplat\r\n %vget_lane = extractelement <2 x i8> %res, i64 1\r\n ret i8 %vget_lane\r\n}\r\n```\r\nHowever, this is not correct, because the added poisoned values end up observed in the final output. First, in InstCombine, the first element in each mask for the shuffles are first replaced with `poison` due to not being observed in the final `extractelement`. After that we run into this code in `InstCombineSimplifyDemanded.cpp`:\r\nhttps://github.com/llvm/llvm-project/blob/d8278b682386f51dfba204849c624672a3df40c7/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L1866-L1880\r\n\r\nThis is what replaces the `mul <2 x i8> %x, %y` with `mul <2 x i8> %xsplat, %y` (`m_ZeroMask` also matches poison). However in doing so, it introduces the extra poison from `%xsplat`, meaning that `%msplat` has both its elements poisoned, which ends up propagating to `%vget_lane`.\r\n\r\nHere is a Godbolt link showing the test case on 16.x, 17.x, and trunk:\r\nhttps://godbolt.org/z/5eeT7x4s3\r\n\r\nAnd also an Alive2 example showing the bad transformation with a counter-example:\r\nhttps://alive2.llvm.org/ce/z/RpBJEN\r\n\r\nThe code was first introduced in 3b090ff2bdb2828b53d6fec9c06b9d52fed09f42, which a bisect shows is when this first started repro'ing\r\n\r\nI have verified that this still repros on latest trunk, 2de269a641e4ffbb7a44e559c4c0a91bb66df823\r\n\r\nFor priority/triage: this bug was found by a fuzzer meant to test SIMD codegen. It was not from manually written code", "author": "Benjins", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "Benjins", "body": "A slightly smaller test case:\r\nhttps://alive2.llvm.org/ce/z/6AMPWC\r\n```llvm\r\ndefine <2 x i8> @src(<2 x i8> %x, <2 x i8> %y) {\r\n %xsplat = shufflevector <2 x i8> %x, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %vv = mul <2 x i8> %xsplat, %y\r\n %m = mul <2 x i8> %x, %y\r\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %res = add <2 x i8> %vv, %msplat\r\n ret <2 x i8> %res\r\n}\r\n```\r\nThis doesn't extract the vector, and instead manually specifies the poisonous elements in the shuffles. As Alive notes, the output for `src(<0, 0>, <0, 0>)` goes from `<poison, 0>` to `<poison, poison>`" } ] }
true
null
124387
https://github.com/llvm/llvm-project/issues/124387
miscompilation
77c325b646301e394bcd89c2980b4c2da8af49cd
2025-01-25T03:24:37
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "2131115be5b9d8b39af80973d9b64c0adc41d38d", "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": [ [ 1039, 1049 ] ], "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 2131115be5b9d8b39af80973d9b64c0adc41d38d Author: Fangrui Song <[email protected]> Date: Sat Jan 25 13:35:11 2025 -0800 [InstCombine] Drop Range attribute when simplifying 'fshl' based on demanded bits (#124429) When simplifying operands based on demanded bits, the return value range of llvm.fshl might change. Keeping the Range attribute might cause llvm.fshl to generate a poison and lead to miscompile. Drop the Range attribute similar to `dropPosonGeneratingFlags` elsewhere. Fix #124387 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 943598a30f04..2c8939b5a051 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -1039,11 +1039,14 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, APInt DemandedMaskLHS(DemandedMask.lshr(ShiftAmt)); APInt DemandedMaskRHS(DemandedMask.shl(BitWidth - ShiftAmt)); if (I->getOperand(0) != I->getOperand(1)) { - if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, - Depth + 1, Q) || + if (SimplifyDemandedBits(I, 0, DemandedMaskLHS, LHSKnown, Depth + 1, + Q) || SimplifyDemandedBits(I, 1, DemandedMaskRHS, RHSKnown, Depth + 1, - Q)) + Q)) { + // Range attribute may no longer hold. + I->dropPoisonGeneratingReturnAttributes(); return I; + } } else { // fshl is a rotate // Avoid converting rotate into funnel shift. // Only simplify if one operand is constant.
[ { "file": "llvm/test/Transforms/InstCombine/fsh.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "fshl_range_trunc", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.fshl.i32(i32, i32, i32) #0\n\ndefine i8 @fshl_range_trunc(i1 %x) {\n %zext = zext i1 %x to i32\n %or = or disjoint i32 %zext, -2\n %fshl = call range(i32 -4, 2) i32 @llvm.fshl.i32(i32 %or, i32 %or, i32 1)\n %tr = trunc nsw i32 %fshl to i8\n ret i8 %tr\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Miscompile with -O2/3/s", "body": "This code prints random value at `-O2/3/s` and -1 at `-O0/1`:\n\n```c\nint printf(const char *, ...);\nint a, b;\nvoid c(char d) { a = d; }\nint e(int d) {\n if (d < 0)\n return 1;\n return 0;\n}\nint f() {\n if (b)\n return 0;\n return 1;\n}\nint g(int d) {\n int h = 0;\n if (3 + d)\n h = f() - 1 - 1;\n return e(h) + h + h;\n}\nint main() {\n int i = g(0);\n c(i);\n printf(\"%d\\n\", a);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/KfWsKxcvE\n\nIt starts from x86_64 clang 19.1.0. ", "author": "cardigan1008", "labels": [ "miscompilation", "llvm:instcombine", "regression:19" ], "comments": [ { "author": "MaskRay", "body": "InstCombine miscompiles \n\n```llvm\ndefine i32 @src(i32 %x) local_unnamed_addr {\nentry:\n %cmp = icmp eq i32 %x, 0\n %zext = zext i1 %cmp to i32\n %or = or disjoint i32 %zext, -2\n %fshl = call range(i32 -4, 2) i32 @llvm.fshl.i32(i32 %or, i32 %or, i32 1)\n %tr = trunc nsw i32 %fshl to i8\n %res = sext i8 %tr to i32\n ret i32 %res\n}\n```\n\nedit: `g` has a Range return attribute, which is propagated to the call site in `main` after inlining.\nInstCombine `InstCombinerImpl::SimplifyDemandedUseBits` simplifies the operand, but keeps the no-longer-valid Range return attribute.\n\nThen, CorrelatedValuePropagationPass added nsw, and the value eventually becomes poison." }, { "author": "nikic", "body": "Slightly reduced: https://alive2.llvm.org/ce/z/3Kf7-2\n\nI assume the problem is that we don't clear the return range attribute in SimplifyDemanded." } ] }
true
null
139728
https://github.com/llvm/llvm-project/issues/139728
crash
be6c1684c058ff40b5cb29e7eb88f06f72dd50df
2025-05-13T13:36:11
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "d79d9b8fbfc7e8411aeaf2f5e1be9d4247594fee", "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": [ [ 16142, 16157 ], [ 16210, 16216 ], [ 17799, 17815 ], [ 18696, 18701 ] ], "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::getLastInstructionInBundle", "BoUpSLP::setInsertPointAfterBundle", "BoUpSLP::vectorizeTree" ], "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 d79d9b8fbfc7e8411aeaf2f5e1be9d4247594fee Author: Alexey Bataev <[email protected]> Date: Fri May 16 12:52:27 2025 -0400 [SLP]Change the insertion point for outside-block-used nodes and prevec phi operand gathers Need to set the insertion point for (non-schedulable) vector node after the last instruction in the node to avoid def-use breakage. But it also causes miscompilation with gather/buildvector operands of the phi nodes, used in the same phi only in the block. These nodes supposed to be inserted at the end of the block and after changing the insertion point for the non-schedulable vec block, it also may break def-use dependencies. Need to prevector such nodes, to emit them as early as possible, so the vectorized nodes are inserted before these nodes. Fixes #139728 Reviewers: hiraditya, HanKuanChen, RKSimon Reviewed By: RKSimon Pull Request: https://github.com/llvm/llvm-project/pull/139917 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index eb339282fdae..19d19946ea23 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -16142,16 +16142,10 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { [](Value *V) { return !isa<GetElementPtrInst>(V) && isa<Instruction>(V); })) || - all_of(E->Scalars, - [](Value *V) { - return isa<PoisonValue>(V) || - (!isVectorLikeInstWithConstOps(V) && - isUsedOutsideBlock(V)); - }) || - (E->isGather() && E->Idx == 0 && all_of(E->Scalars, [](Value *V) { - return isa<ExtractElementInst, UndefValue>(V) || - areAllOperandsNonInsts(V); - }))) + all_of(E->Scalars, [](Value *V) { + return isa<PoisonValue>(V) || + (!isVectorLikeInstWithConstOps(V) && isUsedOutsideBlock(V)); + })) Res = FindLastInst(); else Res = FindFirstInst(); @@ -16210,7 +16204,7 @@ void BoUpSLP::setInsertPointAfterBundle(const TreeEntry *E) { } if (IsPHI || (!E->isGather() && E->State != TreeEntry::SplitVectorize && - doesNotNeedToSchedule(E->Scalars)) || + all_of(E->Scalars, areAllOperandsNonInsts)) || (GatheredLoadsEntriesFirst.has_value() && E->Idx >= *GatheredLoadsEntriesFirst && !E->isGather() && E->getOpcode() == Instruction::Load)) { @@ -17799,17 +17793,27 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { Value *VecOp = NewPhi->getIncomingValueForBlock(IBB); NewPhi->addIncoming(VecOp, IBB); TreeEntry *OpTE = getOperandEntry(E, I); + assert(!OpTE->VectorizedValue && "Expected no vectorized value."); OpTE->VectorizedValue = VecOp; continue; } Builder.SetInsertPoint(IBB->getTerminator()); Builder.SetCurrentDebugLocation(PH->getDebugLoc()); - Value *Vec = vectorizeOperand(E, I); + const TreeEntry *OpE = getOperandEntry(E, I); + Value *Vec; + if (OpE->isGather()) { + assert(OpE->VectorizedValue && "Expected vectorized value."); + Vec = OpE->VectorizedValue; + if (auto *IVec = dyn_cast<Instruction>(Vec)) + Builder.SetInsertPoint(IVec->getNextNonDebugInstruction()); + } else { + Vec = vectorizeOperand(E, I); + } if (VecTy != Vec->getType()) { - assert((It != MinBWs.end() || getOperandEntry(E, I)->isGather() || - MinBWs.contains(getOperandEntry(E, I))) && - "Expected item in MinBWs."); + assert( + (It != MinBWs.end() || OpE->isGather() || MinBWs.contains(OpE)) && + "Expected item in MinBWs."); Vec = Builder.CreateIntCast(Vec, VecTy, GetOperandSignedness(I)); } NewPhi->addIncoming(Vec, IBB); @@ -18696,6 +18700,28 @@ Value *BoUpSLP::vectorizeTree( else Builder.SetInsertPoint(&F->getEntryBlock(), F->getEntryBlock().begin()); + // Vectorize gather operands of the PHI nodes. + for (const std::unique_ptr<TreeEntry> &TE : reverse(VectorizableTree)) { + if (TE->isGather() && TE->UserTreeIndex.UserTE && + TE->UserTreeIndex.UserTE->hasState() && + !TE->UserTreeIndex.UserTE->isAltShuffle() && + TE->UserTreeIndex.UserTE->State == TreeEntry::Vectorize && + TE->UserTreeIndex.UserTE->getOpcode() == Instruction::PHI && + !TE->VectorizedValue) { + auto *PH = cast<PHINode>(TE->UserTreeIndex.UserTE->getMainOp()); + BasicBlock *IBB = PH->getIncomingBlock(TE->UserTreeIndex.EdgeIdx); + // If there is the same incoming block earlier - skip, it will be handled + // in PHI node. + if (TE->UserTreeIndex.EdgeIdx > 0 && + any_of(seq<unsigned>(TE->UserTreeIndex.EdgeIdx), [&](unsigned Idx) { + return PH->getIncomingBlock(Idx) == IBB; + })) + continue; + Builder.SetInsertPoint(IBB->getTerminator()); + Builder.SetCurrentDebugLocation(PH->getDebugLoc()); + (void)vectorizeTree(TE.get()); + } + } // Emit gathered loads first to emit better code for the users of those // gathered loads. for (const std::unique_ptr<TreeEntry> &TE : VectorizableTree) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/AArch64/reused-scalar-repeated-in-node.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=aarch64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nentry:\n br label %bb61\n\nbb61: ; preds = %entry\n br label %bb64\n\nbb62: ; No predecessors!\n br i1 poison, label %bb63, label %bb64\n\nbb63: ; preds = %bb62\n br label %bb64\n\nbb64: ; preds = %bb63, %bb62, %bb61\n %i = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\n %i65 = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\n %i66 = load float, ptr poison, align 16\n %i67 = load float, ptr poison, align 4\n %i68 = load float, ptr poison, align 8\n %i69 = load float, ptr poison, align 4\n %i70 = load float, ptr poison, align 4\n %i71 = load float, ptr poison, align 16\n %i72 = load float, ptr poison, align 4\n %i73 = load float, ptr poison, align 8\n %i74 = load float, ptr poison, align 4\n %i75 = load float, ptr poison, align 16\n %i76 = load float, ptr poison, align 4\n br i1 poison, label %bb167, label %bb77\n\nbb77: ; preds = %bb64\n br label %bb78\n\nbb78: ; preds = %bb78, %bb77\n %i79 = phi nsz float [ %i66, %bb77 ], [ %i103, %bb78 ]\n %i80 = phi nsz float [ %i67, %bb77 ], [ %i104, %bb78 ]\n %i81 = phi nsz float [ %i68, %bb77 ], [ %i105, %bb78 ]\n %i82 = phi nsz float [ poison, %bb77 ], [ %i106, %bb78 ]\n %i83 = phi nsz float [ poison, %bb77 ], [ %i123, %bb78 ]\n %i84 = phi nsz float [ %i69, %bb77 ], [ %i124, %bb78 ]\n %i85 = phi nsz float [ poison, %bb77 ], [ %i125, %bb78 ]\n %i86 = phi nsz float [ %i70, %bb77 ], [ %i126, %bb78 ]\n %i87 = fmul fast float %i79, poison\n %i88 = fmul fast float %i80, poison\n %i89 = fmul fast float %i81, poison\n %i90 = fmul fast float %i82, poison\n %i91 = fmul fast float %i83, poison\n %i92 = fadd fast float %i91, %i87\n %i93 = fmul fast float %i84, poison\n %i94 = fadd fast float %i93, %i88\n %i95 = fmul fast float %i85, poison\n %i96 = fadd fast float %i95, %i89\n %i97 = fmul fast float %i86, poison\n %i98 = fadd fast float %i97, %i90\n %i99 = fadd fast float %i92, poison\n %i100 = fadd fast float %i94, poison\n %i101 = fadd fast float %i96, poison\n %i102 = fadd fast float %i98, poison\n %i103 = fadd fast float %i99, poison\n %i104 = fadd fast float %i100, poison\n %i105 = fadd fast float %i101, poison\n %i106 = fadd fast float %i102, poison\n %i107 = fmul fast float %i79, poison\n %i108 = fmul fast float %i80, poison\n %i109 = fmul fast float %i81, poison\n %i110 = fmul fast float %i82, poison\n %i111 = fmul fast float %i83, poison\n %i112 = fadd fast float %i111, %i107\n %i113 = fmul fast float %i84, poison\n %i114 = fadd fast float %i113, %i108\n %i115 = fmul fast float %i85, poison\n %i116 = fadd fast float %i115, %i109\n %i117 = fmul fast float %i86, poison\n %i118 = fadd fast float %i117, %i110\n %i119 = fadd fast float %i112, poison\n %i120 = fadd fast float %i114, poison\n %i121 = fadd fast float %i116, poison\n %i122 = fadd fast float %i118, poison\n %i123 = fadd fast float %i119, poison\n %i124 = fadd fast float %i120, poison\n %i125 = fadd fast float %i121, poison\n %i126 = fadd fast float %i122, poison\n %i127 = fmul fast float %i79, %i\n %i128 = fmul fast float %i80, %i\n %i129 = fmul fast float %i81, %i\n %i130 = fmul fast float %i82, %i\n %i131 = fmul fast float %i83, %i65\n %i132 = fadd fast float %i131, %i127\n %i133 = fmul fast float %i84, %i65\n %i134 = fadd fast float %i133, %i128\n %i135 = fmul fast float %i85, %i65\n %i136 = fadd fast float %i135, %i129\n %i137 = fmul fast float %i86, %i65\n %i138 = fadd fast float %i137, %i130\n %i139 = fadd fast float %i132, poison\n %i140 = fadd fast float %i134, poison\n %i141 = fadd fast float %i136, poison\n %i142 = fadd fast float %i138, poison\n %i143 = fadd fast float %i139, poison\n %i144 = fadd fast float %i140, poison\n %i145 = fadd fast float %i141, poison\n %i146 = fadd fast float %i142, poison\n %i147 = fmul fast float %i79, poison\n %i148 = fmul fast float %i80, poison\n %i149 = fmul fast float %i81, poison\n %i150 = fmul fast float %i82, poison\n %i151 = fmul fast float %i83, poison\n %i152 = fadd fast float %i151, %i147\n %i153 = fmul fast float %i84, poison\n %i154 = fadd fast float %i153, %i148\n %i155 = fmul fast float %i85, poison\n %i156 = fadd fast float %i155, %i149\n %i157 = fmul fast float %i86, poison\n %i158 = fadd fast float %i157, %i150\n %i159 = fadd fast float %i152, poison\n %i160 = fadd fast float %i154, poison\n %i161 = fadd fast float %i156, poison\n %i162 = fadd fast float %i158, poison\n %i163 = fadd fast float %i159, poison\n %i164 = fadd fast float %i160, poison\n %i165 = fadd fast float %i161, poison\n %i166 = fadd fast float %i162, poison\n br i1 poison, label %bb78, label %bb167\n\nbb167: ; preds = %bb78, %bb64\n %i168 = phi nsz float [ %i76, %bb64 ], [ %i166, %bb78 ]\n %i169 = phi nsz float [ poison, %bb64 ], [ %i165, %bb78 ]\n %i170 = phi nsz float [ poison, %bb64 ], [ %i164, %bb78 ]\n %i171 = phi nsz float [ %i75, %bb64 ], [ %i163, %bb78 ]\n %i172 = phi nsz float [ %i74, %bb64 ], [ %i146, %bb78 ]\n %i173 = phi nsz float [ %i73, %bb64 ], [ %i145, %bb78 ]\n %i174 = phi nsz float [ %i72, %bb64 ], [ %i144, %bb78 ]\n %i175 = phi nsz float [ %i71, %bb64 ], [ %i143, %bb78 ]\n %i176 = phi nsz float [ %i70, %bb64 ], [ %i126, %bb78 ]\n %i177 = phi nsz float [ poison, %bb64 ], [ %i125, %bb78 ]\n %i178 = phi nsz float [ %i69, %bb64 ], [ %i124, %bb78 ]\n %i179 = phi nsz float [ poison, %bb64 ], [ %i123, %bb78 ]\n %i180 = phi nsz float [ poison, %bb64 ], [ %i106, %bb78 ]\n %i181 = phi nsz float [ %i68, %bb64 ], [ %i105, %bb78 ]\n %i182 = phi nsz float [ %i67, %bb64 ], [ %i104, %bb78 ]\n %i183 = phi nsz float [ %i66, %bb64 ], [ %i103, %bb78 ]\n store float %i182, ptr poison, align 1\n store float %i174, ptr poison, align 1\n br i1 poison, label %bb186, label %bb184\n\nbb184: ; preds = %bb167\n br label %bb185\n\nbb185: ; preds = %bb185, %bb184\n br i1 poison, label %bb185, label %bb186\n\nbb186: ; preds = %bb185, %bb167\n %i187 = phi nsz float [ %i178, %bb167 ], [ poison, %bb185 ]\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/buildvectors-parent-phi-nodes.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-generic-linux-gnu -mattr=+avx < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %0, float %1) {\n %3 = load float, ptr %0, align 4\n br label %4\n\n4: ; preds = %4, %2\n %5 = phi float [ %1, %4 ], [ %3, %2 ]\n %6 = phi float [ %1, %4 ], [ 0.000000e+00, %2 ]\n %7 = phi float [ %28, %4 ], [ 0.000000e+00, %2 ]\n %8 = phi float [ %26, %4 ], [ 0.000000e+00, %2 ]\n %9 = phi float [ %26, %4 ], [ %3, %2 ]\n %10 = phi float [ %24, %4 ], [ 0.000000e+00, %2 ]\n %11 = fmul float %9, 0.000000e+00\n %12 = fadd float %11, 0.000000e+00\n %13 = fmul float %7, 0.000000e+00\n %14 = fadd float %13, 0.000000e+00\n %15 = fmul float %10, 0.000000e+00\n %16 = fadd float %15, 0.000000e+00\n %17 = fmul float %8, 0.000000e+00\n %18 = fadd float %17, 0.000000e+00\n %19 = insertelement <4 x float> zeroinitializer, float %12, i64 0\n %20 = insertelement <4 x float> %19, float %14, i64 1\n %21 = insertelement <4 x float> %20, float %16, i64 2\n %22 = insertelement <4 x float> %21, float %18, i64 3\n store <4 x float> %22, ptr %0, align 16\n %23 = fmul float %6, 0.000000e+00\n %24 = fadd float %23, 0.000000e+00\n %25 = fmul float %6, 0.000000e+00\n %26 = fadd float %25, 0.000000e+00\n %27 = fmul float %5, 0.000000e+00\n %28 = fadd float %27, 0.000000e+00\n br label %4\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 } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/matched-bv-schedulable.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s -slp-threshold=-99999" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n br i1 false, label %bb1, label %bb5\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ %or4, %bb1 ], [ 0, %bb ]\n %phi2 = phi i32 [ %add, %bb1 ], [ 0, %bb ]\n %add = add i32 1, 0\n %or = or i32 0, %phi2\n %or3 = or i32 %or, 0\n %mul = mul i32 0, 0\n %or4 = or i32 %phi, %mul\n br i1 false, label %bb1, label %bb5\n\nbb5: ; preds = %bb1, %bb\n %phi6 = phi i32 [ 0, %bb ], [ %or4, %bb1 ]\n %phi7 = phi i32 [ 0, %bb ], [ %or, %bb1 ]\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/matched-nodes-updated.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-9999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(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", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/node-outside-used-only.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i64 @test() {\n;\nbb:\n br label %bb1\n\nbb1:\n %phi = phi i32 [ 0, %bb ], [ %or, %bb5 ]\n %phi2 = phi i32 [ 0, %bb ], [ %or4, %bb5 ]\n %or = or i32 %phi, 0\n %add = add i32 0, 0\n %or3 = or i32 %add, %phi2\n %or4 = or i32 %or3, 0\n br label %bb5\n\nbb5:\n br i1 false, label %bb6, label %bb1\n\nbb6:\n %phi7 = phi i32 [ %or, %bb5 ]\n %phi8 = phi i32 [ %or3, %bb5 ]\n ret i64 0\n}", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-val-vectorized-in-transform.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-10 < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(i1 %cond) {\nentry:\n br label %bb\n\nbb: ; preds = %bb, %entry\n %p1 = phi i32 [ %or92, %bb ], [ 0, %entry ]\n %p2 = phi i32 [ %0, %bb ], [ 0, %entry ]\n %p3 = phi i32 [ %4, %bb ], [ 0, %entry ]\n %0 = or i32 1, 0\n %or8.i = or i32 0, 0\n %or9.i = or i32 0, 0\n %or91 = or i32 %p1, 0\n %or12.i = or i32 %p2, 0\n %or92 = or i32 1, 0\n %1 = xor i32 %or91, %or12.i\n %2 = xor i32 %1, %or9.i\n %3 = xor i32 %2, %or8.i\n %4 = xor i32 %3, %or92\n br i1 %cond, label %exit, label %bb\n\nexit: ; preds = %bb\n ret i32 %4\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/split-node-num-operands.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx -slp-threshold=-1000 < %s" ], "tests": [ { "test_name": "Foo", "test_body": "define i64 @Foo(ptr align 8 dereferenceable(344) %0, i64 %1) {\n %3 = getelementptr i8, ptr %0, i64 104\n %4 = getelementptr i8, ptr %0, i64 112\n %5 = getelementptr i8, ptr %0, i64 24\n %6 = load i64, ptr %3, align 8\n %7 = load i64, ptr %4, align 8\n %8 = load i64, ptr %5, align 8\n %9 = load i64, ptr %0, align 8\n br label %10\n\n10: ; preds = %18, %2\n %11 = phi i64 [ %9, %2 ], [ 0, %18 ]\n %12 = phi i64 [ %8, %2 ], [ %12, %18 ]\n %13 = phi i64 [ %7, %2 ], [ 0, %18 ]\n %14 = phi i64 [ %6, %2 ], [ 0, %18 ]\n switch i32 0, label %15 [\n i32 0, label %18\n ]\n\n15: ; preds = %10\n %16 = tail call i64 @llvm.umin.i64(i64 0, i64 0)\n %17 = tail call i64 @llvm.umax.i64(i64 0, i64 0)\n br label %18\n\n18: ; preds = %15, %10\n %19 = phi i64 [ %17, %15 ], [ 0, %10 ]\n %20 = phi i64 [ %16, %15 ], [ 0, %10 ]\n %21 = phi i64 [ %11, %15 ], [ 0, %10 ]\n %22 = phi i64 [ %12, %15 ], [ 0, %10 ]\n %23 = phi i64 [ %13, %15 ], [ %1, %10 ]\n %24 = phi i64 [ %14, %15 ], [ 0, %10 ]\n br i1 false, label %.loopexit206, label %10\n\n.loopexit206: ; preds = %18\n switch i32 0, label %26 [\n i32 0, label %.cont174\n i32 1, label %25\n ]\n\n25: ; preds = %.loopexit206\n br label %.cont174\n\n26: ; preds = %.loopexit206\n %27 = tail call i64 @llvm.umin.i64(i64 0, i64 0)\n %28 = tail call i64 @llvm.umax.i64(i64 0, i64 0)\n br label %.cont174\n\n.cont174: ; preds = %26, %25, %.loopexit206\n %.sroa.139.1 = phi i64 [ %28, %26 ], [ %19, %25 ], [ %19, %.loopexit206 ]\n %.sroa.133.1 = phi i64 [ %27, %26 ], [ 0, %25 ], [ %20, %.loopexit206 ]\n %.sroa.81.1 = phi i64 [ %23, %26 ], [ 0, %25 ], [ %23, %.loopexit206 ]\n %.sroa.75.1 = phi i64 [ %24, %26 ], [ 0, %25 ], [ %24, %.loopexit206 ]\n %.sroa.21.1 = phi i64 [ %21, %26 ], [ 0, %25 ], [ %21, %.loopexit206 ]\n %.sroa.15.1 = phi i64 [ %22, %26 ], [ 0, %25 ], [ %22, %.loopexit206 ]\n %29 = phi i64 [ %28, %26 ], [ 0, %25 ], [ %19, %.loopexit206 ]\n %30 = phi i64 [ %27, %26 ], [ 0, %25 ], [ %20, %.loopexit206 ]\n ret i64 0\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.umax.i64(i64, i64) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.umin.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/SLPVectorizer/revec.ll", "commands": [ "opt -passes=slp-vectorizer -S -slp-revec -slp-max-reg-size=1024 -slp-threshold=-100 %s" ], "tests": [ { "test_name": "test8", "test_body": "define void @test8() {\nentry:\n br i1 false, label %for0, label %for.body\n\nfor0: ; preds = %for.body, %entry\n %0 = phi <2 x float> [ zeroinitializer, %entry ], [ %4, %for.body ]\n %1 = phi <2 x float> [ zeroinitializer, %entry ], [ %5, %for.body ]\n %2 = phi <2 x float> [ zeroinitializer, %entry ], [ %4, %for.body ]\n %3 = phi <2 x float> [ zeroinitializer, %entry ], [ %5, %for.body ]\n ret void\n\nfor.body: ; preds = %for.body, %entry\n %4 = phi <2 x float> [ %4, %for.body ], [ zeroinitializer, %entry ]\n %5 = phi <2 x float> [ %5, %for.body ], [ zeroinitializer, %entry ]\n br i1 false, label %for0, label %for.body\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test7", "test_body": "define void @test7() {\n %1 = getelementptr i8, ptr null, i64 16\n %2 = trunc <8 x i64> zeroinitializer to <8 x i16>\n store <8 x i16> %2, ptr %1, align 2\n %3 = trunc <8 x i64> zeroinitializer to <8 x i16>\n store <8 x i16> %3, ptr null, align 2\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted! Yet another case.", "body": "To reproduce run opt with the test below using -passes=slp-vectorizer -slp-threshold=-99999:\n\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 i64 @wombat() #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb5, %bb\n %phi = phi i32 [ 0, %bb ], [ %or, %bb5 ]\n %phi2 = phi i32 [ 0, %bb ], [ %or4, %bb5 ]\n %or = or i32 %phi, 0\n %add = add i32 0, 0\n %or3 = or i32 %add, %phi2\n %or4 = or i32 %or3, 0\n br label %bb5\n\nbb5: ; preds = %bb1\n br i1 false, label %bb6, label %bb1\n\nbb6: ; preds = %bb5\n %phi7 = phi i32 [ %or, %bb5 ]\n %phi8 = phi i32 [ %or3, %bb5 ]\n ret i64 0\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,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-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,-avx512f\" }\n```\n\nReproducer: https://godbolt.org/z/xh9xjfEKc\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 \"verify\" on module \"<source>\"\n #0 0x00000000055a8748 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x55a8748)\n #1 0x00000000055a60d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007479c4242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007479c42969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007479c4242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007479c42287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000000000080bfcd llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\n #7 0x00000000054e4741 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54e4741)\n #8 0x00000000053e0e38 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x53e0e38)\n #9 0x0000000000940c0e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x940c0e)\n#10 0x000000000539ff70 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x539ff70)\n#11 0x000000000094b05a 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+0x94b05a)\n#12 0x000000000093e82c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x93e82c)\n#13 0x00007479c4229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#14 0x00007479c4229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#15 0x0000000000936465 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x936465)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
132841
https://github.com/llvm/llvm-project/issues/132841
crash
822aa5ec1afee68fb16457ff06de9111c1b62450
2025-03-24T22:57:28
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "8122bb9dbe39a1dde77eb4aad76bf1c0e70b2d89", "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": [ [ 15071, 15077 ], [ 15098, 15109 ] ], "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::getLastInstructionInBundle" ], "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 8122bb9dbe39a1dde77eb4aad76bf1c0e70b2d89 Author: Alexey Bataev <[email protected]> Date: Tue Mar 25 04:10:56 2025 -0700 [SLP]Fix a check for non-schedulable instructions Need to fix a check for non-schedulable instructions in getLastInstructionInBundle function, because this check may not work correctly during the codegen. Instead, need to check that actually these instructions were never scheduled, since the scheduling analysis always performed before the codegen and is stable. Fixes #132841 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4dc398f716b3..7741f96ee897 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -15071,7 +15071,18 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { // Set the insert point to the beginning of the basic block if the entry // should not be scheduled. - if (doesNotNeedToSchedule(E->Scalars) || + const auto *It = BlocksSchedules.find(BB); + auto IsNotScheduledEntry = [&](const TreeEntry *E) { + if (E->isGather()) + return false; + // Found previously that the instruction do not need to be scheduled. + return It == BlocksSchedules.end() || all_of(E->Scalars, [&](Value *V) { + if (!isa<Instruction>(V)) + return true; + return It->second->getScheduleBundles(V).empty(); + }); + }; + if (IsNotScheduledEntry(E) || (!E->isGather() && all_of(E->Scalars, isVectorLikeInstWithConstOps))) { if ((E->getOpcode() == Instruction::GetElementPtr && any_of(E->Scalars, @@ -15098,12 +15109,11 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { // scheduled, and the last instruction is VL.back(). So we start with // VL.back() and iterate over schedule data until we reach the end of the // bundle. The end of the bundle is marked by null ScheduleData. - if (BlocksSchedules.count(BB) && !E->isGather()) { + if (It != BlocksSchedules.end() && !E->isGather()) { Value *V = E->isOneOf(E->Scalars.back()); if (doesNotNeedToBeScheduled(V)) V = *find_if_not(E->Scalars, doesNotNeedToBeScheduled); - if (ArrayRef<ScheduleBundle *> Bundles = - BlocksSchedules[BB]->getScheduleBundles(V); + if (ArrayRef<ScheduleBundle *> Bundles = It->second->getScheduleBundles(V); !Bundles.empty()) { const auto *It = find_if( Bundles, [&](ScheduleBundle *B) { return B->getTreeEntry() == E; });
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/non-schedulable-instructions-become-schedulable.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-unknown -mcpu=znver2 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nentry:\n br label %bb1\n\nif.then.i.i:\n br label %3\n\nbb1:\n %0 = zext i1 false to i64\n %1 = add i64 0, %0\n %2 = add i64 0, 0\n br i1 false, label %3, label %bb2\n\n3:\n %pgocount51962 = phi i64 [ 0, %bb1 ], [ 0, %if.then.i.i ]\n %pgocount62360 = phi i64 [ 0, %bb1 ], [ 0, %if.then.i.i ]\n %pgocount83056 = phi i64 [ %1, %bb1 ], [ 0, %if.then.i.i ]\n %pgocount93354 = phi i64 [ %2, %bb1 ], [ 0, %if.then.i.i ]\n br label %bb2\n\nbb2:\n %pgocount51961 = phi i64 [ %pgocount51962, %3 ], [ 0, %bb1 ]\n %pgocount62359 = phi i64 [ %pgocount62360, %3 ], [ 0, %bb1 ]\n %pgocount83055 = phi i64 [ %pgocount83056, %3 ], [ %1, %bb1 ]\n %pgocount93353 = phi i64 [ %pgocount93354, %3 ], [ %2, %bb1 ]\n store i64 %pgocount51961, ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 8\n store i64 %pgocount62359, ptr getelementptr inbounds nuw (i8, ptr null, i64 48), align 8\n store i64 %pgocount83055, ptr getelementptr inbounds nuw (i8, ptr null, i64 56), align 8\n store i64 %pgocount93353, ptr getelementptr inbounds nuw (i8, ptr null, i64 64), align 8\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLP] crash with -fprofile-generate: Instruction::PHI && \"Expected PHI\"", "body": "One of our internal tests picked up a new assertion failure since #131625\n\nHere's a reduced test-case\nhttps://godbolt.org/z/rKT64of5b\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-unknown\"\n\ndefine void @_Z1sv() #0 {\nentry:\n br label %\"_ZZ1svEN3$_08__invokeEii.exit\"\n\nif.then.i.i: ; No predecessors!\n br label %3\n\n\"_ZZ1svEN3$_08__invokeEii.exit\": ; preds = %entry\n %0 = zext i1 false to i64\n %1 = add i64 0, %0\n %2 = add i64 0, 0\n br i1 false, label %3, label %while.cond.while.end_crit_edge\n\n3: ; preds = %\"_ZZ1svEN3$_08__invokeEii.exit\", %if.then.i.i\n %pgocount51962 = phi i64 [ 0, %\"_ZZ1svEN3$_08__invokeEii.exit\" ], [ 0, %if.then.i.i ]\n %pgocount62360 = phi i64 [ 0, %\"_ZZ1svEN3$_08__invokeEii.exit\" ], [ 0, %if.then.i.i ]\n %pgocount83056 = phi i64 [ %1, %\"_ZZ1svEN3$_08__invokeEii.exit\" ], [ 0, %if.then.i.i ]\n %pgocount93354 = phi i64 [ %2, %\"_ZZ1svEN3$_08__invokeEii.exit\" ], [ 0, %if.then.i.i ]\n br label %while.cond.while.end_crit_edge\n\nwhile.cond.while.end_crit_edge: ; preds = %3, %\"_ZZ1svEN3$_08__invokeEii.exit\"\n %pgocount51961 = phi i64 [ %pgocount51962, %3 ], [ 0, %\"_ZZ1svEN3$_08__invokeEii.exit\" ]\n %pgocount62359 = phi i64 [ %pgocount62360, %3 ], [ 0, %\"_ZZ1svEN3$_08__invokeEii.exit\" ]\n %pgocount83055 = phi i64 [ %pgocount83056, %3 ], [ %1, %\"_ZZ1svEN3$_08__invokeEii.exit\" ]\n %pgocount93353 = phi i64 [ %pgocount93354, %3 ], [ %2, %\"_ZZ1svEN3$_08__invokeEii.exit\" ]\n store i64 %pgocount51961, ptr getelementptr inbounds nuw (i8, ptr null, i64 40), align 8\n store i64 %pgocount62359, ptr getelementptr inbounds nuw (i8, ptr null, i64 48), align 8\n store i64 %pgocount83055, ptr getelementptr inbounds nuw (i8, ptr null, i64 56), align 8\n store i64 %pgocount93353, ptr getelementptr inbounds nuw (i8, ptr null, i64 64), align 8\n ret void\n}\n\n; uselistorder directives\nuselistorder ptr null, { 3, 2, 1, 0 }\n\nattributes #0 = { \"target-cpu\"=\"znver2\" }\n```\n\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:15064: llvm::Instruction& llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(const llvm::slpvectorizer::BoUpSLP::TreeEntry*): Assertion `E->getOpcode() == Instruction::PHI && \"Expected PHI\"' 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 \"_Z1sv\"\n```\n\nThis is derived from the following reduced C++ code:\n\nhttps://godbolt.org/z/aqYnvnGdj\n```\nint b, a, c, d, e, g, h, i;\nint j(const char *, const char *);\nint q();\nstruct ag {\n friend bool r(ag) {\n const char *f, *k = q() ? 0 : \"\";\n f = q() ? 0 : \"\";\n return j(k, f);\n }\n} l;\nbool m;\nvoid s() {\n auto n = [](int, int) {\n if (c) {\n if (a)\n return true;\n } else if (a)\n if (d)\n if (e) {\n bool o = r(l);\n return o;\n }\n return m;\n };\n bool (*p)(int, int) = n;\n while (h)\n g = p(b, i) ?: g;\n}\n```\n\n```\nclang++: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:15064: llvm::Instruction& llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(const llvm::slpvectorizer::BoUpSLP::TreeEntry*): Assertion `E->getOpcode() == Instruction::PHI && \"Expected PHI\"' 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 -O2 -fprofile-generate -march=znver2 <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 \"slp-vectorizer\" on function \"_Z1sv\"\n\n```", "author": "gregbedwell", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
106417
https://github.com/llvm/llvm-project/issues/106417
crash
66927fb95abef9327b453d7213c5df7d641269be
2024-08-28T16:21:38
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "c4906588ce47de33d59bcd95f3e82ce2c3e61c23", "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": [ [ 7113, 7119 ], [ 7121, 7126 ] ], "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::precomputeCosts" ], "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 c4906588ce47de33d59bcd95f3e82ce2c3e61c23 Author: Florian Hahn <[email protected]> Date: Thu Aug 29 21:19:59 2024 +0100 [VPlan] Use skipCostComputation when pre-computing induction costs. This ensures we skip any instructions identified to be ignored by the legacy cost model as well. Fixes a divergence between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/106417. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4cc75e2e7546..6babfd1eee91 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7113,7 +7113,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, IVInsts.push_back(CI); } for (Instruction *IVInst : IVInsts) { - if (!CostCtx.SkipCostComputation.insert(IVInst).second) + if (CostCtx.skipCostComputation(IVInst, VF.isVector())) continue; InstructionCost InductionCost = CostCtx.getLegacyCost(IVInst, VF); LLVM_DEBUG({ @@ -7121,6 +7121,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, << ": induction instruction " << *IVInst << "\n"; }); Cost += InductionCost; + CostCtx.SkipCostComputation.insert(IVInst); } }
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/induction-costs.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "skip_free_iv_truncate", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @skip_free_iv_truncate(i16 %x, ptr %A) #0 {\nentry:\n %x.i32 = sext i16 %x to i32\n %x.i64 = sext i16 %x to i64\n %invariant.gep = getelementptr i8, ptr %A, i64 -8\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %x.i64, %entry ], [ %iv.next, %loop ]\n %iv.conv = phi i32 [ %x.i32, %entry ], [ %3, %loop ]\n %gep.i64 = getelementptr i64, ptr %A, i64 %iv\n %0 = load i64, ptr %gep.i64, align 8\n %1 = sext i32 %iv.conv to i64\n %gep.conv = getelementptr i64, ptr %invariant.gep, i64 %1\n %2 = load i64, ptr %gep.conv, align 8\n %gep.i16 = getelementptr i16, ptr %A, i64 %iv\n store i16 0, ptr %gep.i16, align 2\n %iv.next = add i64 %iv, 3\n %3 = trunc i64 %iv.next to i32\n %c = icmp slt i64 %iv, 99\n br i1 %c, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl256b\" }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using 190449a5d2a9ddfc2180dce11714a4443f0f29f0\r\n\r\nTestcase:\r\n```c\r\nchar a;\r\nextern short b[][6][6];\r\nshort c;\r\nlong d;\r\nlong *e, *f;\r\nvoid g(char h[][6]) {\r\n for (short i = d + 9; i < 4; i += 3) {\r\n a = ({ f[i]; }) < f[i - 1];\r\n for (int j = c; j; j = ({ h[5][i + 2]; }) ? e[i - 1] : 0)\r\n ;\r\n b[i][i][i] = 0;\r\n }\r\n}\r\n```\r\nhttps://godbolt.org/z/EGdEPbKad\r\n\r\nIR 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 void @g(i16 %0, i64 %indvars.iv52) #0 {\r\nentry:\r\n %conv146 = sext i16 %0 to i32\r\n %1 = sext i16 %0 to i64\r\n %invariant.gep = getelementptr i8, ptr null, i64 -8\r\n br label %for.body.us\r\n\r\nfor.body.us: ; preds = %for.body.us, %entry\r\n %indvars.iv521 = phi i64 [ %1, %entry ], [ %indvars.iv.next53, %for.body.us ]\r\n %conv149.us = phi i32 [ %conv146, %entry ], [ %5, %for.body.us ]\r\n %arrayidx.us = getelementptr i64, ptr null, i64 %indvars.iv521\r\n %2 = load i64, ptr %arrayidx.us, align 8\r\n %3 = sext i32 %conv149.us to i64\r\n %gep = getelementptr i64, ptr %invariant.gep, i64 %3\r\n %4 = load i64, ptr %gep, align 8\r\n %arrayidx31.us = getelementptr [0 x [6 x [6 x i16]]], ptr null, i64 0, i64 %indvars.iv521, i64 %indvars.iv52, i64 %indvars.iv52\r\n store i16 0, ptr %arrayidx31.us, align 2\r\n %indvars.iv.next53 = add i64 %indvars.iv521, 3\r\n %5 = trunc i64 %indvars.iv.next53 to i32\r\n %cmp.us = icmp slt i64 %indvars.iv521, 0\r\n br i1 %cmp.us, label %for.body.us, label %for.cond.for.cond.cleanup_crit_edge.split.us\r\n\r\nfor.cond.for.cond.cleanup_crit_edge.split.us: ; preds = %for.body.us\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,+zvl256b,+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,-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 -S reduced.ll\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7359: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && \" 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 -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 0x0000640a195798f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x30178f0)\r\n #1 0x0000640a19576d0f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3014d0f)\r\n #2 0x0000640a19576e65 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007aac19442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007aac194969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007aac194969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007aac194969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007aac19442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007aac194287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007aac1942871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007aac19439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000640a18546ac9 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe4ac9)\r\n#12 0x0000640a1855cedb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffaedb)\r\n#13 0x0000640a1855fef1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffdef1)\r\n#14 0x0000640a18560567 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffe567)\r\n#15 0x0000640a173c0a96 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+0xe5ea96)\r\n#16 0x0000640a19384d4f 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+0x2e22d4f)\r\n#17 0x0000640a173c3c26 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+0xe61c26)\r\n#18 0x0000640a19383acb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e21acb)\r\n#19 0x0000640a173bfec6 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+0xe5dec6)\r\n#20 0x0000640a19381b0d 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+0x2e1fb0d)\r\n#21 0x0000640a16be9da6 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+0x687da6)\r\n#22 0x0000640a16bdbb31 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679b31)\r\n#23 0x00007aac19429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007aac19429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007aac19429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x0000640a16bd1ee5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66fee5)\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/W3KqbcKrb\r\n\r\nFound via fuzzer\r\nRelated/prior issue: #104714\r\n\r\ncc @fhahn ", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
125301
https://github.com/llvm/llvm-project/issues/125301
crash
4f381d0be845a8702c89a0a7f4bd9188e1ff60a3
2025-01-31T21:43:25
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "75b922dccfc35ec25a520b1941e6682a300802b8", "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": 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": [ [ 1058, 1063 ] ], "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": 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": [ "classof" ], "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 75b922dccfc35ec25a520b1941e6682a300802b8 Author: Florian Hahn <[email protected]> Date: Sat Feb 1 21:40:58 2025 +0000 [VPlan] Check VPWidenIntrinsicSC in VPRecipeWithIRFlags::classof. When VPWidenIntrinsicRecipe was changed to inhert from VPRecipeWithIRFlags, VPRecipeWithIRFlags::classof wasn't updated accordingly. Also check for VPWidenIntrinsicSC in VPRecipeWithIRFlags::classof. Fixes https://github.com/llvm/llvm-project/issues/125301. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 459222234bc3..87ef2dc6d8ea 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1058,6 +1058,7 @@ public: R->getVPDefID() == VPRecipeBase::VPWidenEVLSC || R->getVPDefID() == VPRecipeBase::VPWidenGEPSC || R->getVPDefID() == VPRecipeBase::VPWidenCastSC || + R->getVPDefID() == VPRecipeBase::VPWidenIntrinsicSC || R->getVPDefID() == VPRecipeBase::VPReplicateSC || R->getVPDefID() == VPRecipeBase::VPReverseVectorPointerSC || R->getVPDefID() == VPRecipeBase::VPVectorPointerSC;
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/drop-poison-generating-flags.ll", "commands": [ "opt -p loop-vectorize -mcpu=neoverse-v2 -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget triple = \"aarch64-unknown-linux\"\n\n; Test case where we visit a VPWidenIntrinsic (for @llvm.fabs) with nnan flags.\n; For https://github.com/llvm/llvm-project/issues/125301.\ndefine void @check_widen_intrinsic_with_nnan(ptr noalias %dst.0, ptr noalias %dst.1, ptr noalias %src.1, ptr %src.2) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.src.1 = getelementptr inbounds double, ptr %src.1, i64 %iv\n %l.1 = load double, ptr %gep.src.1, align 8\n %abs = tail call nnan double @llvm.fabs.f64(double %l.1)\n %c.0 = fcmp olt double %abs, 1.000000e+00\n br i1 %c.0, label %then, label %else\n\nthen:\n %l.2 = load double, ptr %src.2, align 8\n %iv.sub.1 = add nsw i64 %iv, -1\n %gep.iv.sub.1 = getelementptr double, ptr %dst.0, i64 %iv.sub.1\n store double 0.000000e+00, ptr %gep.iv.sub.1, align 8\n %c.1 = fcmp oeq double %l.2, 0.000000e+00\n br i1 %c.1, label %merge, label %loop.latch\n\nelse:\n %iv.sub.2 = add nsw i64 %iv, -1\n %gep.iv.sub.2 = getelementptr double, ptr %dst.0, i64 %iv.sub.2\n store double 0.000000e+00, ptr %gep.iv.sub.2, align 8\n br label %merge\n\nmerge:\n %merge.iv = phi i64 [ %iv.sub.2, %else ], [ %iv.sub.1, %then ]\n %gep.dst.1 = getelementptr inbounds i32, ptr %dst.1, i64 %merge.iv\n store i32 10, ptr %gep.dst.1, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %exit, label %loop.header\n\nexit:\nret void\n}\n\ndeclare double @llvm.fabs.f64(double)", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[vplan] Assertion: found instruction with poison generating flags not covered by VPRecipeWithIRFlags", "body": "```\nclang++ -O3 -mcpu=neoverse-v2 -c reduced.ll\n\nclang++: llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:1926: llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, const std::function<bool(llvm::BasicBlock*)>&)::<lambda(llvm::VPRecipeBase*)>: Assertion `(!Instr || !Instr->hasPoisonGeneratingFlags()) && \"found instruction with poison generating flags not covered by \" \"VPRecipeWithIRFlags\"' 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: clang++ -O3 -mcpu=neoverse-v2 -c reduced.ll\n1. Optimizer\n2. 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 \"reduced.ll\"\n3. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"foo\"\n #0 0x0000aaaaaf09abe8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)\n #1 0x0000aaaaaf098908 llvm::sys::RunSignalHandlers()\n #2 0x0000aaaaaf098c88 llvm::sys::CleanupOnSignal(unsigned long)\n #3 0x0000aaaaaefee5bc CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #4 0x0000fffff7fb08dc (linux-vdso.so.1+0x8dc)\n #5 0x0000fffff7c2f200 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #6 0x0000fffff7bea67c gsignal ./signal/../sysdeps/posix/raise.c:27:6\n #7 0x0000fffff7bd7130 abort ./stdlib/abort.c:81:7\n #8 0x0000fffff7be3fd0 __assert_fail_base ./assert/assert.c:89:7\n #9 0x0000fffff7be4040 __assert_perror_fail ./assert/assert-perr.c:31:1\n#10 0x0000aaaab0bfd210 llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, std::function<bool (llvm::BasicBlock*)> const&)::'lambda'(llvm::VPRecipeBase*)::operator()(llvm::VPRecipeBase*) const (.isra.0) VPlanTransforms.cpp:0:0\n#11 0x0000aaaab0c065b4 llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, std::function<bool (llvm::BasicBlock*)> const&) \n#12 0x0000aaaab0b99078 llvm::LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(llvm::VFRange&)\n#13 0x0000aaaab0b99634 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount)\n#14 0x0000aaaab0b99c1c llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int)\n#15 0x0000aaaab0b9b05c llvm::LoopVectorizePass::processLoop(llvm::Loop*) \n#16 0x0000aaaab0b9d464 llvm::LoopVectorizePass::runImpl(llvm::Function&) \n#17 0x0000aaaab0b9da1c llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) \n#18 0x0000aaaab07856fc llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilder.cpp:0:0\n#19 0x0000aaaaaeb3fef8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)\n#20 0x0000aaaaadbd51dc 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#21 0x0000aaaaaeb3e97c llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&)\n#22 0x0000aaaaadbd513c llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) NVPTXTargetMachine.cpp:0:0\n#23 0x0000aaaaaeb3e3a4 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) \n#24 0x0000aaaaafa2b598 (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 0x0000aaaaafa2e258 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*)\n#26 0x0000aaaaafb69e8c clang::CodeGenAction::ExecuteAction()\n#27 0x0000aaaaafef684c clang::FrontendAction::Execute()\n#28 0x0000aaaaafe8bb30 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) \n#29 0x0000aaaaaffe49b0 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) \n#30 0x0000aaaaadb8f874 cc1_main(llvm::ArrayRef<char const*>, char const*, void*)\n#31 0x0000aaaaadb87f34 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#32 0x0000aaaaafcd7778 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 0x0000aaaaaefeeac0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>)\n#34 0x0000aaaaafcd7d48 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 0x0000aaaaafc9daf4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const\n#36 0x0000aaaaafc9e744 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const \n#37 0x0000aaaaafca6268 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) \n#38 0x0000aaaaadb8c654 clang_main(int, char**, llvm::ToolContext const&)\n#39 0x0000aaaaadb9c06c main\n#40 0x0000fffff7bd73fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\n#41 0x0000fffff7bd74cc call_init ./csu/../csu/libc-start.c:128:20\n#42 0x0000fffff7bd74cc __libc_start_main ./csu/../csu/libc-start.c:379:5\n#43 0x0000aaaaadb87a24 _start\nclang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project 82b923defe27cc46ecf3084f3a8f1c0d1c36199e)\nTarget: aarch64-unknown-linux-gnu\nThread model: posix\nInstalledDir: \nBuild config: +assertions\nclang++: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.\n```\n```\n# works ok\nclang++ -O3 -mcpu=neoverse-n1 -c reduced.ll\n```\n\n```\n; ModuleID = '<bc file>'\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32\"\ntarget triple = \"aarch64-unknown-linux-gnu\"\n\ndefine void @foo(ptr %0, ptr %1, ptr %bar, i64 %2) {\n br label %4\n\n4: ; preds = %5, %3\n br label %5\n\n5: ; preds = %26, %4\n %6 = phi i32 [ %27, %26 ], [ 0, %4 ]\n %7 = phi i64 [ %28, %26 ], [ %2, %4 ]\n %8 = icmp sgt i64 %7, 0\n br i1 %8, label %9, label %4\n\n9: ; preds = %5\n %10 = load double, ptr %1, align 8\n %11 = call nnan double @llvm.fabs.f64(double %10)\n %12 = fcmp olt double %11, 1.000000e+00\n br i1 %12, label %13, label %21\n\n13: ; preds = %9\n %14 = load double, ptr %bar, align 8\n %15 = zext i32 %6 to i64\n %16 = add i64 %15, -1\n %17 = getelementptr double, ptr %0, i64 %16\n store double 0.000000e+00, ptr %17, align 8\n %18 = fcmp oeq double %14, 0.000000e+00\n br i1 %18, label %19, label %26\n\n19: ; preds = %13\n %20 = getelementptr i32, ptr null, i64 %16\n store i32 0, ptr %20, align 4\n br label %26\n\n21: ; preds = %9\n %22 = zext i32 %6 to i64\n %23 = add i64 %22, -1\n %24 = getelementptr double, ptr %0, i64 %23\n store double 0.000000e+00, ptr %24, align 8\n %25 = getelementptr i32, ptr null, i64 %23\n store i32 0, ptr %25, align 4\n br label %26\n\n26: ; preds = %21, %19, %13\n %27 = add nsw i32 %6, 1\n %28 = add i64 %7, -1\n br label %5\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare double @llvm.fabs.f64(double) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```", "author": "ashermancinelli", "labels": [ "release:backport", "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "@ashermancinelli it looks like `reduced.ll` is missing from the issue here? Could you attach it (or share a link to godbolt)?" }, { "author": "ashermancinelli", "body": "@fhahn Sorry about that! I updated the description." } ] }
true
null
108004
https://github.com/llvm/llvm-project/issues/108004
crash
512cecad4c384c84b79fea050a755cb7e46c6ac5
2024-09-10T11:32:26
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "7858e14547c509c95503b74ff8ffc7bf2fc5b110", "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": [ [ 8663, 8668 ] ], "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": [ "collectUsersInExitBlock" ], "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 7858e14547c509c95503b74ff8ffc7bf2fc5b110 Author: Hari Limaye <[email protected]> Date: Wed Sep 11 16:43:34 2024 +0100 [LV] Amend check for IV increments in collectUsersInEntryBlock (#108020) The check for IV increments in collectUsersInEntryBlock currently triggers for exit-block PHIs which use the IV start value, resulting in us failing to add the input value for the middle block to these PHIs. Fix this by amending the check for IV increments to only include incoming values that are instructions inside the loop. Fixes #108004 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b821da03c16e..640a7bf3d672 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8663,6 +8663,7 @@ static MapVector<PHINode *, VPValue *> collectUsersInExitBlock( !cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst()) || isa<VPWidenPointerInductionRecipe>(V) || (isa<Instruction>(IncomingValue) && + OrigLoop->contains(cast<Instruction>(IncomingValue)) && any_of(IncomingValue->users(), [&Inductions](User *U) { auto *P = dyn_cast<PHINode>(U); return P && Inductions.contains(P);
[ { "file": "llvm/test/Transforms/LoopVectorize/use-iv-start-value.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S" ], "tests": [ { "test_name": "foo", "test_body": "define i64 @foo(ptr %p1, ptr %p2, i64 %start, i64 %end) {\nentry:\n %start2 = and i64 %start, 12345\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %ind = phi i64 [ %start2, %entry ], [ %ind.next, %for.body ]\n %arrayidx1 = getelementptr inbounds i32, ptr %p1, i64 %ind\n %0 = load i32, ptr %arrayidx1, align 4\n %arrayidx2 = getelementptr inbounds i32, ptr %p2, i64 %ind\n %1 = load i32, ptr %arrayidx2, align 4\n %ind.next = add i64 %ind, 1\n %cmp = icmp ne i64 %ind.next, %end\n br i1 %cmp, label %for.body, label %exit\n\nexit: ; preds = %for.body\n %use = phi i64 [ %start2, %for.body ]\n ret i64 %use\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[LoopVectorize] Assertion fails when IV start value is used by an exit block PHI", "body": "With the following IR:\r\n```\r\ndefine i64 @foo(i64 %start, i64 %end) {\r\nentry:\r\n %p1 = alloca [1024 x i32]\r\n %p2 = alloca [1024 x i32]\r\n call void @init_mem(ptr %p1, i64 1024)\r\n call void @init_mem(ptr %p2, i64 1024)\r\n %start2 = and i64 %start, 12345\r\n br label %for.body\r\n\r\nfor.body:\r\n %ind = phi i64 [ %ind.next, %for.body ], [ %start2, %entry ]\r\n %arrayidx1 = getelementptr inbounds i32, ptr %p1, i64 %ind\r\n %0 = load i32, ptr %arrayidx1, align 4\r\n %arrayidx2 = getelementptr inbounds i32, ptr %p2, i64 %ind\r\n %1 = load i32, ptr %arrayidx2, align 4\r\n %ind.next = add i64 %ind, 1\r\n %cmp = icmp ne i64 %ind.next, %end\r\n br i1 %cmp, label %for.body, label %exit\r\n\r\nexit:\r\n %use = phi i64 [ %start2, %for.body ]\r\n ret i64 %use\r\n}\r\n\r\ndeclare void @init_mem(ptr, i64)\r\n```\r\n\r\nLV crashes due to hitting the following assertion:\r\n```\r\nLV: Vectorizing: innermost loop.\r\nPHINode should have one entry for each predecessor of its parent basic block!\r\n %bob = phi i64 [ %start2, %for.body ]\r\nopt: /work/llvm-project-wt/nuw-clang-arr/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10244: bool llvm::LoopVectorizePass::processLoop(Loop *): Assertion `!verif\r\nyFunction(*L->getHeader()->getParent(), &dbgs())' 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: ./build/bin/opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=4 -debug test.ll -o - -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"test.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"foo\"\r\n #0 0x0000aaaaaec431c0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./build/bin/opt+0x41a31c0)\r\n #1 0x0000aaaaaec4102c llvm::sys::RunSignalHandlers() (./build/bin/opt+0x41a102c)\r\n #2 0x0000aaaaaec438dc SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000fffff7ffb9d0 (linux-vdso.so.1+0x9d0)\r\n #4 0x0000fffff7b5f200 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000fffff7b1a67c gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #6 0x0000fffff7b07130 abort ./stdlib/abort.c:81:7\r\n #7 0x0000fffff7b13fd0 __assert_fail_base ./assert/assert.c:89:7\r\n #8 0x0000fffff7b14040 __assert_perror_fail ./assert/assert-perr.c:31:1\r\n #9 0x0000aaaaadee375c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (./build/bin/opt+0x344375c)\r\n#10 0x0000aaaaadee72d0 llvm::LoopVectorizePass::runImpl(llvm::Function&) (./build/bin/opt+0x34472d0)\r\n#11 0x0000aaaaadee7ac0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./build/bin/opt+0x3447ac0)\r\n#12 0x0000aaaaaea9676c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./bui\r\nld/bin/opt+0x3ff676c)\r\n#13 0x0000aaaaaea9a1fc llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./build/bin/opt+0x3ffa1fc)\r\n#14 0x0000aaaaaea958cc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./build/bin/o\r\npt+0x3ff58cc)\r\n#15 0x0000aaaaab5b3d88 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOu\r\ntputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::Outpu\r\ntKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (./build/bin/opt+0xb13d88)\r\n#16 0x0000aaaaab5a7fc0 optMain (./build/bin/opt+0xb07fc0)\r\n#17 0x0000fffff7b073fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\r\n#18 0x0000fffff7b074cc call_init ./csu/../csu/libc-start.c:128:20\r\n#19 0x0000fffff7b074cc __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#20 0x0000aaaaab5a1ef0 _start (./build/bin/opt+0xb01ef0)\r\n```\r\n\r\nSeems like we fail to properly handle fixing up the incoming value for this PHI from the middle block. ", "author": "hazzlim", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "hazzlim", "body": "Note: I am actively looking into this and plan to put up a fix " } ] }
true
null
120361
https://github.com/llvm/llvm-project/issues/120361
miscompilation
c6967efe780d6cc5d70fc8cadbd227353b6768f1
2024-12-18T05:27:30
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "6f68010f9123aae9f6f105d7a11af22458518ad7", "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": [ [ 455, 468 ] ], "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": [ "foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed" ], "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 6f68010f9123aae9f6f105d7a11af22458518ad7 Author: Yingwei Zheng <[email protected]> Date: Wed Dec 18 20:40:33 2024 +0800 [InstCombine] Drop samesign flags in `foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed` (#120373) Counterexamples: https://alive2.llvm.org/ce/z/6Ks8Qz Closes https://github.com/llvm/llvm-project/issues/120361. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index dff9304be64d..e576eea4ca36 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -455,14 +455,20 @@ static Value *foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed( // RHS. For example, // (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8). // (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8). - if (IsSuperSetOrEqual(BCst, DCst)) + if (IsSuperSetOrEqual(BCst, DCst)) { + // We can't guarantee that samesign hold after this fold. + RHS->setSameSign(false); return RHS; + } // Otherwise, B is a subset of D. If B and E have a common bit set, // ie. (B & E) != 0, then LHS is subsumed by RHS. For example. // (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8). assert(IsSubSetOrEqual(BCst, DCst) && "Precondition due to above code"); - if ((*BCst & ECst) != 0) + if ((*BCst & ECst) != 0) { + // We can't guarantee that samesign hold after this fold. + RHS->setSameSign(false); return RHS; + } // Otherwise, LHS and RHS contradict and the whole expression becomes false // (or true if negated.) For example, // (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.
[ { "file": "llvm/test/Transforms/InstCombine/icmp-logical.ll", "commands": [ "opt -passes=instcombine -S -o - %s" ], "tests": [ { "test_name": "pr120361", "test_body": "define i1 @pr120361(i8 %x, i8 %y) {\n %cmp1 = icmp samesign eq i8 %x, -1\n %cmp2 = icmp ne i8 %x, 0\n %result = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %result\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr120361_v2", "test_body": "define i1 @pr120361_v2(i32 %x) {\n %and1 = and i32 %x, 15\n %cmp1 = icmp ne i32 %and1, 0\n %and2 = and i32 %x, -113\n %cmp2 = icmp samesign eq i32 %and2, 15\n %and = select i1 %cmp1, i1 %cmp2, i1 false\n ret i1 %and\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "masked_icmps_bmask_notmixed_not_subset_notoptimized", "test_body": "define i1 @masked_icmps_bmask_notmixed_not_subset_notoptimized(i32 %A) {\n %mask1 = and i32 %A, 254\n %tst1 = icmp ne i32 %mask1, 252\n %mask2 = and i32 %A, 253\n %tst2 = icmp ne i32 %mask2, 252\n %res = and i1 %tst1, %tst2\n ret i1 %res\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] `samesign` should be dropped when folding logical and of icmps", "body": "Reproducer: https://alive2.llvm.org/ce/z/YSW_NC\n```\ndefine i1 @src(i8 %0, i8 %1) {\nstart:\n %2 = icmp samesign eq i8 %0, -1\n %3 = icmp ne i8 %0, 0\n %4 = icmp ugt i8 %0, %0\n %result = select i1 %3, i1 %2, i1 %4\n ret i1 %result\n}\n\ndefine i1 @tgt(i8 %0, i8 %1) {\nstart:\n %2 = icmp samesign eq i8 %0, -1\n ret i1 %2\n}\n```\n```\n\n----------------------------------------\ndefine i1 @src(i8 %#0, i8 %#1) {\nstart:\n %#2 = icmp samesign eq i8 %#0, 255\n %#3 = icmp ne i8 %#0, 0\n %#4 = icmp ugt i8 %#0, %#0\n %result = select i1 %#3, i1 %#2, i1 %#4\n ret i1 %result\n}\n=>\ndefine i1 @tgt(i8 %#0, i8 %#1) {\nstart:\n %#2 = icmp samesign eq i8 %#0, 255\n ret i1 %#2\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\ni8 %#0 = #x00 (0)\ni8 %#1 = poison\n\nSource:\ni1 %#2 = poison\ni1 %#3 = #x0 (0)\ni1 %#4 = #x0 (0)\ni1 %result = #x0 (0)\n\nTarget:\ni1 %#2 = poison\nSource value: #x0 (0)\nTarget value: poison\n```\nReported by https://github.com/dtcxzyw/llvm-mutation-based-fuzz-service/issues/14 while reviewing https://github.com/llvm/llvm-project/pull/120177.\n\n\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
101213
https://github.com/llvm/llvm-project/issues/101213
crash
8364a6e108faea1a6f05f7bb53720a6fc101fed2
2024-07-30T18:00:09
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "f70f1228035c9610de38e0e376afdacb647c4ad9", "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": [ [ 13909, 13919 ] ], "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" ], "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 f70f1228035c9610de38e0e376afdacb647c4ad9 Author: Alexey Bataev <[email protected]> Date: Tue Jul 30 14:02:51 2024 -0700 [SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value. When trying to reuse extractelement instruction, need to check that it is inserted into proper position. Its original vector operand should come before new vector value, otherwise new extractelement instruction must be generated. Fixes https://github.com/llvm/llvm-project/issues/101213 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 6501a14d8778..cf87b8621027 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13909,11 +13909,16 @@ Value *BoUpSLP::vectorizeTree( } if (!Ex) { // "Reuse" the existing extract to improve final codegen. - if (auto *ES = dyn_cast<ExtractElementInst>(Scalar)) { + if (auto *ES = dyn_cast<ExtractElementInst>(Scalar); + ES && isa<Instruction>(Vec)) { Value *V = ES->getVectorOperand(); if (const TreeEntry *ETE = getTreeEntry(V)) V = ETE->VectorizedValue; - Ex = Builder.CreateExtractElement(V, ES->getIndexOperand()); + if (auto *IV = dyn_cast<Instruction>(V); + !IV || IV == Vec || IV->comesBefore(cast<Instruction>(Vec))) + Ex = Builder.CreateExtractElement(V, ES->getIndexOperand()); + else + Ex = Builder.CreateExtractElement(Vec, Lane); } else if (ReplaceGEP) { // Leave the GEPs as is, they are free in most cases and better to // keep them as GEPs.
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/extract-vectorized-operand.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 %0 = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> zeroinitializer, <2 x i32> <i32 1, i32 0>\n %1 = extractelement <2 x ptr addrspace(1)> %0, i32 0\n %2 = extractelement <2 x ptr addrspace(1)> %0, i32 1\n br label %bb43\n\nbb20: ; No predecessors!\n br label %bb105\n\nbb43: ; preds = %bb51, %bb\n %phi441 = phi ptr addrspace(1) [ %4, %bb51 ], [ %2, %bb ]\n %phi452 = phi ptr addrspace(1) [ %5, %bb51 ], [ %1, %bb ]\n br i1 false, label %bb105, label %bb51\n\nbb51: ; preds = %bb54, %bb43\n %3 = phi <2 x ptr addrspace(1)> [ poison, %bb54 ], [ zeroinitializer, %bb43 ]\n %4 = extractelement <2 x ptr addrspace(1)> %3, i32 0\n %5 = extractelement <2 x ptr addrspace(1)> %3, i32 1\n br label %bb43\n\nbb54: ; No predecessors!\n br label %bb51\n\nbb105: ; preds = %bb43, %bb20\n %phi106 = phi ptr addrspace(1) [ %1, %bb20 ], [ null, %bb43 ]\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run the following test with -passes slp-vectorizer -slp-threshold=-99999\r\n[Test.ll.tgz](https://github.com/user-attachments/files/16431764/Test.ll.tgz)\r\n\r\nReproducer : https://godbolt.org/z/GW41a7WP6\r\n\r\nStack dump:\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = shufflevector <2 x ptr addrspace(1)> %0, <2 x ptr addrspace(1)> poison, <2 x i32> <i32 1, i32 0>\r\n %1 = extractelement <2 x ptr addrspace(1)> %2, i32 0\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.\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 \"verify\" on module \"<source>\"\r\n #0 0x0000000004eff778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eff778)\r\n #1 0x0000000004efceec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c0269e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c0269e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c0269e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c0269e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b3ff7 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004e396a8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e396a8)\r\n #8 0x0000000004d360f0 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d360f0)\r\n #9 0x00000000008d865e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d865e)\r\n#10 0x0000000004cf9c90 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cf9c90)\r\n#11 0x00000000008e33d2 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+0x8e33d2)\r\n#12 0x00000000008d62fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d62fc)\r\n#13 0x00007c0269e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007c0269e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008cd75e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cd75e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "llvm:crash" ], "comments": [ { "author": "Zentrik", "body": "@alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking f70f1228035c9610de38e0e376afdacb647c4ad9 but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. \r\nI can create an IR reproducer for that failure if need be.\r\nThank you.\r\n\r\nEDIT: Would just adding a check that they're in the same basic block work?" }, { "author": "alexey-bataev", "body": "> @alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking [f70f122](https://github.com/llvm/llvm-project/commit/f70f1228035c9610de38e0e376afdacb647c4ad9) but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. I can create an IR reproducer for that failure if need be. Thank you.\r\n> \r\n> EDIT: Would just adding a check that they're in the same basic block work?\r\n\r\nYes, check for the same parent should fix it" } ] }
true
null
121428
https://github.com/llvm/llvm-project/issues/121428
miscompilation
b5f21671ef04984bc00770263234dfb94833a274
2025-01-01T09:27:44
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a37dbc1f51c70d92fd209c2e52a9d794eb15e4e7", "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": [ [ 1225, 1232 ] ], "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": [ "foldSelectCttzCtlz" ], "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 a37dbc1f51c70d92fd209c2e52a9d794eb15e4e7 Author: Yingwei Zheng <[email protected]> Date: Mon Jan 6 00:04:28 2025 +0800 [InstCombine] Drop noundef in `foldSelectCttzCtlz` (#121692) Close https://github.com/llvm/llvm-project/issues/121428 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index e7a8e947705f..a18b927678ef 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1225,8 +1225,12 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal, // zext/trunc) have one use (ending at the select), the cttz/ctlz result will // not be used if the input is zero. Relax to 'zero is poison' for that case. if (II->hasOneUse() && SelectArg->hasOneUse() && - !match(II->getArgOperand(1), m_One())) + !match(II->getArgOperand(1), m_One())) { II->setArgOperand(1, ConstantInt::getTrue(II->getContext())); + // noundef attribute on the intrinsic may no longer be valid. + II->dropUBImplyingAttrsAndMetadata(); + IC.addToWorklist(II); + } return nullptr; }
[ { "file": "llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll", "commands": [ "opt -passes=instcombine -S < %s" ], "tests": [ { "test_name": "test_cttz_not_bw_multiuse", "test_body": "define i32 @test_cttz_not_bw_multiuse(i32 %x) {\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %sel = select i1 %cmp, i32 %ct, i32 123\n %res = or i32 %sel, %ct\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": "test_cttz_not_bw", "test_body": "define i32 @test_cttz_not_bw(i32 %x) {\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\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": "test_cttz_not_bw_noundef", "test_body": "define i32 @test_cttz_not_bw_noundef(i32 %x) {\n %ct = tail call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\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", "body": "Alive2: https://alive2.llvm.org/ce/z/wKsUWK\n```\ndefine i32 @src(i32 noundef %x) {\n %ct = call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\n ret i32 %res\n}\ndefine i32 @tgt(i32 noundef %x) {\n %ct = call noundef range(i32 0, 33) i32 @llvm.cttz.i32(i32 %x, i1 true)\n %cmp.not = icmp eq i32 %x, 0\n %res = select i1 %cmp.not, i32 123, i32 %ct\n ret i32 %res\n}\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
124526
https://github.com/llvm/llvm-project/issues/124526
crash
e14962a39cc6476bebba65e5639b74b0318c7fc3
2025-01-27T10:24:37
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "212f344b84b400c0a9dedfa3c1ec6af9d9d30223", "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": [ [ 732, 738 ] ], "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": [ "tryFactorization" ], "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 212f344b84b400c0a9dedfa3c1ec6af9d9d30223 Author: Nikita Popov <[email protected]> Date: Mon Jan 27 16:24:15 2025 +0100 [InstCombine] Handle constant expression result in tryFactorization() If IRBuilder folds the result to a constant expression, don't try to set nowrap flags on it. Fixes https://github.com/llvm/llvm-project/issues/124526. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index cad17c511b6d..a64c188575e6 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -732,7 +732,7 @@ static Value *tryFactorization(BinaryOperator &I, const SimplifyQuery &SQ, RetVal->takeName(&I); // Try to add no-overflow flags to the final value. - if (isa<OverflowingBinaryOperator>(RetVal)) { + if (isa<BinaryOperator>(RetVal)) { bool HasNSW = false; bool HasNUW = false; if (isa<OverflowingBinaryOperator>(&I)) {
[ { "file": "llvm/test/Transforms/InstCombine/add2.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "mul_add_to_mul_9", "test_body": "define i16 @mul_add_to_mul_9(i16 %a) {\n %mul1 = mul nsw i16 %a, 16384\n %mul2 = mul nsw i16 %a, 16384\n %add = add nsw i16 %mul1, %mul2\n ret i16 %add\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "shl_add_to_shl_constexpr", "test_body": "@g = external global i8\n\ndefine i32 @shl_add_to_shl_constexpr() {\n %shl = shl i32 ptrtoint (ptr @g to i32), 1\n %add = add i32 %shl, %shl\n ret i32 %add\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Crash at -O2: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.", "body": "This code crashes at `-O2`:\n\n```c\nint a, b;\nvoid c();\nint d(int e) {\n if (e)\n return 3;\n return 2;\n}\nint f(int e) {\n int i = d(e) + e;\n return i;\n}\nint j(int e) {\n static char g;\n char *h = &g;\n a = h - \"\";\n b = a << e;\n return f(b - 7) + 303 + b;\n}\nvoid k() {\n int l = j(4);\n c(l);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/4h9PrKG8z\n\nCrash:\n\n```console\nclang: /root/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.\n```\n\nBacktrace:\n\n```console\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 -Wextra -Wall <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>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,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>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,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,constraint-elimination,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,extra-simple-loop-unswitch-passes,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;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>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,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>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,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,constraint-elimination,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,extra-simple-loop-unswitch-passes,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;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>\"\n5.\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"k\"\n #0 0x0000000003def1b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3def1b8)\n #1 0x0000000003dece74 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dece74)\n #2 0x0000000003d39368 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x0000789749042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007897490969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x0000789749042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007897490287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x000078974902871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x0000789749039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000000000d8d74a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd8d74a)\n#10 0x0000000003935620 tryFactorization(llvm::BinaryOperator&, llvm::SimplifyQuery const&, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderCallbackInserter>&, llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*) InstructionCombining.cpp:0:0\n#11 0x0000000003935ce2 llvm::InstCombinerImpl::tryFactorizationFolds(llvm::BinaryOperator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3935ce2)\n#12 0x0000000003935d67 llvm::InstCombinerImpl::foldUsingDistributiveLaws(llvm::BinaryOperator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3935d67)\n#13 0x0000000003972ab2 llvm::InstCombinerImpl::visitAdd(llvm::BinaryOperator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3972ab2)\n#14 0x00000000039586c1 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39586c1)\n#15 0x000000000395a066 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&) (.isra.0) InstructionCombining.cpp:0:0\n#16 0x000000000395b52c llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x395b52c)\n#17 0x0000000004094a6e llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4094a6e)\n#18 0x0000000003796c50 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3796c50)\n#19 0x000000000114aa4e 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+0x114aa4e)\n#20 0x0000000002c71112 llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c71112)\n#21 0x000000000114aede 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-assertions-trunk/bin/clang+0x114aede)\n#22 0x0000000002c68502 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+0x2c68502)\n#23 0x000000000548dd6e 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+0x548dd6e)\n#24 0x0000000002c6dbd6 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+0x2c6dbd6)\n#25 0x000000000548dd8e 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+0x548dd8e)\n#26 0x0000000002c6ba86 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c6ba86)\n#27 0x000000000548dd4e 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+0x548dd4e)\n#28 0x0000000003794f70 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3794f70)\n#29 0x00000000056e3783 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x56e3783)\n#30 0x000000000532b69e 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+0x532b69e)\n#31 0x0000000003794f70 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3794f70)\n#32 0x00000000040a7734 (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#33 0x00000000040ab13e 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+0x40ab13e)\n#34 0x000000000477edb0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x477edb0)\n#35 0x00000000067c259c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67c259c)\n#36 0x000000000477f1b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x477f1b8)\n#37 0x0000000004a44575 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a44575)\n#38 0x00000000049c72ae clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49c72ae)\n#39 0x0000000004b31ede clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b31ede)\n#40 0x0000000000cfcd0f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcfcd0f)\n#41 0x0000000000cf47aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#42 0x00000000047c5ae9 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#43 0x0000000003d39814 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d39814)\n#44 0x00000000047c60df 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#45 0x0000000004788f4d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4788f4d)\n#46 0x0000000004789fce 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+0x4789fce)\n#47 0x0000000004791b05 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4791b05)\n#48 0x0000000000cf9b23 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcf9b23)\n#49 0x0000000000bc2a84 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbc2a84)\n#50 0x0000789749029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#51 0x0000789749029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#52 0x0000000000cf4255 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcf4255)\n```", "author": "cardigan1008", "labels": [ "crash", "llvm:instcombine", "regression:19" ], "comments": [ { "author": "shafik", "body": "Looks like a clang-19 regression: https://godbolt.org/z/EvWdTGY6E" }, { "author": "nikic", "body": "```llvm\n; RUN: opt -passes=instcombine < %s\n@g = external global i8\n\ndefine i32 @test() {\n %shl = shl i32 ptrtoint (ptr @g to i32), 1\n %add1 = add i32 %shl, -1\n %add2 = add i32 %shl, 2\n %add3 = add i32 %add1, %add2\n ret i32 %add3 \n} \n```" }, { "author": "nikic", "body": "Further reduced:\n```llvm\n@g = external global i8\n\ndefine i32 @test() {\n %shl = shl i32 ptrtoint (ptr @g to i32), 1\n %add = add i32 %shl, %shl\n ret i32 %add \n} \n```" } ] }
true
null
111042
https://github.com/llvm/llvm-project/issues/111042
crash
67c0846357bcd6faca713315380f9981a805a6e5
2024-10-03T18:44:33
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "68210c7c269b7b7325dedaea7cea9fe9d979fab5", "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": [ [ 2185, 2190 ] ], "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": [ "VPPredInstPHIRecipe::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 68210c7c269b7b7325dedaea7cea9fe9d979fab5 Author: Florian Hahn <[email protected]> Date: Sat Oct 5 19:15:05 2024 +0100 [VPlan] Only generate first lane for VPPredInstPHI if no others used. IF only the first lane of the result is used, only generate the first lane. Fixes https://github.com/llvm/llvm-project/issues/111042. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 0d092b9c10ac..376b3d33be76 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2185,6 +2185,9 @@ void VPPredInstPHIRecipe::execute(VPTransformState &State) { // predicated iteration inserts its generated value in the correct vector. State.reset(getOperand(0), VPhi); } else { + if (vputils::onlyFirstLaneUsed(this) && !State.Lane->isFirstLane()) + return; + Type *PredInstType = getOperand(0)->getUnderlyingValue()->getType(); PHINode *Phi = State.Builder.CreatePHI(PredInstType, 2); Phi->addIncoming(PoisonValue::get(ScalarPredInst->getType()),
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/divs-with-tail-folding.ll", "commands": [ "opt -p loop-vectorize -mtriple x86_64 -prefer-predicate-over-epilogue=predicate-dont-vectorize -mcpu=skylake-avx512 -S %s" ], "tests": [ { "test_name": "sdiv_feeding_gep_predicated", "test_body": "define void @sdiv_feeding_gep_predicated(ptr %dst, i32 %x, i64 %M, i64 %conv6, i64 %N) {\nentry:\n %conv61 = zext i32 %x to i64\n br label %loop\n\nloop: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c = icmp ule i64 %iv, %M\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop\n %div18 = sdiv i64 %M, %conv6\n %conv20 = trunc i64 %div18 to i32\n %mul30 = mul i64 %div18, %conv61\n %sub31 = sub i64 %iv, %mul30\n %conv34 = trunc i64 %sub31 to i32\n %mul35 = mul i32 %x, %conv20\n %add36 = add i32 %mul35, %conv34\n %idxprom = sext i32 %add36 to i64\n %gep = getelementptr double, ptr %dst, i64 %idxprom\n store double 0.000000e+00, ptr %gep, align 8\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop\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.latch\n ret void\n}\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": "pr70590_recipe_without_underlying_instr", "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@c = external global [5 x i8]\n\ndefine void @pr70590_recipe_without_underlying_instr(i64 %n, ptr noalias %dst) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %inc, %loop.latch ]\n %cmp = icmp eq i64 %iv, %n\n br i1 %cmp, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %rem = srem i64 3, 0\n %add3 = add i64 %rem, -3\n %add5 = add i64 %iv, %add3\n %gep = getelementptr [5 x i8], ptr @c, i64 0, i64 %add5\n %l = load i8, ptr %gep, align 1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %sr = phi i8 [ 0, %loop.header ], [ %l, %then ]\n %gep.dst = getelementptr i8, ptr %dst, i64 %iv\n store i8 %sr, ptr %gep.dst, align 4\n %inc = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %inc, 4\n br i1 %exitcond.not, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/replicate-recipe-with-only-first-lane-used.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s" ], "tests": [ { "test_name": "replicate_udiv_with_only_first_lane_used", "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 @replicate_udiv_with_only_first_lane_used(i32 %x, ptr %dst, i64 %d) {\nentry:\n %c = icmp eq i32 %x, 10\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 true, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %div.i = udiv i64 99, %d\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %retval.0.i = phi i64 [ %div.i, %else ], [ 0, %loop.header ]\n %gep = getelementptr i16, ptr %dst, i64 %retval.0.i\n store i16 0, ptr %gep, align 2\n %iv.next = add i64 %iv, 1\n %cmp = icmp ult i64 %iv.next, 101\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Assertion failed in VPlan.cpp:258", "body": "When I compiled the code with -O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\nstatic uint8_t c[] = {1};\r\nvoid a();\r\nlong b(int h) {\r\n long d = 0;\r\n if (h < 0)\r\n return -1;\r\n int e = 0;\r\n for (int f = 0; f <= h; f++) {\r\n e++;\r\n d += f;\r\n }\r\n long a = d / e;\r\n return a;\r\n}\r\nvoid g();\r\nuint8_t i() {\r\n uint16_t k[4];\r\n int f;\r\n for (; g + f < 4; f++)\r\n k[b(c[0] - 1)] = 5;\r\n for (; f; a(k))\r\n ;\r\n uint8_t *l[3][3], j;\r\n l[0][j] = c;\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:258: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def) || !vputils::onlyFirstLaneUsed(Def) || (hasScalarValue(Def, VPLane(0)) && Data.VPV2Scalars[Def].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/fTrKKha5E", "author": "cardigan1008", "labels": [ "vectorizers", "crash", "regression:19" ], "comments": [ { "author": "shafik", "body": "Looks like a clang-19 regression: https://godbolt.org/z/6d3edKn86" } ] }
true
null
78621
https://github.com/llvm/llvm-project/issues/78621
miscompilation
90ba33099cbb17e7c159e9ebc5a512037db99d6d
2024-01-18T20:57:06
[ "llvm/test/Transforms/ConstraintElimination" ]
{ "fix_commit": "3d91d9613e294b242d853039209b40a0cb7853f2", "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": [ [ 1061, 1071 ] ], "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::addInfoFor" ], "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 3d91d9613e294b242d853039209b40a0cb7853f2 Author: Florian Hahn <[email protected]> Date: Wed Jan 24 14:25:54 2024 +0000 [ConstraintElim] Make sure min/max intrinsic results are not poison. The result of umin may be poison and in that case the added constraints are not be valid in contexts where poison doesn't cause UB. Only queue facts for min/max intrinsics if the result is guaranteed to not be poison. This could be improved in the future, by only adding the fact when solving conditions using the result value. Fixes https://github.com/llvm/llvm-project/issues/78621. diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 8f09569d0d9c..7b672e89b67a 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1061,11 +1061,16 @@ void State::addInfoFor(BasicBlock &BB) { FactOrCheck::getCheck(DT.getNode(&BB), cast<CallInst>(&I))); break; // Enqueue the intrinsics to add extra info. - case Intrinsic::abs: case Intrinsic::umin: case Intrinsic::umax: case Intrinsic::smin: case Intrinsic::smax: + // TODO: Check if it is possible to instead only added the min/max facts + // when simplifying uses of the min/max intrinsics. + if (!isGuaranteedNotToBePoison(&I)) + break; + [[fallthrough]]; + case Intrinsic::abs: WorkList.push_back(FactOrCheck::getInstFact(DT.getNode(&BB), &I)); break; }
[ { "file": "llvm/test/Transforms/ConstraintElimination/minmax.ll", "commands": [ "opt -passes=constraint-elimination -S %s" ], "tests": [ { "test_name": "smin_branchless", "test_body": "define i1 @smin_branchless(i32 %x, i32 %y) {\nentry:\n %min = call i32 @llvm.smin.i32(i32 %x, i32 %y)\n %cmp1 = icmp sle i32 %min, %x\n %cmp2 = icmp sgt i32 %min, %x\n %ret = xor i1 %cmp1, %cmp2\n ret i1 %ret\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/ConstraintElimination/umin-result-may-be-poison.ll", "commands": [ "opt -p constraint-elimination -S %s" ], "tests": [ { "test_name": "umin_poison_call_before_UB", "test_body": "define i1 @umin_poison_call_before_UB(i32 %arg) {\n %icmp = icmp slt i32 %arg, 0\n %shl = shl nuw nsw i32 %arg, 3\n %min = call i32 @llvm.umin.i32(i32 %shl, i32 80)\n call void @fn()\n call void @noundef(i32 noundef %min)\n %cmp2 = shl nuw nsw i32 %arg, 3\n ret i1 %icmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\ndeclare void @noundef(i32 noundef)\n\ndeclare void @fn()\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "umin_not_used", "test_body": "define i1 @umin_not_used(i32 %arg) {\n %icmp = icmp slt i32 %arg, 0\n %shl = shl nuw nsw i32 %arg, 3\n %1 = call i32 @llvm.umin.i32(i32 %shl, i32 80)\n %cmp2 = shl nuw nsw i32 %arg, 3\n ret i1 %icmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "umin_poison_is_UB_via_call", "test_body": "define i1 @umin_poison_is_UB_via_call(i32 %arg) {\n %icmp = icmp slt i32 %arg, 0\n %shl = shl nuw nsw i32 %arg, 3\n %min = call i32 @llvm.umin.i32(i32 %shl, i32 80)\n call void @noundef(i32 noundef %min)\n %cmp2 = shl nuw nsw i32 %arg, 3\n ret i1 %icmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\ndeclare void @noundef(i32 noundef)\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[ConstraintElimination] A miscompile in presence of `shl nuw nsw` and `llvm.umin`", "body": "The following commit: https://github.com/llvm/llvm-project/commit/71f56e49ceca75dbf82cbb9537c2545c2d2e51c9\r\nTriggered this miscompile: https://alive2.llvm.org/ce/z/oBg-u8\r\n\r\nNow `opt -passes=constraint-elimination -S` turns\r\n```\r\ndefine i1 @test(i32 %arg) {\r\n %icmp = icmp slt i32 %arg, 0\r\n %shl = shl nuw nsw i32 %arg, 3\r\n %call4 = call i32 @llvm.umin.i32(i32 %shl, i32 80)\r\n ret i1 %icmp\r\n}\r\n\r\ndeclare i32 @llvm.umin.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\ninto\r\n```\r\ndefine i1 @test(i32 %arg) {\r\n %shl = shl nuw nsw i32 %arg, 3\r\n %call4 = call i32 @llvm.umin.i32(i32 %shl, i32 80)\r\n ret i1 false\r\n}\r\n\r\ndeclare i32 @llvm.umin.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nGiven this debug output:\r\n```\r\nopt -passes=constraint-elimination before-constr-elim-renamed.ll -S -debug-only=constraint-elimination,constraint-system\r\nProcessing fact to add to the system: icmp ule i32 %call4, %shl\r\nAdding 'icmp ule i32 %call4, %shl'\r\n constraint: -8 * %arg + %call4 <= 0\r\n\r\n---\r\n-1 * %arg <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n8 * %arg <= -1\r\nunsat\r\nAdding 'icmp sge i32 %call4, 0'\r\n constraint: -1 * %call4 <= 0\r\n\r\nAdding 'icmp sle i32 %call4, %shl'\r\n constraint: -8 * %arg + %call4 <= 0\r\n\r\nProcessing fact to add to the system: icmp ule i32 %call4, 80\r\nAdding 'icmp ule i32 %call4, 80'\r\n constraint: %call4 <= 80\r\n\r\nAdding 'icmp sge i32 %call4, 0'\r\n constraint: -1 * %call4 <= 0\r\n\r\nAdding 'icmp sle i32 %call4, 80'\r\n constraint: %call4 <= 80\r\n\r\nTop of stack : 0 1\r\nCB: 0 1\r\nProcessing condition to simplify: %icmp = icmp slt i32 %arg, 0\r\nChecking %icmp = icmp slt i32 %arg, 0\r\n---\r\n-1 * %call4 <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n%call4 <= 80\r\n-1 * %arg <= 0\r\nsat\r\n---\r\n-1 * %call4 <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n%call4 <= 80\r\n%arg <= -1\r\nunsat\r\nCondition icmp sge i32 %arg, 0 implied by dominating constraints\r\n-1 * %call4 <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n%call4 <= 80\r\n```\r\nI'm not 100% sure if the aforementioned patch causes the miscompile, of if it merely triggers it on this specific reproducer. The fact that something like `-1 * %call4 <= 0` is reported as a \"dominating constraint\" seems suspicious to a person who's not familiar with the logic of ConstraintElimination and it doesn't look directly related to that patch. However, if I replace the `shl nuw nsw i32 %arg, 3\r\n` with `mul nuw nsw i32 %arg, 8`, the miscompile doesn't happen: https://alive2.llvm.org/ce/z/EL2bCh.", "author": "DaniilSuchkov", "labels": [ "miscompilation", "release:backport", "llvm:transforms" ], "comments": [ { "author": "nikic", "body": "From the debug log, I suspect that we're using the unsigned constraint system to prove a signed fact for some reason.\r\n\r\ncc @fhahn " }, { "author": "nikic", "body": "Okay, this is an interesting case.\r\n\r\nWe are adding an `icmp ule i32 %call4, %shl` fact, which get transferred as `icmp sge i32 %call4, 0` and `icmp sle i32 %call4, %shl` to the signed system, because `%shl` is known non-negative.\r\n\r\nThen we are checking whether a solution of these constraints plus `%arg <= -1` exists, which it does not.\r\n\r\nThis is \"correct\" in the sense that *if* that umin call returns a non-poison result, then `icmp slt i32 %arg, 0` is indeed known to be false. But we obviously can't actually make that assumption.\r\n\r\n@dtcxzyw @fhahn This makes me think that the way we are currently adding facts for MinMaxIntrinsic (and I guess abs as well) is pretty fundamentally incorrect, because it effectively imposes a constraint that the umin operation returns a well-defined value. Any thoughts on how to fix this without dropping support for them entirely?" }, { "author": "nikic", "body": "(The difference between shl and mul in the reproducer is because ValueTracking apparently currently doesn't know that mul nuw nsw is non-negative, but knows that shl nuw nsw is.)" }, { "author": "dtcxzyw", "body": "> @dtcxzyw @fhahn This makes me think that the way we are currently adding facts for MinMaxIntrinsic (and I guess abs as well) is pretty fundamentally incorrect, because it effectively imposes a constraint that the umin operation returns a well-defined value. Any thoughts on how to fix this without dropping support for them entirely?\r\n\r\nCan we conservatively check these intrinsics using `isGuaranteedNotToBePoison`?\r\n" }, { "author": "nikic", "body": "If it's not too complicated, I think a better solution would be to only add the intrinsic constraints when the result variable is added to the constraint system." }, { "author": "fhahn", "body": "> If it's not too complicated, I think a better solution would be to only add the intrinsic constraints when the result variable is added to the constraint system.\r\n\r\nOne way to do that would be to check the uses of the intrinsic and find all the branches that it feeds, and add it as fact for the successors." }, { "author": "nikic", "body": "@dtcxzyw Do you plan to submit a PR for this issue?" }, { "author": "dtcxzyw", "body": "> @dtcxzyw Do you plan to submit a PR for this issue?\r\n\r\nI will post a patch later." }, { "author": "fhahn", "body": "I've pushed a fix that only adds the facts if the result is guaranteed to not be poison so the mis-compile is fixed. I also added a TODO to improve things if possible.\r\n\r\nReopening so we can pick the fix for the release branch" }, { "author": "nikic", "body": "@fhahn Why does your fix only do this for min/max but not abs? Can't it have the same problem?" }, { "author": "fhahn", "body": "> @fhahn Why does your fix only do this for min/max but not abs? Can't it have the same problem?\r\n\r\nI wasn't able to come up with a problematic test case so far for `abs`, but there's a few more things to try." }, { "author": "DaniilSuchkov", "body": "@fhahn I'm not familiar with how this pass works, so I have a question: will this pass still use min/max/etc. to infer facts about the arguments of those intrinsics? I'm just a bit confused by the terminology: I see that it adds \"constraints\" based on things like `icmp`, which on their own don't actually constrain anything unless you branch on the result (or do something similar)." }, { "author": "nikic", "body": "> @fhahn I'm not familiar with how this pass works, so I have a question: will this pass still use min/max/etc. to infer facts about the arguments of those intrinsics? I'm just a bit confused by the terminology: I see that it adds \"constraints\" based on things like `icmp`, which on their own don't actually constrain anything unless you branch on the result (or do something similar).\r\n\r\nConstraints for icmps will only be added in branches that the icmp dominates (or code that an assume with an icmp dominates). The intrinsic handling was a bit special in that constraints are added unconditionally." } ] }
true
null
106083
https://github.com/llvm/llvm-project/issues/106083
crash
d075debc508898d5f365f8e909c54d6f4edada85
2024-08-26T14:36:57
[ "llvm/test/Transforms/DFAJumpThreading" ]
{ "fix_commit": "d4a38c8ff5c993e14c42895b51a47272fb03a857", "components": [ "DFAJumpThreading" ], "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": 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": [ [ 194, 200 ], [ 202, 207 ], [ 223, 254 ] ], "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": 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": [ "unfold" ], "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 d4a38c8ff5c993e14c42895b51a47272fb03a857 Author: Usman Nadeem <[email protected]> Date: Tue Sep 24 08:54:36 2024 -0700 [DFAJumpThreading] Handle select unfolding when user phi is not a dir… (#109511) …ect successor Previously the code assumed that the select instruction is defined in a block that is a direct predecessor of the block where the PHINode uses it. So, we were hitting an assertion when we tried to access the def block as an incoming block for the user phi node. This patch handles that case by using the correct end block and creating a new phi node that aggregates both the values of the select in that end block, and then using that new unfolded phi to overwrite the original user phi node. Fixes #106083 Change-Id: Ie471994cca232318f74a6e6438efa21e561c2dc0 diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp index ef9c264482a6..0e2b5c925a6a 100644 --- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp @@ -194,7 +194,6 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold, SelectInst *SI = SIToUnfold.getInst(); PHINode *SIUse = SIToUnfold.getUse(); BasicBlock *StartBlock = SI->getParent(); - BasicBlock *EndBlock = SIUse->getParent(); BranchInst *StartBlockTerm = dyn_cast<BranchInst>(StartBlock->getTerminator()); @@ -202,6 +201,7 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold, assert(SI->hasOneUse()); if (StartBlockTerm->isUnconditional()) { + BasicBlock *EndBlock = StartBlock->getUniqueSuccessor(); // Arbitrarily choose the 'false' side for a new input value to the PHI. BasicBlock *NewBlock = BasicBlock::Create( SI->getContext(), Twine(SI->getName(), ".si.unfold.false"), @@ -223,32 +223,44 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold, NewBlock->getFirstInsertionPt()); NewPhi->addIncoming(SIOp2, StartBlock); - if (auto *OpSi = dyn_cast<SelectInst>(SIOp1)) - NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, SIUse)); - if (auto *OpSi = dyn_cast<SelectInst>(SIOp2)) - NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, NewPhi)); - - // Update the phi node of SI. - for (unsigned Idx = 0; Idx < SIUse->getNumIncomingValues(); ++Idx) { - if (SIUse->getIncomingBlock(Idx) == StartBlock) - SIUse->setIncomingValue(Idx, SIOp1); + // Update any other PHI nodes in EndBlock. + for (PHINode &Phi : EndBlock->phis()) { + if (SIUse == &Phi) + continue; + Phi.addIncoming(Phi.getIncomingValueForBlock(StartBlock), NewBlock); } - SIUse->addIncoming(NewPhi, NewBlock); - // Update any other PHI nodes in EndBlock. - for (auto II = EndBlock->begin(); PHINode *Phi = dyn_cast<PHINode>(II); - ++II) { - if (Phi != SIUse) - Phi->addIncoming(Phi->getIncomingValueForBlock(StartBlock), NewBlock); + // Update the phi node of SI, which is its only use. + if (EndBlock == SIUse->getParent()) { + SIUse->addIncoming(NewPhi, NewBlock); + SIUse->replaceUsesOfWith(SI, SIOp1); + } else { + PHINode *EndPhi = PHINode::Create(SIUse->getType(), pred_size(EndBlock), + Twine(SI->getName(), ".si.unfold.phi"), + EndBlock->getFirstInsertionPt()); + for (BasicBlock *Pred : predecessors(EndBlock)) { + if (Pred != StartBlock && Pred != NewBlock) + EndPhi->addIncoming(EndPhi, Pred); + } + + EndPhi->addIncoming(SIOp1, StartBlock); + EndPhi->addIncoming(NewPhi, NewBlock); + SIUse->replaceUsesOfWith(SI, EndPhi); + SIUse = EndPhi; } - StartBlockTerm->eraseFromParent(); + if (auto *OpSi = dyn_cast<SelectInst>(SIOp1)) + NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, SIUse)); + if (auto *OpSi = dyn_cast<SelectInst>(SIOp2)) + NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, NewPhi)); // Insert the real conditional branch based on the original condition. + StartBlockTerm->eraseFromParent(); BranchInst::Create(EndBlock, NewBlock, SI->getCondition(), StartBlock); DTU->applyUpdates({{DominatorTree::Insert, StartBlock, EndBlock}, {DominatorTree::Insert, StartBlock, NewBlock}}); } else { + BasicBlock *EndBlock = SIUse->getParent(); BasicBlock *NewBlockT = BasicBlock::Create( SI->getContext(), Twine(SI->getName(), ".si.unfold.true"), EndBlock->getParent(), EndBlock);
[ { "file": "llvm/test/Transforms/DFAJumpThreading/dfa-jump-threading-transform.ll", "commands": [ "opt -S -passes=dfa-jump-threading %s" ], "tests": [ { "test_name": "test2", "test_body": "define i32 @test2(i32 %init) {\nentry:\n %cmp = icmp eq i32 %init, 0\n %sel = select i1 %cmp, i32 0, i32 2\n br label %loop.1\n\nloop.1: ; preds = %loop.1.backedge, %entry\n %state.1 = phi i32 [ %sel, %entry ], [ %state.1.be2, %loop.1.backedge ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2.backedge, %loop.1\n %state.2 = phi i32 [ %state.1, %loop.1 ], [ %state.2.be, %loop.2.backedge ]\n br label %loop.3\n\nloop.3: ; preds = %case2, %loop.2\n %state = phi i32 [ %state.2, %loop.2 ], [ 3, %case2 ]\n switch i32 %state, label %infloop.i [\n i32 2, label %case2\n i32 3, label %case3\n i32 4, label %case4\n i32 0, label %case0\n i32 1, label %case1\n ]\n\ncase2: ; preds = %loop.3\n br i1 %cmp, label %loop.3, label %loop.1.backedge\n\ncase3: ; preds = %loop.3\n br i1 %cmp, label %loop.2.backedge, label %case4\n\ncase4: ; preds = %case3, %loop.3\n br i1 %cmp, label %loop.2.backedge, label %loop.1.backedge\n\nloop.1.backedge: ; preds = %case4, %case2\n %state.1.be = phi i32 [ 2, %case4 ], [ 4, %case2 ]\n %state.1.be2 = select i1 %cmp, i32 1, i32 %state.1.be\n br label %loop.1\n\nloop.2.backedge: ; preds = %case4, %case3\n %state.2.be = phi i32 [ 3, %case4 ], [ 0, %case3 ]\n br label %loop.2\n\ncase0: ; preds = %loop.3\n br label %exit\n\ncase1: ; preds = %loop.3\n br label %exit\n\ninfloop.i: ; preds = %infloop.i, %loop.3\n br label %infloop.i\n\nexit: ; preds = %case1, %case0\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr106083_select_dead_uses", "test_body": "define void @pr106083_select_dead_uses(i1 %cmp1, i1 %not, ptr %p) {\nbb:\n %spec.select = select i1 %cmp1, i32 0, i32 1\n br label %.loopexit6\n\n.loopexit6: ; preds = %select.unfold, %bb\n br i1 %not, label %select.unfold, label %bb1\n\nbb1: ; preds = %.loopexit6\n %i = load i32, ptr %p, align 4\n %not2 = icmp eq i32 0, 0\n %spec.select7 = select i1 %not2, i32 %spec.select, i32 0\n br label %select.unfold\n\nselect.unfold: ; preds = %bb1, %.loopexit6\n %_2 = phi i32 [ 0, %.loopexit6 ], [ %spec.select7, %bb1 ]\n switch i32 %_2, label %bb2 [\n i32 0, label %.preheader.preheader\n i32 1, label %.loopexit6\n ]\n\n.preheader.preheader: ; preds = %select.unfold\n ret void\n\nbb2: ; preds = %select.unfold\n unreachable\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test1", "test_body": "define i32 @test1(i32 %num) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]\n switch i32 %state, label %for.inc [\n i32 1, label %case1\n i32 2, label %case2\n ]\n\ncase1: ; preds = %for.body\n br label %for.inc\n\ncase2: ; preds = %for.body\n %cmp = icmp eq i32 %count, 50\n %sel = select i1 %cmp, i32 1, i32 2\n br label %for.inc\n\nfor.inc: ; preds = %case2, %case1, %for.body\n %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]\n %inc = add nsw i32 %count, 1\n %cmp.exit = icmp slt i32 %inc, %num\n br i1 %cmp.exit, label %for.body, label %for.end\n\nfor.end: ; preds = %for.inc\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr106083_invalidBBarg_fold", "test_body": "define void @pr106083_invalidBBarg_fold(i1 %cmp1, i1 %cmp2, i1 %not, ptr %d) {\nbb:\n %sel = select i1 %cmp1, i32 0, i32 1\n br label %BB1\n\nBB1: ; preds = %BB1.backedge, %BB7, %bb\n %i = phi i16 [ 0, %BB1.backedge ], [ 0, %bb ], [ 1, %BB7 ]\n br i1 %not, label %BB7, label %BB2\n\nBB2: ; preds = %BB1\n store i16 0, ptr %d, align 2\n %spec.select = select i1 %cmp2, i32 %sel, i32 0\n br label %BB7\n\nBB7: ; preds = %BB2, %BB1\n %d.promoted4 = phi i16 [ 0, %BB1 ], [ 1, %BB2 ]\n %_3 = phi i32 [ 0, %BB1 ], [ %spec.select, %BB2 ]\n switch i32 %_3, label %BB1.backedge [\n i32 0, label %BB1\n i32 1, label %BB8\n ]\n\nBB1.backedge: ; preds = %BB7\n br label %BB1\n\nBB8: ; preds = %BB7\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "pr78059_bitwidth", "test_body": "define void @pr78059_bitwidth() {\n.split.preheader:\n br label %.split\n\n.split: ; preds = %.split, %.split.preheader\n %0 = phi i128 [ 0, %.split.preheader ], [ -1, %.split ]\n switch i128 %0, label %end [\n i128 -1, label %end\n i128 0, label %.split\n ]\n\nend: ; preds = %.split, %.split\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[DFAJumpThreading] crash since b167ada", "body": "Seeing many assertions that go away if I revert b167ada \"[DFAJumpThreading] Rewrite the way paths are enumerated (#96127)\".\r\n\r\n```\r\nclang-20 -cc1 -triple s390x-unknown-linux-gnu -target-cpu z15 -O3 -w -mllvm -enable-dfa-jump-thread -o /dev/null -emit-llvm -x ir tc_dfa-jt_invalidbbarg.ll\r\n...\r\n10 0x000002aa0a73e544 (anonymous namespace)::DFAJumpThreading::run\r\n...\r\n```\r\n\r\n```\r\nclang-20 -cc1 -triple s390x-unknown-linux-gnu -target-cpu z16 -O3 -w -mllvm -enable-dfa-jump-thread -o /dev/null -emit-llvm -x ir tc_select_mustbedeadnow.ll\r\n...\r\n#10 0x000002aa1b0c0968 llvm::DFAJumpThreadingPass::run\r\n...\r\n\r\n```\r\n[tcs_dfa-jt.tar.gz](https://github.com/user-attachments/files/16750050/tcs_dfa-jt.tar.gz)\r\n", "author": "JonPsson1", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "mikaelholmen", "body": "Perhaps the same assertion I reported here:\r\n https://github.com/llvm/llvm-project/pull/96127#issuecomment-2303862037\r\n?" }, { "author": "JonPsson1", "body": "> Perhaps the same assertion I reported here: [#96127 (comment)](https://github.com/llvm/llvm-project/pull/96127#issuecomment-2303862037) ?\r\n\r\nYes, same assertion, and in addition my second test case above triggered another assertion." } ] }
true
null
136430
https://github.com/llvm/llvm-project/issues/136430
miscompilation
1f69d6354a4b088bda5ee62c31411a75eead8b0c
2025-04-19T13:06:10
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a0c4876eede8e68de22dc5296b037556c7cca981", "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": [ [ 3929, 3944 ] ], "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 a0c4876eede8e68de22dc5296b037556c7cca981 Author: Yingwei Zheng <[email protected]> Date: Mon Apr 28 17:24:46 2025 +0800 [InstCombine] Fix ninf propagation for fcmp+sel -> minmax (#136433) Proof: https://alive2.llvm.org/ce/z/nCrvfr Closes https://github.com/llvm/llvm-project/issues/136430 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 5a42a5c996da..b5a40892694c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3929,16 +3929,20 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { if (match(&SI, m_OrdOrUnordFMax(m_Value(X), m_Value(Y)))) { Value *BinIntr = Builder.CreateBinaryIntrinsic(Intrinsic::maxnum, X, Y, &SI); - if (auto *BinIntrInst = dyn_cast<Instruction>(BinIntr)) + if (auto *BinIntrInst = dyn_cast<Instruction>(BinIntr)) { BinIntrInst->setHasNoNaNs(FCmp->hasNoNaNs()); + BinIntrInst->setHasNoInfs(FCmp->hasNoInfs()); + } return replaceInstUsesWith(SI, BinIntr); } if (match(&SI, m_OrdOrUnordFMin(m_Value(X), m_Value(Y)))) { Value *BinIntr = Builder.CreateBinaryIntrinsic(Intrinsic::minnum, X, Y, &SI); - if (auto *BinIntrInst = dyn_cast<Instruction>(BinIntr)) + if (auto *BinIntrInst = dyn_cast<Instruction>(BinIntr)) { BinIntrInst->setHasNoNaNs(FCmp->hasNoNaNs()); + BinIntrInst->setHasNoInfs(FCmp->hasNoInfs()); + } return replaceInstUsesWith(SI, BinIntr); } }
[ { "file": "llvm/test/Transforms/InstCombine/fcmp-fadd-select.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_fcmp_ogt_fadd_select_rewrite_flags2", "test_body": "define float @test_fcmp_ogt_fadd_select_rewrite_flags2(float %in) {\n %cmp1 = fcmp ogt float %in, 0.000000e+00\n %add = fadd float %in, 1.000000e+00\n %sel = select nnan nsz i1 %cmp1, float %add, float 1.000000e+00\n ret float %sel\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_fcmp_ogt_fadd_select_rewrite_and_fastmath", "test_body": "define float @test_fcmp_ogt_fadd_select_rewrite_and_fastmath(float %in) {\n %cmp1 = fcmp nnan ogt float %in, 0.000000e+00\n %add = fadd nnan ninf nsz float %in, 1.000000e+00\n %sel = select nnan ninf nsz i1 %cmp1, float %add, float 1.000000e+00\n ret float %sel\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": "maxnum_ogt_fmf_on_select", "test_body": "define float @maxnum_ogt_fmf_on_select(float %a, float %b) {\n %cond = fcmp ogt float %a, %b\n %f = select nnan nsz i1 %cond, float %a, float %b\n ret float %f\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "maxnum_oge_fmf_on_select", "test_body": "define <2 x float> @maxnum_oge_fmf_on_select(<2 x float> %a, <2 x float> %b) {\n %cond = fcmp oge <2 x float> %a, %b\n %f = select nnan ninf nsz <2 x i1> %cond, <2 x float> %a, <2 x float> %b\n ret <2 x float> %f\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "minnum_olt_fmf_on_select_both_ninf", "test_body": "define float @minnum_olt_fmf_on_select_both_ninf(float %a, float %b) {\n %cond = fcmp ninf olt float %a, %b\n %f = select nnan ninf nsz i1 %cond, float %a, float %b\n ret float %f\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "minnum_ole_fmf_on_select", "test_body": "define <2 x float> @minnum_ole_fmf_on_select(<2 x float> %a, <2 x float> %b) {\n %cond = fcmp ole <2 x float> %a, %b\n %f = select nnan ninf nsz <2 x i1> %cond, <2 x float> %a, <2 x float> %b\n ret <2 x float> %f\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "minnum_olt_fmf_on_select", "test_body": "define float @minnum_olt_fmf_on_select(float %a, float %b) {\n %cond = fcmp olt float %a, %b\n %f = select nnan nsz i1 %cond, float %a, float %b\n ret float %f\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "maxnum_no_nnan", "test_body": "define float @maxnum_no_nnan(float %a, float %b) {\n %cond = fcmp oge float %a, %b\n %f = select nsz i1 %cond, float %a, float %b\n ret float %f\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_max_ugt_2_use_cmp", "test_body": "declare void @foo(i1)\n\ndefine float @select_max_ugt_2_use_cmp(float %a, float %b) {\n %cmp = fcmp ugt float %a, %b\n call void @foo(i1 %cmp)\n %sel = select nnan ninf nsz i1 %cmp, float %a, float %b\n ret float %sel\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[InstCombine] ninf should not be propagated", "body": "Reproducer: https://alive2.llvm.org/ce/z/cmneUX\n```\ndefine half @test_fcmp_select_maxnum(half %x) {\n#0:\n %cmp2 = fcmp ogt half %x, 0x5bf8\n %sel2 = select nnan ninf nsz i1 %cmp2, half %x, half 0x5bf8\n ret half %sel2\n}\n=>\ndefine half @test_fcmp_select_maxnum(half %x) {\n#0:\n %sel2 = fmax ninf nsz half %x, 0x5bf8\n ret half %sel2\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\nhalf %x = #xfc00 (-oo)\n\nSource:\ni1 %cmp2 = #x0 (0)\nhalf %sel2 = #x5bf8 (255)\n\nTarget:\nhalf %sel2 = poison\nSource value: #x5bf8 (255)\nTarget value: poison\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [] }
true
null
78049
https://github.com/llvm/llvm-project/issues/78049
crash
de8f782355842a5d3ad44ad8861c53e3ef6fa73a
2024-01-13T16:38:44
[ "llvm/test/Transforms/MoveAutoInit" ]
{ "fix_commit": "26d3cd1d07ae3fc8312feb2ab3a3a86414f28c70", "components": [ "MoveAutoInit" ], "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": 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": [ [ 164, 169 ], [ 178, 186 ] ], "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": 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": [ "runMoveAutoInit" ], "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 26d3cd1d07ae3fc8312feb2ab3a3a86414f28c70 Author: XChy <[email protected]> Date: Tue Jan 16 18:45:44 2024 +0800 [MoveAutoInit] Ignore unreachable basicblocks and handle catchswitch (#78232) Fixes #78049 This patch has done: - Ignore unreachable predecessors when looking for nearest common dominator. - Check catchswitch with `getFirstNonPHI`, instead of `getFirstInsertionPt`. The latter skips EHPad. diff --git a/llvm/lib/Transforms/Utils/MoveAutoInit.cpp b/llvm/lib/Transforms/Utils/MoveAutoInit.cpp index a977ad87b79f..9a5dba219cee 100644 --- a/llvm/lib/Transforms/Utils/MoveAutoInit.cpp +++ b/llvm/lib/Transforms/Utils/MoveAutoInit.cpp @@ -164,6 +164,9 @@ static bool runMoveAutoInit(Function &F, DominatorTree &DT, MemorySSA &MSSA) { if (TransitiveSuccessors.count(Pred)) continue; + if (!DT.isReachableFromEntry(Pred)) + continue; + DominatingPredecessor = DominatingPredecessor ? DT.findNearestCommonDominator(DominatingPredecessor, Pred) @@ -178,9 +181,10 @@ static bool runMoveAutoInit(Function &F, DominatorTree &DT, MemorySSA &MSSA) { // CatchSwitchInst blocks can only have one instruction, so they are not // good candidates for insertion. - while (isa<CatchSwitchInst>(UsersDominator->getFirstInsertionPt())) { + while (isa<CatchSwitchInst>(UsersDominator->getFirstNonPHI())) { for (BasicBlock *Pred : predecessors(UsersDominator)) - UsersDominator = DT.findNearestCommonDominator(UsersDominator, Pred); + if (DT.isReachableFromEntry(Pred)) + UsersDominator = DT.findNearestCommonDominator(UsersDominator, Pred); } // We finally found a place where I can be moved while not introducing extra
[ { "file": "llvm/test/Transforms/MoveAutoInit/catchswitch.ll", "commands": [ "opt < %s -S -passes='move-auto-init' -verify-memoryssa" ], "tests": [ { "test_name": "test", "test_body": "declare void @dummy()\n\ndeclare void @dummy1()\n\ndefine void @test() personality ptr @dummy {\nentry:\n %p = alloca [2 x i16], i32 0, align 2\n store i32 0, ptr %p, align 2, !annotation !0\n br label %middle\n\nmiddle: ; preds = %entry\n %call = invoke ptr @dummy()\n to label %clean unwind label %catchbb\n\nclean: ; preds = %middle\n ret void\n\ncatchbb: ; preds = %middle\n %cs = catchswitch within none [label %pad, label %pad1] unwind to caller\n\npad: ; preds = %catchbb\n %c = catchpad within %cs [i32 0]\n call void @dummy1()\n ret void\n\npad1: ; preds = %catchbb\n %c1 = catchpad within %cs [i32 0]\n call void @dummy1()\n ret void\n}\n\n!0 = !{!\"auto-init\"}\n", "additional_args": null, "lli_expected_out": null } ] }, { "file": "llvm/test/Transforms/MoveAutoInit/loop.ll", "commands": [ "opt < %s -S -passes='move-auto-init' -verify-memoryssa" ], "tests": [ { "test_name": "foo", "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\"\n\ndefine void @foo(i32 %x) {\nentry:\n %buffer = alloca [80 x i32], align 16\n call void @llvm.memset.p0.i64(ptr align 16 %buffer, i8 -86, i64 320, i1 false), !annotation !0\n br label %do.body\n\ndo.body: ; preds = %do.cond, %entry\n %x.addr.0 = phi i32 [ %x, %entry ], [ %dec, %do.cond ]\n %arrayidx = getelementptr inbounds [80 x i32], ptr %buffer, i64 0, i64 0\n call void @dump(ptr %arrayidx)\n br label %do.cond\n\ndo.cond: ; preds = %do.body\n %dec = add nsw i32 %x.addr.0, -1\n %tobool = icmp ne i32 %x.addr.0, 0\n br i1 %tobool, label %do.body, label %do.end\n\ndo.end: ; preds = %do.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0\n\ndeclare void @dump(ptr)\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\n\n!0 = !{!\"auto-init\"}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "bar", "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\"\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0\n\ndeclare void @dump(ptr)\n\ndefine void @bar(i32 %x, i32 %y) {\nentry:\n %buffer = alloca [80 x i32], align 16\n call void @llvm.memset.p0.i64(ptr align 16 %buffer, i8 -86, i64 320, i1 false), !annotation !0\n %tobool = icmp ne i32 %y, 0\n br i1 %tobool, label %if.then, label %if.end\n\nif.then: ; preds = %entry\n %add = add nsw i32 %x, %y\n br label %do.body\n\ndo.body: ; preds = %do.cond, %if.then\n %x.addr.0 = phi i32 [ %add, %if.then ], [ %dec, %do.cond ]\n %arrayidx = getelementptr inbounds [80 x i32], ptr %buffer, i64 0, i64 0\n call void @dump(ptr %arrayidx)\n br label %do.cond\n\ndo.cond: ; preds = %do.body\n %dec = add nsw i32 %x.addr.0, -1\n %tobool1 = icmp ne i32 %x.addr.0, 0\n br i1 %tobool1, label %do.body, label %do.end\n\ndo.end: ; preds = %do.cond\n br label %if.end\n\nif.end: ; preds = %do.end, %entry\n ret void\n}\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\n\n!0 = !{!\"auto-init\"}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[MoveAutoInit] Assertion `NodeB && \"B must be in the tree\"' failed.", "body": "opt -O3 -sroa-skip-mem2reg -enable-dfa-jump-thread tc_dt.ll\r\n[tc_dt.tar.gz](https://github.com/llvm/llvm-project/files/13928836/tc_dt.tar.gz)\r\n\r\nGenericDomTree.h:501: NodeT* llvm::DominatorTreeBase<NodeT, IsPostDom>::findNearestCommonDominator(NodeT*, NodeT*) const [with NodeT = llvm::BasicBlock; \r\nbool IsPostDom = false]: Assertion `NodeB && \"B must be in the tree\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\n\r\nReduced test case attached, but have not looked into it. Adding people high in the log...\r\n", "author": "JonPsson1", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "bjope", "body": "Reduced the test case and pipeline a bit more:\r\n\r\nopt -S -o - -passes='dfa-jump-threading,move-auto-init' reduced.ll \r\n\r\nWith reduced.ll being\r\n```\r\ndefine void @func_1() {\r\nentry:\r\n %l_2586 = alloca [2 x i16], i32 0, align 2\r\n store i32 0, ptr %l_2586, align 2, !annotation !0\r\n br label %lbl_2844.preheader\r\n\r\nlbl_2844.preheader: ; preds = %entry\r\n br label %lbl_2844\r\n\r\nlbl_2844: ; preds = %cleanup1473, %lbl_2844.preheader\r\n call void null()\r\n br label %cleanup1473\r\n\r\nfor.end516: ; No predecessors!\r\n br label %cleanup1473\r\n\r\ncleanup1473: ; preds = %for.end516, %lbl_2844\r\n %cleanup.dest.slot.0 = phi i32 [ 0, %for.end516 ], [ 17, %lbl_2844 ]\r\n switch i32 %cleanup.dest.slot.0, label %cleanup1829 [\r\n i32 0, label %if.end1787\r\n i32 17, label %lbl_2844\r\n ]\r\n\r\nif.end1787: ; preds = %cleanup1473\r\n %cmp1789.not = icmp ult ptr null, %l_2586\r\n unreachable\r\n\r\ncleanup1829: ; preds = %cleanup1473\r\n ret void\r\n}\r\n\r\n!0 = !{!\"auto-init\"}\r\n\r\n```" }, { "author": "XChy", "body": "It seems that DFAJumpThreading broke the dominator tree analysis." }, { "author": "XChy", "body": "> It seems that DFAJumpThreading broke the dominator tree analysis.\r\n\r\nIn fact, *MoveAutoInit* should be to blame. This pass doesn't handle unreachable predecessors correctly. A reduced version without `DFAJumpThreading`: \r\n```llvm\r\ndeclare void @dummy()\r\n\r\ndefine void @func_1() {\r\nentry:\r\n %p = alloca [2 x i16], i32 0, align 2\r\n store i32 0, ptr %p, align 2, !annotation !0\r\n br i1 true, label %loop, label %usebb\r\n\r\nloop:\r\n call void @dummy()\r\n br label %loop\r\n\r\na:\r\n br label %loop\r\n\r\nb:\r\n br label %loop\r\n\r\nusebb:\r\n %use_p = icmp ult ptr null, %p\r\n ret void\r\n}\r\n\r\n!0 = !{!\"auto-init\"}\r\n```\r\n\r\nAnd after looking into the source, I found that this pass doesn't handle `catchswitch` well too. For example:\r\n```llvm\r\ndeclare void @dummy()\r\n\r\ndeclare void @dummy1()\r\n\r\ndefine void @func_1() personality ptr @dummy {\r\nentry:\r\n %p = alloca [2 x i16], i32 0, align 2\r\n store i32 0, ptr %p, align 2, !annotation !0\r\n %call = invoke ptr @dummy() to label %clean unwind label %catchbb\r\n\r\nunreachable:\r\n %call1 = invoke ptr @dummy() to label %clean unwind label %catchbb\r\n\r\nclean:\r\n ret void\r\n\r\ncatchbb:\r\n %cs = catchswitch within none [label %pad, label %pad1] unwind to caller\r\n\r\npad:\r\n %c = catchpad within %cs [ptr null, i32 0, ptr null]\r\n call void @dummy1()\r\n ret void\r\n\r\npad1:\r\n %c1 = catchpad within %cs [ptr null, i32 0, ptr null]\r\n call void @dummy1()\r\n ret void\r\n}\r\n\r\n!0 = !{!\"auto-init\"}\r\n```\r\n" } ] }
true
null
107051
https://github.com/llvm/llvm-project/issues/107051
crash
fcb7b390ccd5b4cfc71f13b5e16a846f3f400c10
2024-09-03T06:19:24
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "3bd161e98d89d31696002994771b7761f1c74859", "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": [ [ 1290, 1297 ], [ 6194, 6199 ], [ 6206, 6219 ], [ 6229, 6248 ] ], "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::setVectorizedCallDecision", "collectUniformsAndScalars" ], "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 3bd161e98d89d31696002994771b7761f1c74859 Author: Florian Hahn <[email protected]> Date: Tue Sep 3 21:06:31 2024 +0100 [LV] Honor forced scalars in setVectorizedCallDecision. Similarly to dd94537b4, setVectorizedCallDecision also did not consider ForcedScalars. This lead to VPlans not reflecting the decision by the legacy cost model (cost computation would use scalar cost, VPlan would have VPWidenCallRecipe). To fix this, check if the call has been forced to scalar in setVectorizedCallDecision. Note that this requires moving setVectorizedCallDecision after collectLoopUniforms (which sets ForcedScalars). collectLoopUniforms does not depend on call decisions and can safely be moved. Fixes https://github.com/llvm/llvm-project/issues/107051. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 17050b2b433c..0200525a718d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1290,8 +1290,8 @@ public: if (VF.isScalar() || Uniforms.contains(VF)) return; setCostBasedWideningDecision(VF); - setVectorizedCallDecision(VF); collectLoopUniforms(VF); + setVectorizedCallDecision(VF); collectLoopScalars(VF); } @@ -6194,6 +6194,7 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { assert(!VF.isScalar() && "Trying to set a vectorization decision for a scalar VF"); + auto ForcedScalar = ForcedScalars.find(VF); for (BasicBlock *BB : TheLoop->blocks()) { // For each instruction in the old loop. for (Instruction &I : *BB) { @@ -6206,14 +6207,37 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { InstructionCost VectorCost = InstructionCost::getInvalid(); InstructionCost IntrinsicCost = InstructionCost::getInvalid(); TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; - Function *ScalarFunc = CI->getCalledFunction(); Type *ScalarRetTy = CI->getType(); SmallVector<Type *, 4> Tys, ScalarTys; - bool MaskRequired = Legal->isMaskRequired(CI); for (auto &ArgOp : CI->args()) ScalarTys.push_back(ArgOp->getType()); + // Estimate cost of scalarized vector call. The source operands are + // assumed to be vectors, so we need to extract individual elements from + // there, execute VF scalar calls, and then gather the result into the + // vector return value. + InstructionCost ScalarCallCost = + TTI.getCallInstrCost(ScalarFunc, ScalarRetTy, ScalarTys, CostKind); + + // Compute costs of unpacking argument values for the scalar calls and + // packing the return values to a vector. + InstructionCost ScalarizationCost = + getScalarizationOverhead(CI, VF, CostKind); + + ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost; + // Honor ForcedScalars decision. + // TODO: For calls, it might still be more profitable to widen. Use + // VPlan-based cost model to compare different options. + if (VF.isVector() && ForcedScalar != ForcedScalars.end() && + ForcedScalar->second.contains(CI)) { + setCallWideningDecision(CI, VF, CM_Scalarize, nullptr, + Intrinsic::not_intrinsic, std::nullopt, + ScalarCost); + continue; + } + + bool MaskRequired = Legal->isMaskRequired(CI); // Compute corresponding vector type for return value and arguments. Type *RetTy = ToVectorTy(ScalarRetTy, VF); for (Type *ScalarTy : ScalarTys) @@ -6229,20 +6253,6 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { continue; } - // Estimate cost of scalarized vector call. The source operands are - // assumed to be vectors, so we need to extract individual elements from - // there, execute VF scalar calls, and then gather the result into the - // vector return value. - InstructionCost ScalarCallCost = - TTI.getCallInstrCost(ScalarFunc, ScalarRetTy, ScalarTys, CostKind); - - // Compute costs of unpacking argument values for the scalar calls and - // packing the return values to a vector. - InstructionCost ScalarizationCost = - getScalarizationOverhead(CI, VF, CostKind); - - ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost; - // Find the cost of vectorizing the call, if we can find a suitable // vector variant of the function. bool UsesMask = false;
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/call-costs.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "call_forced_scalar", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @call_forced_scalar(ptr %src.1, ptr %src.2, 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 %0 = load i32, ptr %src.1, align 4\n %smax = tail call i32 @llvm.smax.i32(i32 %0, i32 0)\n %umin = tail call i32 @llvm.umin.i32(i32 %smax, i32 1)\n %umin.ext = zext i32 %umin to i64\n %gep.src.2 = getelementptr i8, ptr %src.2, i64 %umin.ext\n %1 = load i8, ptr %gep.src.2, align 1\n %l.ext = zext i8 %1 to i32\n %mul = mul i32 3, %l.ext\n store i32 %mul, ptr %dst.1, align 4\n %gep.dst.2 = getelementptr i32, ptr %dst.2, i64 %iv\n store i32 0, ptr %gep.dst.2, 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\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smax.i32(i32, i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "call_scalarized", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @call_scalarized(ptr noalias %src, ptr noalias %dst, double %0) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 100, %entry ], [ %iv.next, %loop.latch ]\n %iv.next = add i64 %iv, -1\n %gep.src = getelementptr double, ptr %src, i64 %iv.next\n %l = load double, ptr %gep.src, align 8\n %cmp295 = fcmp ugt double %0, 0.000000e+00\n %cmp299 = fcmp ugt double %l, 0.000000e+00\n %or.cond = or i1 %cmp295, %cmp299\n br i1 %or.cond, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %sqrt = call double @llvm.sqrt.f64(double %l)\n %gep.dst = getelementptr double, ptr %dst, i64 %iv.next\n store double %sqrt, ptr %gep.dst, align 8\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %tobool.not = icmp eq i64 %iv.next, 0\n br i1 %tobool.not, 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 double @llvm.sqrt.f64(double) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "fshl_operand_first_order_recurrence", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @fshl_operand_first_order_recurrence(ptr %dst, ptr noalias %src) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %recur = phi i64 [ 0, %entry ], [ %l, %loop ]\n %gep.src = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep.src, align 8\n %or = tail call i64 @llvm.fshl.i64(i64 1, i64 %recur, i64 1)\n %gep.dst = getelementptr inbounds i64, ptr %dst, i64 %iv\n store i64 %or, ptr %gep.dst, align 8\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 100\n br i1 %exitcond.not, 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 i64 @llvm.fshl.i64(i64, i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "powi_call", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @powi_call(ptr %P) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr inbounds double, ptr %P, i64 %iv\n %l = load double, ptr %gep, align 8\n %powi = tail call double @llvm.powi.f64.i32(double %l, i32 3)\n store double %powi, ptr %gep, 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\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare double @llvm.powi.f64.i32(double, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[clang] Assertion failed in Vectorize", "body": "I compiled this code with -Os and a crash appeared in assertion failure:\r\n\r\n```c\r\n#include <stdint.h>\r\nint32_t *c;\r\nint8_t ****d;\r\nuint64_t g;\r\nint a();\r\nlong b(long, long h, long p3) {\r\n long e;\r\n int f = 0;\r\n if (h) {\r\n e = h;\r\n f = 1;\r\n }\r\n if (e > p3)\r\n f = 2;\r\n switch (f) {\r\n case 1:\r\n e++;\r\n case 2:\r\n e--;\r\n }\r\n if (e < h)\r\n e = h;\r\n return e;\r\n}\r\n\r\nuint8_t div_func_uint8_t_u_u(uint8_t ui1, uint8_t ui2)\r\n{\r\n return (ui1 / ui2);\r\n}\r\n\r\nuint64_t j() {\r\n uint16_t k[8];\r\n int i;\r\n for (i = 0; *c + ****d + (int)g + i < 8; i++)\r\n k[b(0, g, 0)] = 6;\r\n *c = div_func_uint8_t_u_u(k[6], a());\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7369: 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\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/T81adKPY5\r\n\r\n", "author": "cardigan1008", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "patrick-rivos", "body": "Unreduced LLVM IR:\r\n```llvm ir\r\n; ModuleID = '/app/example.c'\r\nsource_filename = \"/app/example.c\"\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@c = dso_local local_unnamed_addr global ptr null, align 8\r\n@d = dso_local local_unnamed_addr global ptr null, align 8\r\n@g = dso_local local_unnamed_addr global i64 0, align 8\r\n\r\n; Function Attrs: mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable\r\ndefine dso_local i64 @b(i64 noundef %0, i64 noundef %h, i64 noundef %p3) local_unnamed_addr #0 {\r\nentry:\r\n %tobool.not = icmp ne i64 %h, 0\r\n %spec.select = zext i1 %tobool.not to i32\r\n %cmp = icmp sgt i64 %h, %p3\r\n %f.1 = select i1 %cmp, i32 2, i32 %spec.select\r\n switch i32 %f.1, label %sw.epilog [\r\n i32 1, label %sw.bb\r\n i32 2, label %sw.bb3\r\n ]\r\n\r\nsw.bb: ; preds = %entry\r\n %inc = add nsw i64 %h, 1\r\n br label %sw.bb3\r\n\r\nsw.bb3: ; preds = %entry, %sw.bb\r\n %e.1 = phi i64 [ %h, %entry ], [ %inc, %sw.bb ]\r\n %dec = add nsw i64 %e.1, -1\r\n br label %sw.epilog\r\n\r\nsw.epilog: ; preds = %sw.bb3, %entry\r\n %e.2 = phi i64 [ %h, %entry ], [ %dec, %sw.bb3 ]\r\n %spec.select14 = tail call i64 @llvm.smax.i64(i64 %e.2, i64 %h)\r\n ret i64 %spec.select14\r\n}\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1\r\n\r\n; Function Attrs: mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable\r\ndefine dso_local noundef zeroext i8 @div_func_uint8_t_u_u(i8 noundef zeroext %ui1, i8 noundef zeroext %ui2) local_unnamed_addr #0 {\r\nentry:\r\n %0 = udiv i8 %ui1, %ui2\r\n ret i8 %0\r\n}\r\n\r\n; Function Attrs: nounwind optsize uwtable\r\ndefine dso_local i64 @j() local_unnamed_addr #2 {\r\nentry:\r\n %k = alloca [8 x i16], align 16\r\n call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %k) #5\r\n %0 = load ptr, ptr @c, align 8, !tbaa !6\r\n %1 = load i32, ptr %0, align 4, !tbaa !10\r\n %2 = load ptr, ptr @d, align 8, !tbaa !6\r\n %3 = load ptr, ptr %2, align 8, !tbaa !6\r\n %4 = load ptr, ptr %3, align 8, !tbaa !6\r\n %5 = load ptr, ptr %4, align 8, !tbaa !6\r\n %6 = load i8, ptr %5, align 1, !tbaa !12\r\n %conv = sext i8 %6 to i32\r\n %7 = load i64, ptr @g, align 8, !tbaa !13\r\n %conv1 = trunc i64 %7 to i32\r\n %invariant.op = add i32 %conv, %conv1\r\n %add3.reass12 = add i32 %1, %invariant.op\r\n %cmp13 = icmp slt i32 %add3.reass12, 8\r\n br i1 %cmp13, label %for.body.lr.ph, label %for.end\r\n\r\nfor.body.lr.ph: ; preds = %entry\r\n %tobool.not.i = icmp ne i64 %7, 0\r\n %spec.select.i = zext i1 %tobool.not.i to i32\r\n %cmp.i = icmp sgt i64 %7, 0\r\n %f.1.i = select i1 %cmp.i, i32 2, i32 %spec.select.i\r\n %inc.i = add nsw i64 %7, 1\r\n br label %for.body\r\n\r\nfor.body: ; preds = %for.body.lr.ph, %b.exit\r\n %i.014 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %b.exit ]\r\n switch i32 %f.1.i, label %b.exit [\r\n i32 1, label %sw.bb.i\r\n i32 2, label %sw.bb3.i\r\n ]\r\n\r\nsw.bb.i: ; preds = %for.body\r\n br label %sw.bb3.i\r\n\r\nsw.bb3.i: ; preds = %sw.bb.i, %for.body\r\n %e.1.i = phi i64 [ %7, %for.body ], [ %inc.i, %sw.bb.i ]\r\n %dec.i = add nsw i64 %e.1.i, -1\r\n br label %b.exit\r\n\r\nb.exit: ; preds = %for.body, %sw.bb3.i\r\n %e.2.i = phi i64 [ %7, %for.body ], [ %dec.i, %sw.bb3.i ]\r\n %spec.select14.i = tail call i64 @llvm.smax.i64(i64 %e.2.i, i64 %7)\r\n %arrayidx = getelementptr inbounds [8 x i16], ptr %k, i64 0, i64 %spec.select14.i\r\n store i16 6, ptr %arrayidx, align 2, !tbaa !15\r\n %inc = add nuw nsw i32 %i.014, 1\r\n %add = add i32 %1, %inc\r\n %add3.reass = add i32 %add, %invariant.op\r\n %cmp = icmp slt i32 %add3.reass, 8\r\n br i1 %cmp, label %for.body, label %for.end.loopexit, !llvm.loop !17\r\n\r\nfor.end.loopexit: ; preds = %b.exit\r\n %arrayidx5.phi.trans.insert = getelementptr inbounds i8, ptr %k, i64 12\r\n %.pre = load i16, ptr %arrayidx5.phi.trans.insert, align 4, !tbaa !15\r\n %8 = trunc i16 %.pre to i8\r\n br label %for.end\r\n\r\nfor.end: ; preds = %for.end.loopexit, %entry\r\n %conv6 = phi i8 [ %8, %for.end.loopexit ], [ undef, %entry ]\r\n %call7 = tail call i32 (...) @a() #6\r\n %conv8 = trunc i32 %call7 to i8\r\n %9 = udiv i8 %conv6, %conv8\r\n %conv10 = zext i8 %9 to i32\r\n %10 = load ptr, ptr @c, align 8, !tbaa !6\r\n store i32 %conv10, ptr %10, align 4, !tbaa !10\r\n call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %k) #5\r\n ret i64 undef\r\n}\r\n\r\n; Function Attrs: optsize\r\ndeclare i32 @a(...) local_unnamed_addr #3\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.smax.i64(i64, i64) #4\r\n\r\nattributes #0 = { mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }\r\nattributes #2 = { nounwind optsize uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #3 = { optsize \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #5 = { nounwind }\r\nattributes #6 = { nounwind optsize }\r\n\r\n!llvm.module.flags = !{!0, !1, !2, !3, !4}\r\n!llvm.ident = !{!5}\r\n\r\n!0 = !{i32 7, !\"Dwarf Version\", i32 4}\r\n!1 = !{i32 1, !\"wchar_size\", i32 4}\r\n!2 = !{i32 8, !\"PIC Level\", i32 2}\r\n!3 = !{i32 7, !\"PIE Level\", i32 2}\r\n!4 = !{i32 7, !\"uwtable\", i32 2}\r\n!5 = !{!\"clang version 20.0.0git (https://github.com/llvm/llvm-project.git b6597f521d8a040f2b9fee54b3f89c380de8e432)\"}\r\n!6 = !{!7, !7, i64 0}\r\n!7 = !{!\"any pointer\", !8, i64 0}\r\n!8 = !{!\"omnipotent char\", !9, i64 0}\r\n!9 = !{!\"Simple C/C++ TBAA\"}\r\n!10 = !{!11, !11, i64 0}\r\n!11 = !{!\"int\", !8, i64 0}\r\n!12 = !{!8, !8, i64 0}\r\n!13 = !{!14, !14, i64 0}\r\n!14 = !{!\"long\", !8, i64 0}\r\n!15 = !{!16, !16, i64 0}\r\n!16 = !{!\"short\", !8, i64 0}\r\n!17 = distinct !{!17, !18}\r\n!18 = !{!\"llvm.loop.mustprogress\"}\r\n```\r\n\r\nhttps://godbolt.org/z/Yo1crEjGG\r\n\r\ncc @fhahn " } ] }
true
null
116691
https://github.com/llvm/llvm-project/issues/116691
crash
a4e1a3dc8bc9bb971d8a38130254b4570f8b7a03
2024-11-18T20:36:44
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "ad9c0b369e86e75d56e229f294782a4eaf527226", "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": [ [ 6815, 6830 ], [ 6861, 6866 ], [ 6903, 6909 ] ], "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::tryToVectorizeGatheredLoads" ], "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 ad9c0b369e86e75d56e229f294782a4eaf527226 Author: Alexey Bataev <[email protected]> Date: Mon Nov 18 13:49:04 2024 -0800 [SLP]Check if the gathered loads form full vector before attempting build it Need to check that the number of gathered loads in the slice forms the build vector to avoid compiler crash. Fixes #116691 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 918d7663548f..dc0dffd9fcbf 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6815,16 +6815,7 @@ void BoUpSLP::tryToVectorizeGatheredLoads( // Check if it is profitable to try vectorizing gathered loads. It is // profitable if we have more than 3 consecutive loads or if we have // less but all users are vectorized or deleted. - bool AllowToVectorize = - NumElts >= 3 || - any_of(ValueToGatherNodes.at(Slice.front()), - [=](const TreeEntry *TE) { - return TE->Scalars.size() == 2 && - ((TE->Scalars.front() == Slice.front() && - TE->Scalars.back() == Slice.back()) || - (TE->Scalars.front() == Slice.back() && - TE->Scalars.back() == Slice.front())); - }); + bool AllowToVectorize = false; // Check if it is profitable to vectorize 2-elements loads. if (NumElts == 2) { bool IsLegalBroadcastLoad = TTI->isLegalBroadcastLoad( @@ -6861,6 +6852,19 @@ void BoUpSLP::tryToVectorizeGatheredLoads( return true; }; AllowToVectorize = CheckIfAllowed(Slice); + } else { + AllowToVectorize = + (NumElts >= 3 || + any_of(ValueToGatherNodes.at(Slice.front()), + [=](const TreeEntry *TE) { + return TE->Scalars.size() == 2 && + ((TE->Scalars.front() == Slice.front() && + TE->Scalars.back() == Slice.back()) || + (TE->Scalars.front() == Slice.back() && + TE->Scalars.back() == Slice.front())); + })) && + hasFullVectorsOrPowerOf2(*TTI, Slice.front()->getType(), + Slice.size()); } if (AllowToVectorize) { SmallVector<Value *> PointerOps; @@ -6903,7 +6907,8 @@ void BoUpSLP::tryToVectorizeGatheredLoads( } // Mark masked gathers candidates as vectorized, if any. for (unsigned Cnt : MaskedGatherVectorized) { - ArrayRef<LoadInst *> Slice = ArrayRef(Loads).slice(Cnt, NumElts); + ArrayRef<LoadInst *> Slice = ArrayRef(Loads).slice( + Cnt, std::min<unsigned>(NumElts, Loads.size() - Cnt)); ArrayRef<Value *> Values( reinterpret_cast<Value *const *>(Slice.begin()), Slice.size()); Results.emplace_back(Values, LoadsState::ScatterVectorize);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/gathered-loads-non-full-reg.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux -mcpu=cascadelake < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@solid_ = external global [608 x i8]\n\ndefine void @test(ptr noalias %0) {\n;\n.lr.ph1019:\n %1 = getelementptr i8, ptr %0, i64 8\n %2 = getelementptr i8, ptr %0, i64 32\n %3 = getelementptr i8, ptr %0, i64 128\n %4 = getelementptr i8, ptr %0, i64 200\n %5 = getelementptr i8, ptr %0, i64 208\n %6 = getelementptr i8, ptr %0, i64 232\n %7 = getelementptr i8, ptr %0, i64 288\n %8 = getelementptr i8, ptr %0, i64 320\n %9 = getelementptr i8, ptr %0, i64 304\n %10 = getelementptr i8, ptr %0, i64 424\n %11 = getelementptr i8, ptr %0, i64 480\n %12 = getelementptr i8, ptr %0, i64 504\n %13 = getelementptr i8, ptr %0, i64 632\n %14 = getelementptr i8, ptr %0, i64 720\n %15 = load double, ptr %1, align 8\n %16 = load double, ptr %2, align 8\n %17 = fadd double %16, %15\n %18 = load double, ptr %3, align 8\n %19 = load double, ptr %4, align 8\n %20 = load double, ptr %5, align 8\n %21 = load double, ptr %6, align 8\n %22 = fadd double %21, %20\n %23 = load double, ptr %7, align 8\n %24 = load double, ptr %8, align 8\n %25 = load double, ptr %9, align 8\n %26 = load double, ptr %10, align 8\n %27 = load double, ptr %11, align 8\n %28 = load double, ptr %12, align 8\n %29 = fadd double %28, %27\n %30 = fmul double %22, %18\n %31 = fmul double %30, 0.000000e+00\n %32 = fsub double 0.000000e+00, %25\n %33 = fmul double %32, 0.000000e+00\n %34 = fadd double %33, 0.000000e+00\n %35 = fmul double %34, 0.000000e+00\n %36 = fmul double %29, %26\n %37 = fmul double %36, 0.000000e+00\n %38 = fadd double %37, 0.000000e+00\n %39 = fsub double %17, %19\n %40 = fmul double %39, %23\n %41 = fmul double %40, 0.000000e+00\n %42 = load double, ptr %0, align 8\n %43 = load double, ptr %13, align 8\n %44 = fmul double %43, %31\n %45 = load double, ptr %14, align 8\n %46 = fmul double %35, 0.000000e+00\n %47 = fadd double %44, 0.000000e+00\n %48 = fmul double %45, %38\n %49 = fmul double %45, %41\n store double %46, ptr getelementptr inbounds (i8, ptr @solid_, i64 384), align 8\n store double %47, ptr getelementptr inbounds (i8, ptr @solid_, i64 408), align 8\n store double %48, ptr getelementptr inbounds (i8, ptr @solid_, i64 392), align 8\n store double %49, ptr getelementptr inbounds (i8, ptr @solid_, i64 400), align 8\n %.neg965 = fmul double %48, %24\n %reass.add993 = fadd double %.neg965, 0.000000e+00\n %50 = fadd double %42, %reass.add993\n %51 = fsub double 0.000000e+00, %50\n store double %51, ptr getelementptr inbounds (i8, ptr @solid_, i64 296), align 8\n %.neg969 = fmul double %49, 0.000000e+00\n %reass.add996 = fadd double %.neg969, 0.000000e+00\n %52 = fadd double %45, %reass.add996\n %53 = fsub double 0.000000e+00, %52\n store double %53, ptr getelementptr inbounds (i8, ptr @solid_, i64 304), align 8\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Crash in SLPVectorizer.cpp", "body": "I'm seeing a problem that shows up in the flang compiler when compiling a large, proprietary benchmark. Since the benchmark is proprietary, I can't include the source code in this bug report.\r\n\r\nThe problem happens in in the file `.../llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp` in the function `BoUpSLP::tryToVectorizeGatheredLoads`.\r\n\r\nIn the code around line 6906, is the statement:\r\n\r\n```\r\nArrayRef<LoadInst *> Slice = ArrayRef(Loads).slice(Cnt, NumElts);\r\n```\r\n\r\nThe code for `slice()` is in `llvm-project/llvm/include/llvm/ADT/ArrayRef.h`. It contains the line:\r\n\r\n```\r\nassert(N+M <= size() && \"Invalid specifier\");\r\n```\r\n\r\nThis assertion fails, and the compiler crashes.\r\n\r\nI added debug code to `SLPVectorizer.cpp` to trace how the variables `Cnt` and `NumElts` got their values leading up to the point of failure. I've included the output of running the compiler on the test case in the file `log` along with the source code of the modified version of `SLPVectorizer.cpp` in the attached zip file.\r\n\r\nAt the point of failure, the value of `N` (which corresponds to `Cnt`) is 8. The value of `M` (passed from `NumElts`) is also 8. The call to `size()` returns 14. Since 8 + 8 is not less than or equal to 14, the assert fails and the compiler crashes.\r\n\r\nI captured the LLVM IR of the original test case and included it below in the file `x13.f90.ll` in the attached zip file.\r\n\r\nIf you run this command after downloading `x13.f90.ll`, you'll see the error:\r\n\r\n```\r\n#!/bin/bash\r\n../bin/clang -c -O3 -march=native -mllvm -locally-hot-callsite-threshold=4500 x13.f90.ll\r\n```\r\n\r\nI also ran the `x13.f90.ll` file through `llvm-reduce` using the following command:\r\n\r\n```\r\nllvm-reduce --test pcrash.sh x13.f90.ll\r\n```\r\n\r\nThis produced a file called `reduced.ll` that I've included in the attached zip file. I've also included the log file `reduced.log` that shows what happend when you run the command:\r\n\r\n```\r\n#!/bin/bash\r\n../bin/clang -c -O3 -march=native -mllvm -locally-hot-callsite-threshold=4500 reduced.ll\r\n```\r\n\r\n@alexey-bataev, please let me know if someone else should look at this or if I can help out by adding additional debug information.\r\n\r\n[Archive.zip](https://github.com/user-attachments/files/17805978/Archive.zip)\r\n", "author": "psteinfeld", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
113451
https://github.com/llvm/llvm-project/issues/113451
crash
7a1036935f8122d9120df5ecf5afb5c927a9ea8b
2024-10-23T12:43:54
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "a3508e0246741851f06cb9ba86203be8d89febed", "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": [ [ 11588, 11594 ] ], "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::isTreeTinyAndNotFullyVectorizable" ], "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 a3508e0246741851f06cb9ba86203be8d89febed Author: Alexey Bataev <[email protected]> Date: Wed Oct 23 10:25:41 2024 -0700 [SLP]Small buidlvector only graph should contains scalars from same block If the graph is small and has single buildvector node, all scalars instructions must be from the same basic block to prevent compiler crash. Fixes #113451 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 756b25ac9856..d824c40c401d 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -11588,7 +11588,8 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const { if (VectorizableTree.back()->isGather() && VectorizableTree.back()->isAltShuffle() && - VectorizableTree.back()->getVectorFactor() > 2) + VectorizableTree.back()->getVectorFactor() > 2 && + allSameBlock(VectorizableTree.back()->Scalars)) return false; assert(VectorizableTree.empty()
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/small-graph-diff-block-instructions.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512dq -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(i32 %arg, i32 %arg1) {\nbb:\n %zext = zext i32 %arg1 to i64\n %zext2 = zext i32 %arg to i64\n %sext = sext i32 %arg to i64\n br label %bb3\n\nbb3: ; preds = %bb\n %getelementptr = getelementptr i64, ptr addrspace(1) null, i64 %zext\n %getelementptr4 = getelementptr i64, ptr addrspace(1) null, i64 %zext2\n %getelementptr5 = getelementptr i64, ptr addrspace(1) null, i64 %sext\n %zext6 = zext i32 0 to i64\n %getelementptr7 = getelementptr i64, ptr addrspace(1) null, i64 %zext6\n ret i32 0\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "Assertion `((GatheredLoadsEntriesFirst.has_value() && E->getOpcode() == Instruction::Load && E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) || all_of(E->Scalars, [=](Value *V) -> bool { if (E->getOpcode() == Instruction::GetElementPtr && !isa<GetElementPtrInst>(V)) return true; auto *I = cast<Instruction>(V); return !E->isOpcodeOrAlt(I) || I->getParent() == BB || isVectorLikeInstWithConstOps(I); })) && \"Expected gathered loads or GEPs or instructions from same basic \" \"block.\"' failed.", "body": "To reproduce 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 i32 @wombat(i32 %arg, i32 %arg1) #0 gc \"statepoint-example\" {\r\nbb:\r\n %zext = zext i32 %arg1 to i64\r\n %zext2 = zext i32 %arg to i64\r\n %sext = sext i32 %arg to i64\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb\r\n %getelementptr = getelementptr i64, ptr addrspace(1) null, i64 %zext\r\n %getelementptr4 = getelementptr i64, ptr addrspace(1) null, i64 %zext2\r\n %getelementptr5 = getelementptr i64, ptr addrspace(1) null, i64 %sext\r\n %zext6 = zext i32 0 to i64\r\n %getelementptr7 = getelementptr i64, ptr addrspace(1) null, i64 %zext6\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+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,-avx10.2-256,-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,-avx10.2-512,-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\n```\r\nReproducer: https://godbolt.org/z/8WhP4hY6G\r\n\r\nStack dump:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13048: llvm::Instruction& llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(const llvm::slpvectorizer::BoUpSLP::TreeEntry*): Assertion `((GatheredLoadsEntriesFirst.has_value() && E->getOpcode() == Instruction::Load && E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) || all_of(E->Scalars, [=](Value *V) -> bool { if (E->getOpcode() == Instruction::GetElementPtr && !isa<GetElementPtrInst>(V)) return true; auto *I = cast<Instruction>(V); return !E->isOpcodeOrAlt(I) || I->getParent() == BB || isVectorLikeInstWithConstOps(I); })) && \"Expected gathered loads or GEPs or instructions from same basic \" \"block.\"' 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 -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 0x00000000050d8608 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50d8608)\r\n #1 0x00000000050d5fbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000070a067c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000070a067c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000070a067c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000070a067c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000070a067c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000070a067c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004157831 llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4157831)\r\n #9 0x0000000004157890 llvm::slpvectorizer::BoUpSLP::setInsertPointAfterBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4157890)\r\n#10 0x00000000041820da llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41820da)\r\n#11 0x00000000041a7a5c llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41a7a5c)\r\n#12 0x00000000041ab4ad llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41ab4ad)\r\n#13 0x00000000041c0e45 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c0e45)\r\n#14 0x00000000041c2f7b llvm::SLPVectorizerPass::vectorizeGEPIndices(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c2f7b)\r\n#15 0x00000000041cf257 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#16 0x00000000041cfedb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41cfedb)\r\n#17 0x0000000002f64f0e 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+0x2f64f0e)\r\n#18 0x0000000004ed9788 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed9788)\r\n#19 0x0000000000e2773e 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+0xe2773e)\r\n#20 0x0000000004ed81ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed81ae)\r\n#21 0x0000000000e26e8e 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+0xe26e8e)\r\n#22 0x0000000004ed7be0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed7be0)\r\n#23 0x000000000090a07a 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+0x90a07a)\r\n#24 0x00000000008fce7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce7c)\r\n#25 0x000070a067c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x000070a067c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008f493e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f493e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
97590
https://github.com/llvm/llvm-project/issues/97590
crash
ed51908cec879c9dff435abdc70d8b03afc35c07
2024-07-03T15:09:36
[ "llvm/test/Transforms/Inline" ]
{ "fix_commit": "be7239e5a60927f5b4932f995dc4b57423ea8534", "components": [ "InlineCost" ], "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": 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": [ [ 2644, 2651 ] ], "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": 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": [ "CallAnalyzer::stripAndComputeInBoundsConstantOffsets" ], "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 be7239e5a60927f5b4932f995dc4b57423ea8534 Author: Yingwei Zheng <[email protected]> Date: Tue Jul 9 15:08:04 2024 +0800 [Inline] Remove bitcast handling in `CallAnalyzer::stripAndComputeInBoundsConstantOffsets` (#97988) As we are now using opaque pointers, bitcast handling is no longer needed. Closes https://github.com/llvm/llvm-project/issues/97590. diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 94aa8ecf6f55..345e5a019520 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -2644,8 +2644,6 @@ ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(Value *&V) { if (!GEP->isInBounds() || !accumulateGEPOffset(*GEP, Offset)) return nullptr; V = GEP->getPointerOperand(); - } else if (Operator::getOpcode(V) == Instruction::BitCast) { - V = cast<Operator>(V)->getOperand(0); } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) { if (GA->isInterposable()) break;
[ { "file": "llvm/test/Transforms/Inline/pr97590.ll", "commands": [ "opt -S -passes=inline < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Check that we don't crash when computing the\n; base pointer of `bitcast <1 x ptr> to ptr`\n\ndefine void @caller(<1 x ptr> %x) {\n;\nentry:\n %p = bitcast <1 x ptr> %x to ptr\n call void @callee(ptr %p)\n ret void\n}\n\ndefine void @callee(ptr %p) {\n;\nentry:\n ret void\n}", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[Inline] Assertion `V->getType()->isPointerTy() && \"Unexpected operand type!\"' failed.", "body": "Reproducer: https://godbolt.org/z/qGc1Kx5YK\r\n```\r\n; bin/opt -passes=inline reduced.ll -S\r\ndefine i32 @func_120(i1 %tobool626, ptr %g_231, ptr %l_506, i1 %tobool724, ptr %p) {\r\nentry:\r\n %0 = bitcast i1 %tobool626 to <1 x i1>\r\n call void @llvm.masked.store.v1i64.p0(<1 x i64> zeroinitializer, ptr %g_231, i32 8, <1 x i1> %0)\r\n %1 = xor i1 %tobool626, true\r\n %2 = bitcast i1 %1 to <1 x i1>\r\n %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr %g_231, i32 8, <1 x i1> %2, <1 x ptr> poison)\r\n %4 = bitcast <1 x ptr> %3 to ptr\r\n br i1 %tobool626, label %common.ret, label %if.else647\r\n\r\ncommon.ret: ; preds = %entry, %lor.end739\r\n ret i32 0\r\n\r\nif.else647: ; preds = %entry\r\n br i1 %tobool724, label %land.rhs725, label %lor.end739\r\n\r\nland.rhs725: ; preds = %if.else647\r\n %call726 = load i32, ptr %p, align 4\r\n br label %lor.end739\r\n\r\nlor.end739: ; preds = %land.rhs725, %if.else647\r\n %call745 = call i32 @func_136(ptr %4)\r\n br label %common.ret\r\n}\r\n\r\ndefine i32 @func_136(ptr nocapture readnone %p_137) {\r\nentry:\r\n ret i32 0\r\n}\r\n\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Analysis/InlineCost.cpp:2656: llvm::ConstantInt* {anonymous}::CallAnalyzer::stripAndComputeInBoundsConstantOffsets(llvm::Value*&): Assertion `V->getType()->isPointerTy() && \"Unexpected operand 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=inline <source>\r\n1.\tRunning pass \"cgscc(inline)\" on module \"<source>\"\r\n #0 0x0000000004e7cf38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7cf38)\r\n #1 0x0000000004e7a69c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000077b96f042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000077b96f0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000077b96f042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000077b96f0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000077b96f02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000077b96f039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000043ea53a (anonymous namespace)::CallAnalyzer::analyze() (.part.0) InlineCost.cpp:0:0\r\n #9 0x00000000043eb650 llvm::getInlineCost(llvm::CallBase&, llvm::Function*, llvm::InlineParams const&, llvm::TargetTransformInfo&, llvm::function_ref<llvm::AssumptionCache& (llvm::Function&)>, llvm::function_ref<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::ProfileSummaryInfo*, llvm::OptimizationRemarkEmitter*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43eb650)\r\n#10 0x00000000043ebba6 llvm::getInlineCost(llvm::CallBase&, llvm::InlineParams const&, llvm::TargetTransformInfo&, llvm::function_ref<llvm::AssumptionCache& (llvm::Function&)>, llvm::function_ref<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::ProfileSummaryInfo*, llvm::OptimizationRemarkEmitter*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43ebba6)\r\n#11 0x00000000043ed0ab llvm::InlineCost llvm::function_ref<llvm::InlineCost (llvm::CallBase&)>::callback_fn<getDefaultInlineAdvice(llvm::CallBase&, llvm::AnalysisManager<llvm::Function>&, llvm::InlineParams const&)::'lambda2'(llvm::CallBase&)>(long, llvm::CallBase&) InlineAdvisor.cpp:0:0\r\n#12 0x00000000043f310d llvm::shouldInline(llvm::CallBase&, llvm::function_ref<llvm::InlineCost (llvm::CallBase&)>, llvm::OptimizationRemarkEmitter&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f310d)\r\n#13 0x00000000043f4af5 getDefaultInlineAdvice(llvm::CallBase&, llvm::AnalysisManager<llvm::Function>&, llvm::InlineParams const&) InlineAdvisor.cpp:0:0\r\n#14 0x00000000043f4d3b llvm::DefaultInlineAdvisor::getAdviceImpl(llvm::CallBase&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f4d3b)\r\n#15 0x00000000043eda71 llvm::InlineAdvisor::getAdvice(llvm::CallBase&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43eda71)\r\n#16 0x000000000371e48d llvm::InlinerPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x371e48d)\r\n#17 0x0000000002e127ae llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::InlinerPass, 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/opt+0x2e127ae)\r\n#18 0x000000000431385b 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/opt+0x431385b)\r\n#19 0x0000000002e1154e 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/opt+0x2e1154e)\r\n#20 0x00000000043155b9 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43155b9)\r\n#21 0x0000000002e1152e 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/opt+0x2e1152e)\r\n#22 0x0000000004c780c0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c780c0)\r\n#23 0x00000000008d8702 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+0x8d8702)\r\n#24 0x00000000008cb60c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cb60c)\r\n#25 0x000077b96f029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x000077b96f029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008c2a6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c2a6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nhttps://github.com/llvm/llvm-project/blob/f1a8f94bba8b090a0d667065e4b8b4fc66b6a5cc/llvm/lib/Analysis/InlineCost.cpp#L2647-L2648\r\nshould be removed as we use opaque pointers now.\r\n", "author": "dtcxzyw", "labels": [ "crash-on-valid", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "Related patch: #96878 " }, { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/rbjK6ETEW\r\n```\r\n; bin/opt -passes=inline reduced.ll -S\r\ndefine void @caller(<1 x ptr> %x) {\r\nentry:\r\n %p = bitcast <1 x ptr> %x to ptr\r\n call void @callee(ptr %p)\r\n ret void\r\n}\r\n\r\ndefine void @callee(ptr %p) {\r\nentry:\r\n ret void\r\n}\r\n```" } ] }
true
null
107171
https://github.com/llvm/llvm-project/issues/107171
crash
34f2c9a9ce73a61b27d75dab7e1eed256491afcc
2024-09-04T00:23:05
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "3fe6a064f15cd854fd497594cc20e8b680cd2133", "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": [ [ 6606, 6614 ] ], "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 3fe6a064f15cd854fd497594cc20e8b680cd2133 Author: Florian Hahn <[email protected]> Date: Wed Sep 4 20:50:05 2024 +0100 [LV] Check if compare is truncated directly in getInstructionCost. The current check for truncated compares in getInstructionCost misses cases where either the first or both operands are constants. Check directly if the compare is marked for truncation. In that case, the minimum bitwidth is that of the operands. The patch also adds asserts to ensure that. This fixes a divergence between legacy and VPlan-based cost model, where the legacy cost model incorrectly estimated the cost of compares with truncated operands. Fixes https://github.com/llvm/llvm-project/issues/107171. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0200525a718d..0ccf442dac99 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6606,9 +6606,20 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, case Instruction::ICmp: case Instruction::FCmp: { Type *ValTy = I->getOperand(0)->getType(); + Instruction *Op0AsInstruction = dyn_cast<Instruction>(I->getOperand(0)); - if (canTruncateToMinimalBitwidth(Op0AsInstruction, VF)) - ValTy = IntegerType::get(ValTy->getContext(), MinBWs[Op0AsInstruction]); + (void)Op0AsInstruction; + assert((!canTruncateToMinimalBitwidth(Op0AsInstruction, VF) || + canTruncateToMinimalBitwidth(I, VF)) && + "truncating Op0 must imply truncating the compare"); + if (canTruncateToMinimalBitwidth(I, VF)) { + assert(!canTruncateToMinimalBitwidth(Op0AsInstruction, VF) || + MinBWs[I] == MinBWs[Op0AsInstruction] && + "if both the operand and the compare are marked for " + "truncation, they must have the same bitwidth"); + ValTy = IntegerType::get(ValTy->getContext(), MinBWs[I]); + } + VectorTy = ToVectorTy(ValTy, VF); return TTI.getCmpSelInstrCost(I->getOpcode(), VectorTy, nullptr, cast<CmpInst>(I)->getPredicate(), CostKind,
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll", "commands": [ "opt -p loop-vectorize -mattr=+v -S %s" ], "tests": [ { "test_name": "test_pr98413_zext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_zext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = zext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "truncate_to_i1_used_by_branch", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @truncate_to_i1_used_by_branch(i8 %x, ptr %dst) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %f.039 = phi i8 [ 0, %entry ], [ %add, %loop.latch ]\n %0 = or i8 23, %x\n %extract.t = trunc i8 %0 to i1\n br i1 %extract.t, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n store i8 0, ptr %dst, align 1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %add = add i8 %f.039, 1\n %conv = sext i8 %f.039 to i32\n %cmp = icmp slt i32 %conv, 1\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl256b\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "icmp_ops_narrowed_to_i1", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine i8 @icmp_ops_narrowed_to_i1() #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop ]\n %c = icmp eq i8 0, 0\n %ext = zext i1 %c to i64\n %shr = lshr i64 %ext, 1\n %trunc = trunc i64 %shr to i8\n %iv.next = add i16 %iv, 1\n %ec = icmp eq i16 %iv.next, 100\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i8 %trunc\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "additional_args": null, "lli_expected_out": null }, { "test_name": "test_pr98413_sext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_sext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = sext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "additional_args": null, "lli_expected_out": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Testing using 3bd161e98d89d31696002994771b7761f1c74859\r\n\r\nC testcase:\r\n```c\r\nchar a;\r\nunsigned b = 221;\r\nshort c = 35;\r\nchar d[6];\r\nint main() {\r\n d[0] = 4079751220931503459;\r\n for (short e = 3; e; e += 3)\r\n for (short f = 0; f < 1; f += -1832)\r\n for (long g = ({\r\n __typeof__(0) h = !d[f * 1];\r\n h;\r\n });\r\n g < c - 3; g += b - 219)\r\n a -= 8;\r\n}\r\n```\r\n`/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -I/scratch/tc-testing/compiler-fuzz-ci/csmith-build/include -fsigned-char -fno-strict-aliasing -fwrapv -march=rv64gcv -flto -O3 -fuse-ld=lld red.c -o rv64gcv.out -w`\r\n\r\nLLVM IR:\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 i32 @main() #0 {\r\nentry:\r\n br label %for.body14.preheader48\r\n\r\nfor.cond.cleanup: ; preds = %for.body14.preheader48\r\n store i8 %1, ptr null, align 1\r\n ret i32 0\r\n\r\nfor.body14.preheader48: ; preds = %for.body14.preheader48, %entry\r\n %e.047 = phi i16 [ 0, %entry ], [ %add27, %for.body14.preheader48 ]\r\n %tobool6.not = icmp eq i8 0, 0\r\n %conv7 = zext i1 %tobool6.not to i64\r\n %0 = lshr i64 %conv7, 1\r\n %1 = trunc i64 %0 to i8\r\n %add27 = add i16 %e.047, 1\r\n %tobool.not = icmp eq i16 %add27, 0\r\n br i1 %tobool.not, label %for.cond.cleanup, label %for.body14.preheader48\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:7389: 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 0x000061eac73d9f50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3010f50)\r\n #1 0x000061eac73d735f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300e35f)\r\n #2 0x000061eac73d74b5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007496e1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007496e12969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007496e12969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007496e12969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007496e1242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007496e12287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007496e122871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007496e1239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000061eac63ad810 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe4810)\r\n#12 0x000061eac63c45bb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffb5bb)\r\n#13 0x000061eac63c75d1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffe5d1)\r\n#14 0x000061eac63c7c47 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffec47)\r\n#15 0x000061eac5222626 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+0xe59626)\r\n#16 0x000061eac71e5cef 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+0x2e1ccef)\r\n#17 0x000061eac52257b6 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+0xe5c7b6)\r\n#18 0x000061eac71e4a6b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1ba6b)\r\n#19 0x000061eac5221a56 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+0xe58a56)\r\n#20 0x000061eac71e2aad 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+0x2e19aad)\r\n#21 0x000061eac4a4fde6 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+0x686de6)\r\n#22 0x000061eac4a41b71 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x678b71)\r\n#23 0x00007496e1229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007496e1229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007496e1229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x000061eac4a37f25 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66ef25)\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/x316voG8q\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/106780\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null