bug_id
stringlengths
5
6
issue_url
stringlengths
49
50
bug_type
stringclasses
3 values
base_commit
stringlengths
40
40
knowledge_cutoff
timestamp[s]
lit_test_dir
sequencelengths
1
4
hints
dict
patch
stringlengths
789
17.7k
tests
listlengths
1
35
issue
dict
verified
bool
1 class
test_commit
stringclasses
1 value
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": [ [ 2754, 2780 ] ], "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": [ "ConstantFoldIntrinsicCall2" ], "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
120433
https://github.com/llvm/llvm-project/issues/120433
crash
ac8a9f8fffb605514056f53f12f1fba94ee933e9
2024-12-18T15:02:42
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e7a4d78ad328d02bf515b2fa4af8b2c188a6a636", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 21148, 21155 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "SLPVectorizerPass::vectorizeCmpInsts" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit e7a4d78ad328d02bf515b2fa4af8b2c188a6a636 Author: DianQK <[email protected]> Date: Thu Dec 19 06:21:57 2024 +0800 [SLP] Check if instructions exist after vectorization (#120434) Fixes #120433. diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d967813075bb..88049897b29a 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -21148,8 +21148,11 @@ bool SLPVectorizerPass::vectorizeCmpInsts(iterator_range<ItT> CmpInsts, if (R.isDeleted(I)) continue; for (Value *Op : I->operands()) - if (auto *RootOp = dyn_cast<Instruction>(Op)) + if (auto *RootOp = dyn_cast<Instruction>(Op)) { Changed |= vectorizeRootInstruction(nullptr, RootOp, BB, R); + if (R.isDeleted(I)) + break; + } } // Try to vectorize operands as vector bundles. for (CmpInst *I : CmpInsts) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll", "commands": [ "opt -S -passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "foo", "test_body": "define void @foo() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %i = phi i32 [ %i26, %bb3 ], [ 0, %bb ]\n %i2 = phi i32 [ %i24, %bb3 ], [ 0, %bb ]\n br label %bb3\n\nbb3: ; preds = %bb1\n %i4 = zext i32 %i2 to i64\n %i5 = mul i64 %i4, 0\n %i10 = or i64 0, %i5\n %i11 = trunc i64 %i10 to i32\n %i12 = and i32 %i11, 0\n %i13 = zext i32 %i to i64\n %i14 = mul i64 %i13, 0\n %i19 = or i64 0, %i14\n %i20 = trunc i64 %i19 to i32\n %i21 = and i32 %i20, 0\n %i22 = or i32 %i12, %i21\n %i23 = icmp ult i32 %i22, 0\n %i24 = select i1 %i23, i32 0, i32 0\n %i25 = icmp ult i32 0, 0\n %i26 = select i1 %i25, i32 0, i32 0\n br label %bb1\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLP] Assertion `detail::isPresent(Val) && \"dyn_cast on a non-existent value\"' failed.", "body": "This IR crashes on SLP: https://llvm.godbolt.org/z/8oar4o4d1\n\n```llvm\ndefine void @foo() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %i = phi i32 [ %i26, %bb3 ], [ 0, %bb ]\n %i2 = phi i32 [ %i24, %bb3 ], [ 0, %bb ]\n br label %bb3\n\nbb3: ; preds = %bb1\n %i4 = zext i32 %i2 to i64\n %i5 = mul i64 %i4, 0\n %i10 = or i64 0, %i5\n %i11 = trunc i64 %i10 to i32\n %i12 = and i32 %i11, 0\n %i13 = zext i32 %i to i64\n %i14 = mul i64 %i13, 0\n %i19 = or i64 0, %i14\n %i20 = trunc i64 %i19 to i32\n %i21 = and i32 %i20, 0\n %i22 = or i32 %i12, %i21\n %i23 = icmp ult i32 %i22, 0\n %i24 = select i1 %i23, i32 0, i32 0\n %i25 = icmp ult i32 0, 0\n %i26 = select i1 %i25, i32 0, i32 0\n br label %bb1\n}\n```", "author": "DianQK", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
100591
https://github.com/llvm/llvm-project/issues/100591
crash
71801707e33c235656b172fa7dfb8662473a95c2
2024-07-25T16:31:43
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "e9e3a183d6d8d8729223b7131aa57fd9f02f0440", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6730, 6738 ], [ 6765, 6770 ], [ 6789, 6796 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::collectValuesToIgnore" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit e9e3a183d6d8d8729223b7131aa57fd9f02f0440 Author: Florian Hahn <[email protected]> Date: Sun Aug 18 12:51:17 2024 +0100 [LV] Don't cost branches and conditions to empty blocks. Update the legacy cost model skip branches with successors blocks that are empty or only contain dead instructions, together with their conditions. Such branches and conditions won't result in any generated code and will be cleaned up by VPlan transforms. This fixes a difference between the legacy and VPlan-based cost model. When running LV in its usual pipeline position, such dead blocks should already have been cleaned up, but they might be generated manually or by fuzzers. Fixes https://github.com/llvm/llvm-project/issues/100591. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 27e99694aafd..55c0ba3dd8f9 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6730,9 +6730,12 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { return RequiresScalarEpilogue && !TheLoop->contains(cast<Instruction>(U)->getParent()); }; + + LoopBlocksDFS DFS(TheLoop); + DFS.perform(LI); MapVector<Value *, SmallVector<Value *>> DeadInvariantStoreOps; - for (BasicBlock *BB : TheLoop->blocks()) - for (Instruction &I : *BB) { + for (BasicBlock *BB : reverse(make_range(DFS.beginRPO(), DFS.endRPO()))) + for (Instruction &I : reverse(*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; @@ -6765,6 +6768,13 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { Value *PointerOp = getLoadStorePointerOperand(&I); DeadInterleavePointerOps.push_back(PointerOp); } + + // Queue branches for analysis. They are dead, if their successors only + // contain dead instructions. + if (auto *Br = dyn_cast<BranchInst>(&I)) { + if (Br->isConditional()) + DeadOps.push_back(&I); + } } // Mark ops feeding interleave group members as free, if they are only used @@ -6789,8 +6799,36 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { // Mark ops that would be trivially dead and are only used by ignored // instructions as free. BasicBlock *Header = TheLoop->getHeader(); + + // Returns true if the block contains only dead instructions. Such blocks will + // be removed by VPlan-to-VPlan transforms and won't be considered by the + // VPlan-based cost model, so skip them in the legacy cost-model as well. + auto IsEmptyBlock = [this](BasicBlock *BB) { + return all_of(*BB, [this](Instruction &I) { + return ValuesToIgnore.contains(&I) || VecValuesToIgnore.contains(&I) || + (isa<BranchInst>(&I) && !cast<BranchInst>(&I)->isConditional()); + }); + }; for (unsigned I = 0; I != DeadOps.size(); ++I) { auto *Op = dyn_cast<Instruction>(DeadOps[I]); + + // Check if the branch should be considered dead. + if (auto *Br = dyn_cast_or_null<BranchInst>(Op)) { + BasicBlock *ThenBB = Br->getSuccessor(0); + BasicBlock *ElseBB = Br->getSuccessor(1); + bool ThenEmpty = IsEmptyBlock(ThenBB); + bool ElseEmpty = IsEmptyBlock(ElseBB); + if ((ThenEmpty && ElseEmpty) || + (ThenEmpty && ThenBB->getSingleSuccessor() == ElseBB && + ElseBB->phis().empty()) || + (ElseEmpty && ElseBB->getSingleSuccessor() == ThenBB && + ThenBB->phis().empty())) { + VecValuesToIgnore.insert(Br); + DeadOps.push_back(Br->getCondition()); + } + continue; + } + // Skip any op that shouldn't be considered dead. if (!Op || !TheLoop->contains(Op) || (isa<PHINode>(Op) && Op->getParent() == Header) ||
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/blocks-with-dead-instructions.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "block_with_dead_inst_1", "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 @block_with_dead_inst_1(ptr %src, 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 %xor1315 = phi i16 [ 1, %entry ], [ %xor, %loop.latch ]\n %xor = xor i16 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %dead.gep = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n store i16 %xor, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 3\n %0 = icmp eq i64 %iv.next, %N\n br i1 %0, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "multiple_blocks_with_dead_insts_4", "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 @multiple_blocks_with_dead_insts_4(ptr %src, 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 %xor1315 = phi i16 [ 1, %entry ], [ %xor, %loop.latch ]\n %xor = xor i16 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %loop.header\n br label %then.1\n\nthen.1: ; preds = %then\n %dead.gep.1 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nelse: ; preds = %loop.header\n %dead.gep.2 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nloop.latch: ; preds = %else, %then.1\n store i16 %xor, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 3\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "empty_block_with_phi_1", "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 @empty_block_with_phi_1(ptr %src, 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 %xor1315 = phi i32 [ 1, %entry ], [ %xor, %loop.latch ]\n %xor = xor i32 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i16 [ %l, %loop.header ], [ 99, %then ]\n store i16 %p, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 1\n %0 = icmp eq i64 %iv.next, %N\n br i1 %0, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "multiple_blocks_with_dead_insts_3", "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 @multiple_blocks_with_dead_insts_3(ptr %src) #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 %xor1315 = phi i16 [ 0, %entry ], [ %xor, %loop.latch ]\n %xor = xor i16 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %loop.header\n %dead.gep.1 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nelse: ; preds = %loop.header\n %dead.gep.2 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nloop.latch: ; preds = %else, %then\n store i16 %xor, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 3\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\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "multiple_blocks_with_dead_inst_multiple_successors_5", "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 @multiple_blocks_with_dead_inst_multiple_successors_5(ptr %src) #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 %xor1315 = phi i16 [ 1, %entry ], [ %xor, %loop.latch ]\n %xor = xor i16 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %loop.header\n br label %then.1\n\nthen.1: ; preds = %then\n %dead.gep.1 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nelse: ; preds = %loop.header\n br label %else.2\n\nelse.2: ; preds = %else\n %dead.gep.2 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %then.1\n store i16 %xor, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 3\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\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "multiple_blocks_with_dead_inst_multiple_successors_6", "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 @multiple_blocks_with_dead_inst_multiple_successors_6(ptr %src, i1 %ic, 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 %xor1315 = phi i16 [ 1, %entry ], [ %xor, %loop.latch ]\n %xor = xor i16 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %loop.header\n br i1 %ic, label %then.1, label %else\n\nthen.1: ; preds = %then\n %dead.gep.1 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nelse: ; preds = %then, %loop.header\n br label %else.2\n\nelse.2: ; preds = %else\n %dead.gep.2 = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %then.1\n store i16 %xor, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 3\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "empty_block_with_phi_2", "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 @empty_block_with_phi_2(ptr %src, 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 %xor1315 = phi i32 [ 1, %entry ], [ %xor, %loop.latch ]\n %xor = xor i32 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %p = phi i16 [ %l, %loop.header ], [ 99, %else ]\n store i16 %p, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 1\n %0 = icmp eq i64 %iv.next, %N\n br i1 %0, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "block_with_dead_inst_2", "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 @block_with_dead_inst_2(ptr %src) #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 %xor1315 = phi i16 [ 0, %entry ], [ %xor, %loop.latch ]\n %xor = xor i16 0, 0\n %gep = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep, align 2\n %c = icmp eq i16 %l, 0\n br i1 %c, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %dead.gep = getelementptr i64, ptr %src, i64 %iv\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n store i16 %xor, ptr %gep, align 2\n %iv.next = add nsw i64 %iv, 3\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\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using 51d4980a133db12888207698e39c469cb7055cac\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 @f() #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %cond.end7\r\n ret void\r\n\r\nfor.body: ; preds = %cond.end7, %entry\r\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %cond.end7 ]\r\n %xor1315 = phi i32 [ 0, %entry ], [ %xor, %cond.end7 ]\r\n %xor = xor i32 0, 0\r\n %arrayidx = getelementptr [1 x i16], ptr null, i64 0, i64 %indvars.iv\r\n %0 = load i16, ptr %arrayidx, align 2\r\n %tobool1.not = icmp eq i16 %0, 0\r\n br i1 %tobool1.not, label %cond.false, label %cond.end7\r\n\r\ncond.false: ; preds = %for.body\r\n %arrayidx3 = getelementptr [1 x i64], ptr null, i64 0, i64 %indvars.iv\r\n br label %cond.end7\r\n\r\ncond.end7: ; preds = %cond.false, %for.body\r\n %indvars.iv.next = add nsw i64 %indvars.iv, 3\r\n %1 = icmp eq i64 %indvars.iv.next, 0\r\n br i1 %1, label %for.cond.cleanup, label %for.body\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\nBacktrace:\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:10123: 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 \"f\"\r\n #0 0x00005e0a0dd8f3b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f1f3b0)\r\n #1 0x00005e0a0dd8c7cf llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f1c7cf)\r\n #2 0x00005e0a0dd8c925 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000073a243a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000073a243a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000073a243a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000073a243a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000073a243a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000073a243a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000073a243a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000073a243a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005e0a0cdaadd8 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f3add8)\r\n#12 0x00005e0a0cdad991 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+0x1f3d991)\r\n#13 0x00005e0a0cdae110 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f3e110)\r\n#14 0x00005e0a0bc1fda6 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+0xdafda6)\r\n#15 0x00005e0a0dba750e 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+0x2d3750e)\r\n#16 0x00005e0a0bc22f36 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+0xdb2f36)\r\n#17 0x00005e0a0dba629b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d3629b)\r\n#18 0x00005e0a0bc1f286 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+0xdaf286)\r\n#19 0x00005e0a0dba43ed 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+0x2d343ed)\r\n#20 0x00005e0a0b4686b6 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+0x5f86b6)\r\n#21 0x00005e0a0b45a2f1 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5ea2f1)\r\n#22 0x000073a243a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x000073a243a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x000073a243a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x00005e0a0b450185 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e0185)\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/TnYreKbqn\r\n\r\n@fhahn \r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Another case with dead instructions that get simplified by VPlan-DCE :/" }, { "author": "patrick-rivos", "body": "Just to add a bit of context here: I'm hitting this assertion >300 times a day so I've allowlisted it in the fuzzer I run. There are likely other interesting cases where this assertion triggers but I don't have the bandwidth to deduplicate this failure to pull out those cases. :-(" }, { "author": "preames", "body": "> Just to add a bit of context here: I'm hitting this assertion >300 times a day so I've allowlisted it in the fuzzer I run. There are likely other interesting cases where this assertion triggers but I don't have the bandwidth to deduplicate this failure to pull out those cases. :-(\r\n\r\n@fhahn This assertion is triggering in a large number of fuzzer runs, and we have some reason to believe there are other failures be masked by this one. (We have at least one instance of this found so far by accident.) This needs to be either fixed or reverted so that tree is green. " }, { "author": "fhahn", "body": "Will look into a fix now that I'm back. The crash should not reproduce with `opt -passes='instcombine,simplifycfg,loop-vectorize'` for all instances of the same underlying issue." }, { "author": "nikic", "body": "@fhahn I feel like at this point this assertion is doing a lot more harm than good. It's very fragile, and doesn't seem to help in finding any genuine bugs, just incidental differences in simplification power." }, { "author": "artagnon", "body": "I was also looking into this bug briefly, but couldn't quite figure out why we didn't choose to rip out the legacy costing." }, { "author": "sjoerdmeijer", "body": "If e9e3a183d6d8d8729223b7131aa57fd9f02f0440 was supposed to fix this, then I can confirm I am still seeing this assert. \r\n\r\nIf this is indeed something else or new, then I agree with @nikic that this assert is too fragile." }, { "author": "fhahn", "body": "The assertion originally surfaced real differences that needed fixing; the fuzzer-generated issues over the last weeks mostly were due to unsimplified input, which is very difficult to completely match without actually iteratively simplifying. Seeing the recent https://github.com/llvm/llvm-project/issues/104714 with a C reproducer it was a bit surprising that dead loads (and subsequent dead blocks/conditions) survive until LoopVectorize in the default pipeline.\r\n\r\nThere will be a number of code changes over the next few weeks/months which may introduce unintended divergences the assert is supposed to catch. For that reason it would be beneficial to keep the assert.\r\n\r\nIdeally we would only check if no extra simplifications have been applied on the selected VPlan, which should be possible to check once #103033 lands.\r\n\r\nWe could also guard it with an option, similar to InstCombine's fix point iteration assertion, which can also trigger asserts by default on valid IR input.\r\n\r\n> If [e9e3a18](https://github.com/llvm/llvm-project/commit/e9e3a183d6d8d8729223b7131aa57fd9f02f0440) was supposed to fix this, then I can confirm I am still seeing this assert.\r\n> \r\n\r\nCould you share the reproducer somewhere? Would be good to check if this is due to the simplification issue mentioned above or a genuine divergence" }, { "author": "sjoerdmeijer", "body": "> Could you share the reproducer somewhere? Would be good to check if this is due to the simplification issue mentioned above or a genuine divergence\r\n\r\nThis runs in the same assert with `opt -S -passes=loop-vectorize`: \r\n\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 @foo() #0 {\r\nentry:\r\n br label %for.body315.us.us\r\n\r\nfor.body315.us.us: ; preds = %cond.end388.us.us, %entry\r\n %indvars.iv10421 = phi i64 [ %indvars.iv.next1043, %cond.end388.us.us ], [ 0, %entry ]\r\n br i1 false, label %cond.end388.us.us, label %cond.true380.us.us\r\n\r\ncond.true380.us.us: ; preds = %for.body315.us.us\r\n %0 = load i32, ptr null, align 4\r\n br label %cond.end388.us.us\r\n\r\ncond.end388.us.us: ; preds = %cond.true380.us.us, %for.body315.us.us\r\n %indvars.iv.next1043 = add i64 %indvars.iv10421, 1\r\n %cmp313.us.us = icmp slt i64 %indvars.iv10421, 1\r\n br i1 %cmp313.us.us, label %for.body315.us.us, label %for.cond311.for.cond.cleanup314_crit_edge.loopexit, !llvm.loop !0\r\n\r\nfor.cond311.for.cond.cleanup314_crit_edge.loopexit: ; preds = %cond.end388.us.us\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-cpu\"=\"neoverse-v2\" }\r\n\r\n!0 = distinct !{!0, !1, !2, !3}\r\n!1 = !{!\"llvm.loop.mustprogress\"}\r\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\r\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\r\n```" } ] }
true
null
116375
https://github.com/llvm/llvm-project/issues/116375
crash
07507cb5919cae0ae880bfee538ebc993b97dd6c
2024-11-15T11:48:16
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "320038579d3c23b78f99618b71640f51423fe321", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 3317, 3322 ], [ 3325, 3331 ] ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPFirstOrderRecurrencePHIRecipe::computeCost" ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 320038579d3c23b78f99618b71640f51423fe321 Author: Florian Hahn <[email protected]> Date: Thu Nov 21 21:11:20 2024 +0000 [VPlan] Return cost of PHI for scalar VFs in computeCost for FORs. This fixes a crash when the VF is scalar. Fixes https://github.com/llvm/llvm-project/issues/116375. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 71aca3be9e5d..24cf4666c62c 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -3317,6 +3317,10 @@ void VPFirstOrderRecurrencePHIRecipe::execute(VPTransformState &State) { InstructionCost VPFirstOrderRecurrencePHIRecipe::computeCost(ElementCount VF, VPCostContext &Ctx) const { + TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; + if (VF.isScalar()) + return Ctx.TTI.getCFInstrCost(Instruction::PHI, CostKind); + if (VF.isScalable() && VF.getKnownMinValue() == 1) return InstructionCost::getInvalid(); @@ -3325,7 +3329,6 @@ VPFirstOrderRecurrencePHIRecipe::computeCost(ElementCount VF, Type *VectorTy = ToVectorTy(Ctx.Types.inferScalarType(this->getVPSingleValue()), VF); - TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; return Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Splice, cast<VectorType>(VectorTy), Mask, CostKind, VF.getKnownMinValue() - 1);
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/invalid-costs.ll", "commands": [ "opt -passes=\"loop-vectorize\" -pass-remarks-output=/dev/stderr -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; REMARKS: the cost-model indicates that vectorization is not beneficial\n\n; Test for https://github.com/llvm/llvm-project/issues/116375.\ndefine void @test_i24_load_for(ptr noalias %src, ptr %dst) {\n;\nentry:\n br label %loop\n\nloop:\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop ]\n %for = phi i24 [ 0, %entry ], [ %for.next, %loop ]\n %iv.next = add i16 %iv, 1\n %gep.src = getelementptr inbounds i24, ptr %src, i16 %iv\n %for.next = load i24, ptr %gep.src, align 1\n %gep.dst = getelementptr inbounds i24, ptr %dst, i16 %iv\n store i24 %for, ptr %gep.dst\n %ec = icmp eq i16 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit:\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "opt -passes=\"loop-vectorize\" -pass-remarks-output=tmp.opts crashes with 'Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.'", "body": "llvm commit: 10b048c8922d\r\nReproduce with: ```opt -passes=\"loop-vectorize\" bbi-101140.ll -o /dev/null -pass-remarks-output=tmp.opts```\r\nResult:\r\n```\r\nopt: ../include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = llvm::VectorType, From = llvm::Type]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\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/opt -passes=loop-vectorize bbi-101140.ll -o /dev/null -pass-remarks-output=tmp.opts\r\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"bbi-101140.ll\"\r\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000055b814f24938 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build-all/bin/opt+0x4435938)\r\n #1 0x000055b814f223fe llvm::sys::RunSignalHandlers() (build-all/bin/opt+0x44333fe)\r\n #2 0x000055b814f2516d SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f5d1b5dbcf0 __restore_rt (/lib64/libpthread.so.0+0x12cf0)\r\n #4 0x00007f5d19194acf raise (/lib64/libc.so.6+0x4eacf)\r\n #5 0x00007f5d19167ea5 abort (/lib64/libc.so.6+0x21ea5)\r\n #6 0x00007f5d19167d79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)\r\n #7 0x00007f5d1918d426 (/lib64/libc.so.6+0x47426)\r\n #8 0x000055b816474525 llvm::VPFirstOrderRecurrencePHIRecipe::computeCost(llvm::ElementCount, llvm::VPCostContext&) const (build-all/bin/opt+0x5985525)\r\n #9 0x000055b816461f4c llvm::VPRecipeBase::cost(llvm::ElementCount, llvm::VPCostContext&) (build-all/bin/opt+0x5972f4c)\r\n#10 0x000055b8163faa3a llvm::LoopVectorizationPlanner::emitInvalidCostRemarks(llvm::OptimizationRemarkEmitter*) (build-all/bin/opt+0x590ba3a)\r\n#11 0x000055b816427189 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (build-all/bin/opt+0x5938189)\r\n#12 0x000055b81642cd0b llvm::LoopVectorizePass::runImpl(llvm::Function&) (build-all/bin/opt+0x593dd0b)\r\n#13 0x000055b81642d568 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x593e568)\r\n#14 0x000055b8162e33dd llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\r\n#15 0x000055b81512d317 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (build-all/bin/opt+0x463e317)\r\n#16 0x000055b8162dcf6d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\r\n#17 0x000055b815131ea6 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x4642ea6)\r\n#18 0x000055b8162d6a0d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilderPipelines.cpp:0:0\r\n#19 0x000055b81512c047 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (build-all/bin/opt+0x463d047)\r\n#20 0x000055b81627ab63 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (build-all/bin/opt+0x578bb63)\r\n#21 0x000055b814eebd0a optMain (build-all/bin/opt+0x43fcd0a)\r\n#22 0x00007f5d19180d85 __libc_start_main (/lib64/libc.so.6+0x3ad85)\r\n#23 0x000055b814ee5b2e _start (build-all/bin/opt+0x43f6b2e)\r\nAbort (core dumped)\r\n```\r\n[bbi-101140.ll.gz](https://github.com/user-attachments/files/17774956/bbi-101140.ll.gz)\r\n", "author": "mikaelholmen", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "mikaelholmen", "body": "This starts happening with https://github.com/llvm/llvm-project/commit/680901ed8010319843cd81275b845d682f77e27f\r\n```\r\n[VPlan] Implement VPHeaderPHIRecipe::computeCost.\r\n\r\nFill out computeCost implementations for various header PHI recipes,\r\nmatching the legacy cost model for now.\r\n```" }, { "author": "mikaelholmen", "body": "Thanks!" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 8091, 8096 ], [ 17818, 17824 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec", "BoUpSLP::collectValuesToDemote" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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}", "lli_expected_out": null, "additional_args": 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
96012
https://github.com/llvm/llvm-project/issues/96012
hang
aad27bf534b59645f47a92f072af798687b1dd0d
2024-06-19T02:31:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "48ae61470104e9d7a8be5beb8739c24f52cc33c0", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ [ 90, 102 ], [ 309, 314 ], [ 537, 543 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [ [ 780, 790 ] ], "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ "Negator::Negate", "Negator::Negator", "Negator::visitImpl", "Negator::~Negator" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 48ae61470104e9d7a8be5beb8739c24f52cc33c0 Author: Yingwei Zheng <[email protected]> Date: Sat Aug 17 16:48:29 2024 +0800 [InstCombine] Avoid infinite loop when negating phi nodes (#104581) Closes https://github.com/llvm/llvm-project/issues/96012 --------- Co-authored-by: Nikita Popov <[email protected]> diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 16f1c3ba15eb..a0f2399972b5 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -780,11 +780,14 @@ class Negator final { using BuilderTy = IRBuilder<TargetFolder, IRBuilderCallbackInserter>; BuilderTy Builder; + const DominatorTree &DT; + const bool IsTrulyNegation; SmallDenseMap<Value *, Value *> NegationsCache; - Negator(LLVMContext &C, const DataLayout &DL, bool IsTrulyNegation); + Negator(LLVMContext &C, const DataLayout &DL, const DominatorTree &DT, + bool IsTrulyNegation); #if LLVM_ENABLE_STATS unsigned NumValuesVisitedInThisNegator = 0; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index 2dd1db6a4a75..92293ef40146 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -90,13 +90,14 @@ static cl::opt<unsigned> cl::desc("What is the maximal lookup depth when trying to " "check for viability of negation sinking.")); -Negator::Negator(LLVMContext &C, const DataLayout &DL, bool IsTrulyNegation_) +Negator::Negator(LLVMContext &C, const DataLayout &DL, const DominatorTree &DT_, + bool IsTrulyNegation_) : Builder(C, TargetFolder(DL), IRBuilderCallbackInserter([&](Instruction *I) { ++NegatorNumInstructionsCreatedTotal; NewInstructions.push_back(I); })), - IsTrulyNegation(IsTrulyNegation_) {} + DT(DT_), IsTrulyNegation(IsTrulyNegation_) {} #if LLVM_ENABLE_STATS Negator::~Negator() { @@ -309,6 +310,9 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { auto *PHI = cast<PHINode>(I); SmallVector<Value *, 4> NegatedIncomingValues(PHI->getNumOperands()); for (auto I : zip(PHI->incoming_values(), NegatedIncomingValues)) { + // Don't negate indvars to avoid infinite loops. + if (DT.dominates(PHI->getParent(), std::get<0>(I))) + return nullptr; if (!(std::get<1>(I) = negate(std::get<0>(I), IsNSW, Depth + 1))) // Early return. return nullptr; @@ -537,7 +541,8 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { if (!NegatorEnabled || !DebugCounter::shouldExecute(NegatorCounter)) return nullptr; - Negator N(Root->getContext(), IC.getDataLayout(), LHSIsZero); + Negator N(Root->getContext(), IC.getDataLayout(), IC.getDominatorTree(), + LHSIsZero); std::optional<Result> Res = N.run(Root, IsNSW); if (!Res) { // Negation failed. LLVM_DEBUG(dbgs() << "Negator: failed to sink negation into " << *Root
[ { "file": "llvm/test/Transforms/InstCombine/pr96012.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Make sure we don't hang here.\ndefine i32 @pr96012() {\n;\nentry:\n br label %for.cond\n\nfor.cond:\n %indvar = phi i32 [ 1, %entry ], [ %shl, %for.cond ]\n %conv1 = trunc i32 %indvar to i8\n %neg = sub i8 0, %conv1\n %conv2 = zext i8 %neg to i32\n %shl = shl nuw i32 %conv2, 24\n br label %for.cond\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "InstCombine gets stuck when sinking negation", "body": "Minimal reproducer (It looks over-reduced): https://godbolt.org/z/9zj5K8seP\r\n```\r\n; opt -passes=instcombine test.ll -S -debug\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @func_112() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond, %entry\r\n %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\n %conv5 = trunc i32 %l_139.0 to i8\r\n %call6 = sub i8 0, %conv5\r\n %conv7 = zext i8 %call6 to i32\r\n %0 = shl nuw i32 %conv7, 24\r\n br label %for.cond\r\n}\r\n```\r\n\r\n```\r\nINSTCOMBINE ITERATION #1 on func_112\r\nADD: br label %for.cond\r\nADD: %0 = shl nuw i32 %conv7, 24\r\nADD: %conv7 = zext i8 %call6 to i32\r\nADD: %call6 = sub i8 0, %conv5\r\nADD: %conv5 = trunc i32 %l_139.0 to i8\r\nADD: %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nADD: br label %for.cond\r\nIC: Visiting: br label %for.cond\r\nIC: Visiting: %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nIC: Visiting: %conv5 = trunc i32 %l_139.0 to i8\r\nIC: Visiting: %call6 = sub i8 0, %conv5\r\nNegator: attempting to sink negation into %conv5 = trunc i32 %l_139.0 to i8\r\nNegator: successfully sunk negation into %conv5 = trunc i32 %l_139.0 to i8\r\n NEW: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nNegator: Propagating 3 instrs to InstCombine\r\nADD DEFERRED: %.neg = mul i32 %conv7, -16777216\r\nADD DEFERRED: %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nADD DEFERRED: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nIC: Old = %call6 = sub i8 0, %conv5\r\n New = <badref> = add i8 %conv5.neg, 0\r\nADD: %call6 = add i8 %conv5.neg, 0\r\nIC: ERASE %0 = sub i8 0, %conv5\r\nADD DEFERRED: %conv5 = trunc i32 %l_139.0 to i8\r\nIC: ERASE %conv5 = trunc i32 %l_139.0 to i8\r\nADD DEFERRED: %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nIC: ERASE %l_139.0 = phi i32 [ 1, %entry ], [ %0, %for.cond ]\r\nADD DEFERRED: %0 = shl nuw i32 %conv7, 24\r\nIC: ERASE %0 = shl nuw i32 %conv7, 24\r\nADD DEFERRED: %conv7 = zext i8 %call6 to i32\r\nADD: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nADD: %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nADD: %.neg = mul i32 %conv7, -16777216\r\nIC: Visiting: %.neg = mul i32 %conv7, -16777216\r\nNegator: attempting to sink negation into %conv7 = zext i8 %call6 to i32\r\nNegator: failed to sink negation into %conv7 = zext i8 %call6 to i32\r\nADD DEFERRED: %call6.neg = sub i8 0, %call6\r\nADD DEFERRED: %call6.neg.z = zext i8 %call6.neg to i32\r\nIC: Old = %.neg = mul i32 %conv7, -16777216\r\n New = <badref> = shl i32 %call6.neg.z, 24\r\nADD: %.neg = shl i32 %call6.neg.z, 24\r\nIC: ERASE %0 = mul i32 %conv7, -16777216\r\nADD DEFERRED: %conv7 = zext i8 %call6 to i32\r\nIC: ERASE %conv7 = zext i8 %call6 to i32\r\nADD DEFERRED: %call6 = add i8 %conv5.neg, 0\r\nADD: %call6.neg.z = zext i8 %call6.neg to i32\r\nADD: %call6.neg = sub i8 0, %call6\r\nIC: Visiting: %call6.neg = sub i8 0, %call6\r\nIC: Old = %call6.neg = sub i8 0, %call6\r\n New = <badref> = sub i8 0, %conv5.neg\r\nADD: %call6.neg = sub i8 0, %conv5.neg\r\nIC: ERASE %0 = sub i8 0, %call6\r\nADD DEFERRED: %call6 = add i8 %conv5.neg, 0\r\nIC: ERASE %call6 = add i8 %conv5.neg, 0\r\nADD DEFERRED: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nADD DEFERRED: %call6.neg = sub i8 0, %conv5.neg\r\nIC: Visiting: %call6.neg = sub i8 0, %conv5.neg\r\nNegator: attempting to sink negation into %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nNegator: successfully sunk negation into %conv5.neg = trunc i32 %l_139.0.neg to i8\r\n NEW: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nNegator: Propagating 3 instrs to InstCombine\r\nADD DEFERRED: %.neg.neg = mul i32 %call6.neg.z, -16777216\r\nADD DEFERRED: %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nADD DEFERRED: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nIC: Old = %call6.neg = sub i8 0, %conv5.neg\r\n New = <badref> = add i8 %conv5.neg.neg, 0\r\nADD: %call6.neg = add i8 %conv5.neg.neg, 0\r\nIC: ERASE %0 = sub i8 0, %conv5.neg\r\nADD DEFERRED: %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nIC: ERASE %conv5.neg = trunc i32 %l_139.0.neg to i8\r\nADD DEFERRED: %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nIC: ERASE %l_139.0.neg = phi i32 [ -1, %entry ], [ %.neg, %for.cond ]\r\nADD DEFERRED: %.neg = shl i32 %call6.neg.z, 24\r\nIC: ERASE %.neg = shl i32 %call6.neg.z, 24\r\nADD DEFERRED: %call6.neg.z = zext i8 %call6.neg to i32\r\nADD: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nADD: %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nADD: %.neg.neg = mul i32 %call6.neg.z, -16777216\r\nIC: Visiting: %.neg.neg = mul i32 %call6.neg.z, -16777216\r\nNegator: attempting to sink negation into %call6.neg.z = zext i8 %call6.neg to i32\r\nNegator: failed to sink negation into %call6.neg.z = zext i8 %call6.neg to i32\r\nADD DEFERRED: %call6.neg.neg = sub i8 0, %call6.neg\r\nADD DEFERRED: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nIC: Old = %.neg.neg = mul i32 %call6.neg.z, -16777216\r\n New = <badref> = shl i32 %call6.neg.neg.z, 24\r\nADD: %.neg.neg = shl i32 %call6.neg.neg.z, 24\r\nIC: ERASE %0 = mul i32 %call6.neg.z, -16777216\r\nADD DEFERRED: %call6.neg.z = zext i8 %call6.neg to i32\r\nIC: ERASE %call6.neg.z = zext i8 %call6.neg to i32\r\nADD DEFERRED: %call6.neg = add i8 %conv5.neg.neg, 0\r\nADD: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD: %call6.neg.neg = sub i8 0, %call6.neg\r\nIC: Visiting: %call6.neg.neg = sub i8 0, %call6.neg\r\nIC: Old = %call6.neg.neg = sub i8 0, %call6.neg\r\n New = <badref> = sub i8 0, %conv5.neg.neg\r\nADD: %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\nIC: ERASE %0 = sub i8 0, %call6.neg\r\nADD DEFERRED: %call6.neg = add i8 %conv5.neg.neg, 0\r\nIC: ERASE %call6.neg = add i8 %conv5.neg.neg, 0\r\nADD DEFERRED: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nADD DEFERRED: %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\nIC: Visiting: %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\nNegator: attempting to sink negation into %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nNegator: successfully sunk negation into %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\n NEW: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nNegator: Propagating 3 instrs to InstCombine\r\nADD DEFERRED: %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\nADD DEFERRED: %l_139.0.neg.neg.neg = phi i32 [ -1, %entry ], [ %.neg.neg.neg, %for.cond ]\r\nADD DEFERRED: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nIC: Old = %call6.neg.neg = sub i8 0, %conv5.neg.neg\r\n New = <badref> = add i8 %conv5.neg.neg.neg, 0\r\nADD: %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nIC: ERASE %0 = sub i8 0, %conv5.neg.neg\r\nADD DEFERRED: %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nIC: ERASE %conv5.neg.neg = trunc i32 %l_139.0.neg.neg to i8\r\nADD DEFERRED: %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nIC: ERASE %l_139.0.neg.neg = phi i32 [ 1, %entry ], [ %.neg.neg, %for.cond ]\r\nADD DEFERRED: %.neg.neg = shl i32 %call6.neg.neg.z, 24\r\nIC: ERASE %.neg.neg = shl i32 %call6.neg.neg.z, 24\r\nADD DEFERRED: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nADD: %l_139.0.neg.neg.neg = phi i32 [ -1, %entry ], [ %.neg.neg.neg, %for.cond ]\r\nADD: %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\nIC: Visiting: %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\nNegator: attempting to sink negation into %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nNegator: failed to sink negation into %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD DEFERRED: %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\nADD DEFERRED: %call6.neg.neg.neg.z = zext i8 %call6.neg.neg.neg to i32\r\nIC: Old = %.neg.neg.neg = mul i32 %call6.neg.neg.z, -16777216\r\n New = <badref> = shl i32 %call6.neg.neg.neg.z, 24\r\nADD: %.neg.neg.neg = shl i32 %call6.neg.neg.neg.z, 24\r\nIC: ERASE %0 = mul i32 %call6.neg.neg.z, -16777216\r\nADD DEFERRED: %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nIC: ERASE %call6.neg.neg.z = zext i8 %call6.neg.neg to i32\r\nADD DEFERRED: %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nADD: %call6.neg.neg.neg.z = zext i8 %call6.neg.neg.neg to i32\r\nADD: %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\nIC: Visiting: %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\nIC: Old = %call6.neg.neg.neg = sub i8 0, %call6.neg.neg\r\n New = <badref> = sub i8 0, %conv5.neg.neg.neg\r\nADD: %call6.neg.neg.neg = sub i8 0, %conv5.neg.neg.neg\r\nIC: ERASE %0 = sub i8 0, %call6.neg.neg\r\nADD DEFERRED: %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nIC: ERASE %call6.neg.neg = add i8 %conv5.neg.neg.neg, 0\r\nADD DEFERRED: %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nADD DEFERRED: %call6.neg.neg.neg = sub i8 0, %conv5.neg.neg.neg\r\nIC: Visiting: %call6.neg.neg.neg = sub i8 0, %conv5.neg.neg.neg\r\nNegator: attempting to sink negation into %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\nNegator: successfully sunk negation into %conv5.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg to i8\r\n NEW: %conv5.neg.neg.neg.neg = trunc i32 %l_139.0.neg.neg.neg.neg to i8\r\n...\r\n```", "author": "dtcxzyw", "labels": [ "llvm:instcombine", "llvm:hang" ], "comments": [] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ [ 1039, 1049 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ "InstCombinerImpl::SimplifyDemandedUseBits" ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
91369
https://github.com/llvm/llvm-project/issues/91369
miscompilation
9a28814f59e8f52cc63ae3d17023cee8348d9b53
2024-05-07T18:12:26
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "082c81ae4ab9db6bb0acd52098288223dd58501a", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 8841, 8848 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 082c81ae4ab9db6bb0acd52098288223dd58501a Author: Florian Hahn <[email protected]> Date: Tue May 7 21:31:40 2024 +0100 [LV] Properly extend versioned constant strides. We only version unknown strides to 1. If the original type is i1, then the sign of the extension matters. Properly extend the stride value before replacing it. Fixes https://github.com/llvm/llvm-project/issues/91369. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 3be0102bea3e..261933966b74 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8841,8 +8841,10 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) { VPValue *StrideVPV = Plan->getLiveIn(U); if (!StrideVPV) continue; - VPValue *CI = Plan->getOrAddLiveIn(ConstantInt::get( - U->getType(), ScevStride->getAPInt().getSExtValue())); + unsigned BW = U->getType()->getScalarSizeInBits(); + APInt C = isa<SExtInst>(U) ? ScevStride->getAPInt().sext(BW) + : ScevStride->getAPInt().zext(BW); + VPValue *CI = Plan->getOrAddLiveIn(ConstantInt::get(U->getType(), C)); StrideVPV->replaceAllUsesWith(CI); } }
[ { "file": "llvm/test/Transforms/LoopVectorize/version-stride-with-integer-casts.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "zext_of_i1_stride", "test_body": "target datalayout = \"p:8:8:8\"\n\n; Function Attrs: mustprogress\ndefine void @zext_of_i1_stride(i1 %g, ptr %dst) #0 {\nentry:\n %g.16 = zext i1 %g to i16\n %g.64 = zext i1 %g to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %g.16, ptr %gep, align 2\n %iv.next = add nuw nsw i64 %iv, %g.64\n %cmp = icmp ult i64 %iv.next, 16\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { mustprogress }\n", "lli_expected_out": null, "additional_args": "-src-unroll=32 -tgt-unroll=32" } ] } ]
{ "title": "[LoopVectorize] Sign-extension miscompile", "body": "C Testcase:\r\n```c\r\nlong a, d;\r\nshort b[20];\r\nshort c[20];\r\n_Bool e[20];\r\nint f(_Bool g) {\r\n for (long h = 0; h < 16; h += g)\r\n b[h] = (short) g;\r\n for (int i = 0; i < 12; i++)\r\n for (int j = d; j; j++)\r\n c[i] = (short) a < e[i];\r\n return (int) b[0];\r\n}\r\nint main() {\r\n __builtin_printf(\"%X\\n\", f(1));\r\n}\r\n```\r\nGodbolt: https://godbolt.org/z/3E8frs1Me\r\n\r\nWith loop-vectorize: `FFFFFFFF`\r\nWithout loop-vectorize: `1`\r\n\r\nReduced LLVM IR:\r\n```llvm ir\r\n; ModuleID = 'red.ll'\r\nsource_filename = \"red.c\"\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\n@b = global [20 x i16] zeroinitializer, align 2\r\[email protected] = constant [4 x i8] c\"%X\\0A\\00\"\r\n\r\n; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable vscale_range(2,1024)\r\ndefine i32 @f(i1 %g) #0 {\r\nentry:\r\n %conv = zext i1 %g to i16\r\n %zext.g.i64 = zext i1 %g to i64\r\n br label %for.body\r\n\r\nfor.cond3.preheader: ; preds = %for.body\r\n %0 = load i64, ptr @b, align 2\r\n %zero = and i64 %0, 0\r\n %true = icmp eq i64 %zero, 0\r\n %2 = load i16, ptr @b, align 2\r\n %conv26 = sext i16 %2 to i32\r\n ret i32 %conv26\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %phi.0 = phi i64 [ 0, %entry ], [ %add, %for.body ]\r\n %idx.0 = getelementptr inbounds [20 x i16], ptr @b, i64 0, i64 %phi.0\r\n store i16 %conv, ptr %idx.0, align 2\r\n %add = add nuw nsw i64 %phi.0, %zext.g.i64\r\n %cmp = icmp ult i64 %add, 16\r\n br i1 %cmp, label %for.body, label %for.cond3.preheader, !llvm.loop !0\r\n}\r\n\r\n; Function Attrs: nofree nounwind uwtable vscale_range(2,1024)\r\ndefine noundef signext i32 @main() #1 {\r\nentry:\r\n %call = tail call signext i32 @f(i1 noundef zeroext true)\r\n %call1 = tail call signext i32 (ptr, ...) @printf(ptr noundef nonnull @.str, i32 noundef signext %call) #3\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nofree nounwind\r\ndeclare noundef signext i32 @printf(ptr nocapture noundef readonly, ...) #2\r\n\r\nattributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable vscale_range(2,1024) \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+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,-smstateen,-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,-zama16b,-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,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\nattributes #1 = { nofree nounwind uwtable vscale_range(2,1024) \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+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,-smstateen,-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,-zama16b,-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,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\nattributes #2 = { nofree nounwind \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+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,-smstateen,-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,-zama16b,-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,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\nattributes #3 = { nounwind }\r\n\r\n!0 = distinct !{!0, !1}\r\n!1 = !{!\"llvm.loop.mustprogress\"}\r\n```\r\nLoopVectorize pass.\r\n\r\nLooks like a sext/zext related issue.", "author": "patrick-rivos", "labels": [ "miscompilation", "vectorizers" ], "comments": [] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 1669, 1675 ], [ 1677, 1684 ], [ 1727, 1740 ], [ 1750, 1759 ] ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::foldShuffleOfBinops" ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ [ 895, 901 ], [ 948, 953 ], [ 979, 995 ] ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::truncateToMinimalBitwidths" ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
108620
https://github.com/llvm/llvm-project/issues/108620
crash
03618ceabd003be94190b068db11b607fd1108ef
2024-09-13T18:15:02
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "1e3536ef3141d6429f3616af624b81b6d6ab2959", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 1283, 1293 ], [ 14222, 14235 ], [ 14373, 14378 ], [ 14426, 14436 ], [ 14530, 14537 ], [ 14757, 14762 ], [ 17660, 17666 ], [ 17956, 17961 ], [ 18024, 18031 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::vectorizeTree", "tryToReduce" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 1e3536ef3141d6429f3616af624b81b6d6ab2959 Author: Alexey Bataev <[email protected]> Date: Fri Sep 13 15:40:22 2024 -0700 [SLP]Fix PR108620: Need to check, if the reduced value was transformed Before trying to include the scalar into the list of ExternallyUsedValues, need to check, if it was transformed in previous iteration and use the transformed value, not the original one, to avoid compiler crash when building external uses. Fixes https://github.com/llvm/llvm-project/issues/108620 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 0afe02fc08ff..5f2bf082fb87 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1283,11 +1283,8 @@ public: /// Vectorize the tree but with the list of externally used values \p /// ExternallyUsedValues. Values in this MapVector can be replaced but the /// generated extractvalue instructions. - /// \param ReplacedExternals containd list of replaced external values - /// {scalar, replace} after emitting extractelement for external uses. Value * vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, - SmallVectorImpl<std::pair<Value *, Value *>> &ReplacedExternals, Instruction *ReductionRoot = nullptr); /// \returns the cost incurred by unwanted spills and fills, caused by @@ -14222,14 +14219,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *BoUpSLP::vectorizeTree() { ExtraValueToDebugLocsMap ExternallyUsedValues; - SmallVector<std::pair<Value *, Value *>> ReplacedExternals; - return vectorizeTree(ExternallyUsedValues, ReplacedExternals); + return vectorizeTree(ExternallyUsedValues); } -Value *BoUpSLP::vectorizeTree( - const ExtraValueToDebugLocsMap &ExternallyUsedValues, - SmallVectorImpl<std::pair<Value *, Value *>> &ReplacedExternals, - Instruction *ReductionRoot) { +Value * +BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, + Instruction *ReductionRoot) { // All blocks must be scheduled before any instructions are inserted. for (auto &BSIter : BlocksSchedules) { scheduleBlock(BSIter.second.get()); @@ -14373,6 +14368,7 @@ Value *BoUpSLP::vectorizeTree( SmallDenseSet<Value *, 4> UsedInserts; DenseMap<std::pair<Value *, Type *>, Value *> VectorCasts; SmallDenseSet<Value *, 4> ScalarsWithNullptrUser; + SmallDenseSet<ExtractElementInst *, 4> IgnoredExtracts; // Extract all of the elements with the external uses. for (const auto &ExternalUse : ExternalUses) { Value *Scalar = ExternalUse.Scalar; @@ -14426,11 +14422,16 @@ Value *BoUpSLP::vectorizeTree( if (ReplaceInst) { // Leave the instruction as is, if it cheaper extracts and all // operands are scalar. - auto *CloneInst = Inst->clone(); - CloneInst->insertBefore(Inst); - if (Inst->hasName()) - CloneInst->takeName(Inst); - Ex = CloneInst; + if (auto *EE = dyn_cast<ExtractElementInst>(Inst)) { + IgnoredExtracts.insert(EE); + Ex = EE; + } else { + auto *CloneInst = Inst->clone(); + CloneInst->insertBefore(Inst); + if (Inst->hasName()) + CloneInst->takeName(Inst); + Ex = CloneInst; + } } else if (auto *ES = dyn_cast<ExtractElementInst>(Scalar); ES && isa<Instruction>(Vec)) { Value *V = ES->getVectorOperand(); @@ -14530,8 +14531,12 @@ Value *BoUpSLP::vectorizeTree( } Value *NewInst = ExtractAndExtendIfNeeded(Vec); // Required to update internally referenced instructions. - Scalar->replaceAllUsesWith(NewInst); - ReplacedExternals.emplace_back(Scalar, NewInst); + if (Scalar != NewInst) { + assert((!isa<ExtractElementInst>(Scalar) || + !IgnoredExtracts.contains(cast<ExtractElementInst>(Scalar))) && + "Extractelements should not be replaced."); + Scalar->replaceAllUsesWith(NewInst); + } continue; } @@ -14757,6 +14762,9 @@ Value *BoUpSLP::vectorizeTree( if (Entry->getOpcode() == Instruction::GetElementPtr && !isa<GetElementPtrInst>(Scalar)) continue; + if (auto *EE = dyn_cast<ExtractElementInst>(Scalar); + EE && IgnoredExtracts.contains(EE)) + continue; #ifndef NDEBUG Type *Ty = Scalar->getType(); if (!Ty->isVoidTy()) { @@ -17660,7 +17668,6 @@ public: // because of the vectorization. DenseMap<Value *, WeakTrackingVH> TrackedVals(ReducedVals.size() * ReducedVals.front().size()); - SmallVector<std::pair<Value *, Value *>> ReplacedExternals; // The compare instruction of a min/max is the insertion point for new // instructions and may be replaced with a new compare instruction. @@ -17956,6 +17963,8 @@ public: if (Cnt >= Pos && Cnt < Pos + ReduxWidth) continue; Value *RdxVal = Candidates[Cnt]; + if (auto It = TrackedVals.find(RdxVal); It != TrackedVals.end()) + RdxVal = It->second; if (!Visited.insert(RdxVal).second) continue; // Check if the scalar was vectorized as part of the vectorization @@ -18024,8 +18033,8 @@ public: InsertPt = GetCmpForMinMaxReduction(RdxRootInst); // Vectorize a tree. - Value *VectorizedRoot = V.vectorizeTree(LocalExternallyUsedValues, - ReplacedExternals, InsertPt); + Value *VectorizedRoot = + V.vectorizeTree(LocalExternallyUsedValues, InsertPt); Builder.SetInsertPoint(InsertPt);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-val-extracted-and-externally-used.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(i32 %arg) {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %add27, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add24, %bb1 ]\n %phi3 = phi i32 [ 0, %bb ], [ %xor26, %bb1 ]\n %add = add i32 %phi2, 0\n %add4 = add i32 %phi2, 0\n %xor = xor i32 %add, %add4\n %add5 = add i32 %phi, 0\n %add6 = add i32 %phi2, 0\n %add7 = add i32 %phi2, 0\n %xor8 = xor i32 %add6, %xor\n %xor9 = xor i32 %xor8, %add5\n %xor10 = xor i32 %xor9, %add7\n %add11 = add i32 %phi, 0\n %add12 = add i32 %phi2, 0\n %add13 = add i32 %phi2, 0\n %xor14 = xor i32 %add12, %xor10\n %xor15 = xor i32 %xor14, %add11\n %xor16 = xor i32 %xor15, %add13\n %add17 = add i32 %phi, 0\n %add18 = add i32 %phi2, 0\n %add19 = add i32 %phi2, 0\n %xor20 = xor i32 %add18, %xor16\n %xor21 = xor i32 %xor20, %add17\n %xor22 = xor i32 %xor21, %add19\n %add23 = add i32 %phi2, 0\n %add24 = add i32 %arg, 0\n %xor25 = xor i32 %add23, %xor22\n %xor26 = xor i32 %xor25, %add24\n %add27 = add i32 1, 0\n %icmp = icmp ult i32 %add27, 0\n br label %bb1\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run the following test with -passes=slp-vectorizer\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat(i32 %arg) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %add27, %bb1 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ %add24, %bb1 ]\r\n %phi3 = phi i32 [ 0, %bb ], [ %xor26, %bb1 ]\r\n %add = add i32 %phi2, 0\r\n %add4 = add i32 %phi2, 0\r\n %xor = xor i32 %add, %add4\r\n %add5 = add i32 %phi, 0\r\n %add6 = add i32 %phi2, 0\r\n %add7 = add i32 %phi2, 0\r\n %xor8 = xor i32 %add6, %xor\r\n %xor9 = xor i32 %xor8, %add5\r\n %xor10 = xor i32 %xor9, %add7\r\n %add11 = add i32 %phi, 0\r\n %add12 = add i32 %phi2, 0\r\n %add13 = add i32 %phi2, 0\r\n %xor14 = xor i32 %add12, %xor10\r\n %xor15 = xor i32 %xor14, %add11\r\n %xor16 = xor i32 %xor15, %add13\r\n %add17 = add i32 %phi, 0\r\n %add18 = add i32 %phi2, 0\r\n %add19 = add i32 %phi2, 0\r\n %xor20 = xor i32 %add18, %xor16\r\n %xor21 = xor i32 %xor20, %add17\r\n %xor22 = xor i32 %xor21, %add19\r\n %add23 = add i32 %phi2, 0\r\n %add24 = add i32 %arg, 0\r\n %xor25 = xor i32 %add23, %xor22\r\n %xor26 = xor i32 %xor25, %add24\r\n %add27 = add i32 1, 0\r\n %icmp = icmp ult i32 %add27, 0\r\n br label %bb1\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/77hKre61P\r\n\r\nStack dump:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2663: 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 \"wombat\"\r\n #0 0x00000000050106b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50106b8)\r\n #1 0x000000000500ddfc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000737fffa42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x0000737fffa969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000737fffa42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x0000737fffa287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x0000737fffa2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000737fffa39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000040b91cf void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b91cf)\r\n #9 0x000000000410b80a 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+0x410b80a)\r\n#10 0x0000000004115bed (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x0000000004118321 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+0x4118321)\r\n#12 0x000000000411cb18 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x411cb18)\r\n#13 0x00000000041212fa llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41212fa)\r\n#14 0x0000000004127719 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 0x00000000041283cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41283cb)\r\n#16 0x0000000002efda4e 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+0x2efda4e)\r\n#17 0x0000000004e12948 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e12948)\r\n#18 0x0000000000e06f8e 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+0xe06f8e)\r\n#19 0x0000000004e1136e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e1136e)\r\n#20 0x0000000000e0679e 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+0xe0679e)\r\n#21 0x0000000004e10da0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e10da0)\r\n#22 0x00000000008fb642 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+0x8fb642)\r\n#23 0x00000000008ee4cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ee4cc)\r\n#24 0x0000737fffa29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x0000737fffa29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008e5f9e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e5f9e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
117133
https://github.com/llvm/llvm-project/issues/117133
miscompilation
94df95de6bab20930c1a77bc785221ff2f670dba
2024-11-21T09:18:16
[ "llvm/test/Analysis/ScalarEvolution", "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "f7ef0721d60f85e1f699f8d1b83d4402ae19b122", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ [ 4307, 4321 ], [ 5933, 5950 ], [ 7324, 7329 ] ], "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": [ [ 2187, 2192 ] ], "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::createAddRecFromPHI", "ScalarEvolution::getSequentialMinMaxExpr", "ScalarEvolution::isGuaranteedNotToBePoison", "ScalarEvolution::isSCEVExprNeverPoison" ], "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit f7ef0721d60f85e1f699f8d1b83d4402ae19b122 Author: Yingwei Zheng <[email protected]> Date: Sun Dec 1 20:11:09 2024 +0800 [SCEV] Do not allow refinement in the rewriting of BEValue (#117152) See the following case: ``` ; bin/opt -passes="print<scalar-evolution>" test.ll --disable-output define i32 @widget() { b: br label %b1 b1: ; preds = %b5, %b %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ] %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ] %icmp = icmp eq i32 %phi, 0 br i1 %icmp, label %b3, label %b8 b3: ; preds = %b1 %udiv = udiv i32 10, %phi2 %urem = urem i32 %udiv, 10 %icmp4 = icmp eq i32 %urem, 0 br i1 %icmp4, label %b7, label %b5 b5: ; preds = %b3 %udiv6 = udiv i32 %phi2, 0 %add = add i32 %phi2, 1 br label %b1 b7: ; preds = %b3 ret i32 5 b8: ; preds = %b1 ret i32 7 } ``` ``` %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ] --> {1,+,1}<nuw><nsw><%b1> %udiv6 = udiv i32 %phi2, 0 --> ({1,+,1}<nuw><nsw><%b1> /u 0) %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ] --> ({0,+,1}<nuw><nsw><%b1> /u 0) ``` `ScalarEvolution::createAddRecFromPHI` gives a wrong SCEV result for `%phi`: https://github.com/llvm/llvm-project/blob/d7d6fb1804415b0f3e7f1cc9290bfb3d711cb707/llvm/lib/Analysis/ScalarEvolution.cpp#L5926-L5950 It converts `phi(0, ({1,+,1}<nuw><nsw><%b1> /u 0))` into `phi(0 / 0, ({1,+,1}<nuw><nsw><%b1> /u 0))`. Then it simplifies the expr into `{0,+,1}<nuw><nsw><%b1> /u 0`. As we did in https://github.com/llvm/llvm-project/commit/acd700a24b6f767413db3d525e06d03e4245aa40, this patch disallows udiv simplification if we cannot prove that the denominator is a well-defined non-zero value. Fixes https://github.com/llvm/llvm-project/issues/117133. diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 885c5985f9d2..b20c6a13cb6b 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -2187,6 +2187,9 @@ private: bool isGuaranteedToTransferExecutionTo(const Instruction *A, const Instruction *B); + /// Returns true if \p Op is guaranteed not to cause immediate UB. + bool isGuaranteedNotToCauseUB(const SCEV *Op); + /// Returns true if \p Op is guaranteed to not be poison. static bool isGuaranteedNotToBePoison(const SCEV *Op); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index c3f296b9ff33..882e938e69c0 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -4307,15 +4307,7 @@ ScalarEvolution::getSequentialMinMaxExpr(SCEVTypes Kind, } for (unsigned i = 1, e = Ops.size(); i != e; ++i) { - bool MayBeUB = SCEVExprContains(Ops[i], [this](const SCEV *S) { - auto *UDiv = dyn_cast<SCEVUDivExpr>(S); - // The UDiv may be UB if the divisor is poison or zero. Unless the divisor - // is a non-zero constant, we have to assume the UDiv may be UB. - return UDiv && (!isKnownNonZero(UDiv->getOperand(1)) || - !isGuaranteedNotToBePoison(UDiv->getOperand(1))); - }); - - if (MayBeUB) + if (!isGuaranteedNotToCauseUB(Ops[i])) continue; // We can replace %x umin_seq %y with %x umin %y if either: // * %y being poison implies %x is also poison. @@ -5933,18 +5925,22 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) { // We can generalize this saying that i is the shifted value of BEValue // by one iteration: // PHI(f(0), f({1,+,1})) --> f({0,+,1}) - const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this); - const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false); - if (Shifted != getCouldNotCompute() && - Start != getCouldNotCompute()) { - const SCEV *StartVal = getSCEV(StartValueV); - if (Start == StartVal) { - // Okay, for the entire analysis of this edge we assumed the PHI - // to be symbolic. We now need to go back and purge all of the - // entries for the scalars that use the symbolic expression. - forgetMemoizedResults(SymbolicName); - insertValueToMap(PN, Shifted); - return Shifted; + + // Do not allow refinement in rewriting of BEValue. + if (isGuaranteedNotToCauseUB(BEValue)) { + const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this); + const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false); + if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() && + ::impliesPoison(BEValue, Start)) { + const SCEV *StartVal = getSCEV(StartValueV); + if (Start == StartVal) { + // Okay, for the entire analysis of this edge we assumed the PHI + // to be symbolic. We now need to go back and purge all of the + // entries for the scalars that use the symbolic expression. + forgetMemoizedResults(SymbolicName); + insertValueToMap(PN, Shifted); + return Shifted; + } } } } @@ -7324,6 +7320,16 @@ bool ScalarEvolution::isGuaranteedNotToBePoison(const SCEV *Op) { return PC.MaybePoison.empty(); } +bool ScalarEvolution::isGuaranteedNotToCauseUB(const SCEV *Op) { + return !SCEVExprContains(Op, [this](const SCEV *S) { + auto *UDiv = dyn_cast<SCEVUDivExpr>(S); + // The UDiv may be UB if the divisor is poison or zero. Unless the divisor + // is a non-zero constant, we have to assume the UDiv may be UB. + return UDiv && (!isKnownNonZero(UDiv->getOperand(1)) || + !isGuaranteedNotToBePoison(UDiv->getOperand(1))); + }); +} + bool ScalarEvolution::isSCEVExprNeverPoison(const Instruction *I) { // Only proceed if we can prove that I does not yield poison. if (!programUndefinedIfPoison(I))
[ { "file": "llvm/test/Analysis/ScalarEvolution/pr117133.ll", "commands": [ "opt -S -disable-output \"-passes=print<scalar-evolution>\" < %s 2>&1" ], "tests": [ { "test_name": "test_poisonous", "test_body": "define i64 @test_poisonous(i64 %a, i32 %n) {\nentry:\n br label %loop.body\n\nloop.body: ; preds = %loop.body, %entry\n %indvar1 = phi i32 [ 0, %entry ], [ %indvar1.next, %loop.body ]\n %indvar2 = phi i64 [ 0, %entry ], [ %mul, %loop.body ]\n %indvar1.next = add i32 %indvar1, 1\n %ext = zext i32 %indvar1.next to i64\n %mul = mul i64 %ext, %a\n %exitcond = icmp sgt i32 %indvar1.next, %n\n br i1 %exitcond, label %loop.exit, label %loop.body\n\nloop.exit: ; preds = %loop.body\n ret i64 %mul\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "widget", "test_body": "define i32 @widget() {\nb:\n br label %b1\n\nb1: ; preds = %b5, %b\n %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ]\n %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %b3, label %b8\n\nb3: ; preds = %b1\n %udiv = udiv i32 10, %phi2\n %urem = urem i32 %udiv, 10\n %icmp4 = icmp eq i32 %urem, 0\n br i1 %icmp4, label %b7, label %b5\n\nb5: ; preds = %b3\n %udiv6 = udiv i32 %phi2, 0\n %add = add i32 %phi2, 1\n br label %b1\n\nb7: ; preds = %b3\n ret i32 5\n\nb8: ; preds = %b1\n ret i32 7\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/IndVarSimplify/pr117133.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "widget", "test_body": "define i32 @widget() {\nb:\n br label %b1\n\nb1: ; preds = %b5, %b\n %phi = phi i32 [ 0, %b ], [ %udiv6, %b5 ]\n %phi2 = phi i32 [ 1, %b ], [ %add, %b5 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %b3, label %b8\n\nb3: ; preds = %b1\n %udiv = udiv i32 10, %phi2\n %urem = urem i32 %udiv, 10\n %icmp4 = icmp eq i32 %urem, 0\n br i1 %icmp4, label %b7, label %b5\n\nb5: ; preds = %b3\n %udiv6 = udiv i32 %phi2, 0\n %add = add i32 %phi2, 1\n br label %b1\n\nb7: ; preds = %b3\n ret i32 5\n\nb8: ; preds = %b1\n ret i32 7\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[indvars] Miscompile when loop body has an operation with Undefined Behaviour", "body": "Here is the problematic IR:\r\n```\r\ndefine i32 @widget() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb5, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %udiv6, %bb5 ]\r\n %phi2 = phi i32 [ 1, %bb ], [ %add, %bb5 ]\r\n %icmp = icmp eq i32 %phi, 0\r\n br i1 %icmp, label %bb3, label %bb8\r\n\r\nbb3: ; preds = %bb1\r\n %udiv = udiv i32 10, %phi2\r\n %urem = urem i32 %udiv, 10\r\n %icmp4 = icmp eq i32 %urem, 0\r\n br i1 %icmp4, label %bb7, label %bb5\r\n\r\nbb5: ; preds = %bb3\r\n %udiv6 = udiv i32 %phi2, 0\r\n %add = add i32 %phi2, 1\r\n br label %bb1\r\n\r\nbb7: ; preds = %bb3\r\n ret i32 5\r\n\r\nbb8: ; preds = %bb1\r\n ret i32 7\r\n}\r\n```\r\nproduces incorrect IR when `indvars` pass is run. I suspect this is because of the `%udiv6 = udiv i32 %phi2, 0` divide by zero operation. \r\nLook at the indvars transformation here: https://godbolt.org/z/cz1r5178h\r\nThe original IR must return 5, while the transformed IR returns 7\r\n\r\nProof of wrong transformation: https://alive2.llvm.org/ce/z/vPFhzg", "author": "Nirhar", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "nikic", "body": "Is this a fuzzer-generated test case?" }, { "author": "Nirhar", "body": "> Is this a fuzzer-generated test case?\n\nHi @nikic , yes this test was fuzzer-generated." } ] }
true
null
110382
https://github.com/llvm/llvm-project/issues/110382
crash
72a957ba4c8ef059f1572f6d4ee0cba8dc615268
2024-09-28T19:00:52
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "c136d3237a3c6230cfe1ab3f0f6790f903c54a27", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 1984, 2016 ], [ 2038, 2044 ] ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::foldShuffleToIdentity" ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit c136d3237a3c6230cfe1ab3f0f6790f903c54a27 Author: David Green <[email protected]> Date: Wed Oct 9 16:20:03 2024 +0100 [VectorCombine] Do not try to operate on OperandBundles. (#111635) This bails out if we see an intrinsic with an operand bundle on it, to make sure we don't process the bundles incorrectly. Fixes #110382. diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index a2ab5d966640..627edb680dfa 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1984,33 +1984,35 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) { // We need each element to be the same type of value, and check that each // element has a single use. - if (all_of(drop_begin(Item), [Item](InstLane IL) { - Value *FrontV = Item.front().first->get(); - if (!IL.first) - return true; - Value *V = IL.first->get(); - if (auto *I = dyn_cast<Instruction>(V); I && !I->hasOneUse()) - return false; - if (V->getValueID() != FrontV->getValueID()) - return false; - if (auto *CI = dyn_cast<CmpInst>(V)) - if (CI->getPredicate() != cast<CmpInst>(FrontV)->getPredicate()) - return false; - if (auto *CI = dyn_cast<CastInst>(V)) - if (CI->getSrcTy() != cast<CastInst>(FrontV)->getSrcTy()) - return false; - if (auto *SI = dyn_cast<SelectInst>(V)) - if (!isa<VectorType>(SI->getOperand(0)->getType()) || - SI->getOperand(0)->getType() != - cast<SelectInst>(FrontV)->getOperand(0)->getType()) - return false; - if (isa<CallInst>(V) && !isa<IntrinsicInst>(V)) - return false; - auto *II = dyn_cast<IntrinsicInst>(V); - return !II || (isa<IntrinsicInst>(FrontV) && - II->getIntrinsicID() == - cast<IntrinsicInst>(FrontV)->getIntrinsicID()); - })) { + auto CheckLaneIsEquivalentToFirst = [Item](InstLane IL) { + Value *FrontV = Item.front().first->get(); + if (!IL.first) + return true; + Value *V = IL.first->get(); + if (auto *I = dyn_cast<Instruction>(V); I && !I->hasOneUse()) + return false; + if (V->getValueID() != FrontV->getValueID()) + return false; + if (auto *CI = dyn_cast<CmpInst>(V)) + if (CI->getPredicate() != cast<CmpInst>(FrontV)->getPredicate()) + return false; + if (auto *CI = dyn_cast<CastInst>(V)) + if (CI->getSrcTy() != cast<CastInst>(FrontV)->getSrcTy()) + return false; + if (auto *SI = dyn_cast<SelectInst>(V)) + if (!isa<VectorType>(SI->getOperand(0)->getType()) || + SI->getOperand(0)->getType() != + cast<SelectInst>(FrontV)->getOperand(0)->getType()) + return false; + if (isa<CallInst>(V) && !isa<IntrinsicInst>(V)) + return false; + auto *II = dyn_cast<IntrinsicInst>(V); + return !II || (isa<IntrinsicInst>(FrontV) && + II->getIntrinsicID() == + cast<IntrinsicInst>(FrontV)->getIntrinsicID() && + !II->hasOperandBundles()); + }; + if (all_of(drop_begin(Item), CheckLaneIsEquivalentToFirst)) { // Check the operator is one that we support. if (isa<BinaryOperator, CmpInst>(FrontU)) { // We exclude div/rem in case they hit UB from poison lanes. @@ -2038,7 +2040,8 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) { Worklist.push_back(generateInstLaneVectorFromOperand(Item, 2)); continue; } else if (auto *II = dyn_cast<IntrinsicInst>(FrontU); - II && isTriviallyVectorizable(II->getIntrinsicID())) { + II && isTriviallyVectorizable(II->getIntrinsicID()) && + !II->hasOperandBundles()) { for (unsigned Op = 0, E = II->getNumOperands() - 1; Op < E; Op++) { if (isVectorIntrinsicWithScalarOpAtArg(II->getIntrinsicID(), Op)) { if (!all_of(drop_begin(Item), [Item, Op](InstLane &IL) {
[ { "file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "add_same_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @add_same_operands(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add = add <4 x i32> %shuf, %shuf\n %revshuf = shufflevector <4 x i32> %add, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i32> %revshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "extrause_add_same_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @extrause_add_same_operands(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add = add <4 x i32> %shuf, %shuf\n %revshuf = shufflevector <4 x i32> %add, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add2 = add <4 x i32> %shuf, %revshuf\n ret <4 x i32> %add2\n}\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null }, { "test_name": "poison_intrinsic", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @poison_intrinsic(<2 x i16> %l256) {\n %l266 = call <2 x i16> @llvm.abs.v2i16(<2 x i16> %l256, i1 false)\n %l267 = zext <2 x i16> %l266 to <2 x i32>\n %l271 = shufflevector <2 x i32> %l267, <2 x i32> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>\n ret <4 x i32> %l271\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <2 x i16> @llvm.abs.v2i16(<2 x i16>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "splattwice", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splattwice(<8 x half> %a, <8 x half> %b) {\n %as = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> zeroinitializer\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> zeroinitializer\n %ab1 = fadd <4 x half> %as, %bs\n %ab2 = fadd <4 x half> %as, %bs\n %r = shufflevector <4 x half> %ab1, <4 x half> %ab2, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "fadd_mismatched_types", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x float> @fadd_mismatched_types(<4 x float> %x, <4 x float> %y) {\n %shuf.x = shufflevector <4 x float> %x, <4 x float> poison, <2 x i32> <i32 0, i32 2>\n %shuf.y = shufflevector <4 x float> %y, <4 x float> poison, <2 x i32> <i32 1, i32 3>\n %fadd = fadd fast <2 x float> %shuf.x, %shuf.y\n %extshuf = shufflevector <2 x float> %fadd, <2 x float> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>\n ret <4 x float> %extshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "intrinsics_minmax", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_minmax(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %abt1 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> %abt, <4 x i8> %bt)\n %abb1 = call <4 x i8> @llvm.smax.v4i8(<4 x i8> %abb, <4 x i8> %bb)\n %abt2 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %abt1, <4 x i8> %bt)\n %abb2 = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %abb1, <4 x i8> %bb)\n %abt3 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> %abt2, <4 x i8> %bt)\n %abb3 = call <4 x i8> @llvm.umax.v4i8(<4 x i8> %abb2, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smax.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umax.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "constantdiff2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantdiff2(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, <i8 1, i8 2, i8 3, i8 4>\n %abb = add <4 x i8> %ab, <i8 1, i8 2, i8 3, i8 4>\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "fcmpsel", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @fcmpsel(<8 x half> %a, <8 x half> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt1 = fcmp olt <4 x half> %at, %bt\n %abb1 = fcmp olt <4 x half> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "inner_shuffle", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @inner_shuffle(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %cs = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> zeroinitializer\n %abt = mul <4 x i8> %at, %bt\n %abb = mul <4 x i8> %ab, %bb\n %abt2 = shufflevector <4 x i8> %abt, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %abb2 = shufflevector <4 x i8> %abb, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %abt3 = add <4 x i8> %abt2, %cs\n %abb3 = add <4 x i8> %abb2, %cs\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "zext_types", "test_body": "target triple = \"aarch64\"\n\ndefine void @zext_types(<8 x i16> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = zext <4 x i16> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %r = shufflevector <4 x i64> %ab1, <4 x i64> %at1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i64> %r, ptr %p, align 64\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "add_different_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @add_different_operands(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "constantdiff", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantdiff(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, <i8 1, i8 2, i8 3, i8 4>\n %abb = add <4 x i8> %ab, <i8 5, i8 6, i8 7, i8 8>\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "extrause_add_different_operands", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @extrause_add_different_operands(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n call void @use(<4 x i8> %abb)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\ndeclare void @use(<4 x i8>)\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmpsel_diffentcond", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @icmpsel_diffentcond(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt1 = icmp slt <4 x i8> %at, %bt\n %abb1 = icmp ult <4 x i8> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "exttrunc", "test_body": "target triple = \"aarch64\"\n\ndefine void @exttrunc(<8 x i32> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %bb = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %bt = shufflevector <8 x i32> %b, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = zext <4 x i32> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %bb1 = sext <4 x i32> %bb to <4 x i64>\n %bt1 = sext <4 x i32> %bt to <4 x i64>\n %abb = add <4 x i64> %ab1, %bb1\n %abt = add <4 x i64> %at1, %bt1\n %abb1 = trunc <4 x i64> %abb to <4 x i32>\n %abt1 = trunc <4 x i64> %abt to <4 x i32>\n %r = shufflevector <4 x i32> %abb1, <4 x i32> %abt1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null }, { "test_name": "fadd", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fadd(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = fadd <4 x half> %at, %bt\n %abb = fadd <4 x half> %ab, %bb\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null }, { "test_name": "wrong_addsub", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @wrong_addsub(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = sub <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "single_zext", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @single_zext(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i32> %shuf to <4 x i64>\n %revshuf = shufflevector <4 x i64> %zext, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "v8f64interleave", "test_body": "target triple = \"aarch64\"\n\ndefine void @v8f64interleave(i64 %0, ptr %1, ptr %x, double %z) {\nentry:\n %broadcast.splatinsert = insertelement <2 x double> poison, double %z, i64 0\n %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer\n %wide.vec = load <16 x double>, ptr %1, align 8\n %strided.vec = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 0, i32 8>\n %strided.vec27 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 1, i32 9>\n %strided.vec28 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 2, i32 10>\n %strided.vec29 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 3, i32 11>\n %strided.vec30 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 4, i32 12>\n %strided.vec31 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 5, i32 13>\n %strided.vec32 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 6, i32 14>\n %strided.vec33 = shufflevector <16 x double> %wide.vec, <16 x double> poison, <2 x i32> <i32 7, i32 15>\n %2 = fmul fast <2 x double> %strided.vec, %broadcast.splat\n %3 = getelementptr inbounds double, ptr %x, i64 %0\n %wide.vec34 = load <16 x double>, ptr %3, align 8\n %strided.vec35 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 0, i32 8>\n %strided.vec36 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 1, i32 9>\n %strided.vec37 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 2, i32 10>\n %strided.vec38 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 3, i32 11>\n %strided.vec39 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 4, i32 12>\n %strided.vec40 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 5, i32 13>\n %strided.vec41 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 6, i32 14>\n %strided.vec42 = shufflevector <16 x double> %wide.vec34, <16 x double> poison, <2 x i32> <i32 7, i32 15>\n %4 = fadd fast <2 x double> %strided.vec35, %2\n %5 = fmul fast <2 x double> %strided.vec27, %broadcast.splat\n %6 = fadd fast <2 x double> %strided.vec36, %5\n %7 = fmul fast <2 x double> %strided.vec28, %broadcast.splat\n %8 = fadd fast <2 x double> %strided.vec37, %7\n %9 = fmul fast <2 x double> %strided.vec29, %broadcast.splat\n %10 = fadd fast <2 x double> %strided.vec38, %9\n %11 = fmul fast <2 x double> %strided.vec30, %broadcast.splat\n %12 = fadd fast <2 x double> %strided.vec39, %11\n %13 = fmul fast <2 x double> %strided.vec31, %broadcast.splat\n %14 = fadd fast <2 x double> %strided.vec40, %13\n %15 = fmul fast <2 x double> %strided.vec32, %broadcast.splat\n %16 = fadd fast <2 x double> %strided.vec41, %15\n %17 = or disjoint i64 %0, 7\n %18 = fmul fast <2 x double> %strided.vec33, %broadcast.splat\n %19 = getelementptr inbounds double, ptr %x, i64 %17\n %20 = fadd fast <2 x double> %strided.vec42, %18\n %21 = getelementptr inbounds i8, ptr %19, i64 -56\n %22 = shufflevector <2 x double> %4, <2 x double> %6, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %23 = shufflevector <2 x double> %8, <2 x double> %10, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %24 = shufflevector <2 x double> %12, <2 x double> %14, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %25 = shufflevector <2 x double> %16, <2 x double> %20, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %26 = shufflevector <4 x double> %22, <4 x double> %23, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %27 = shufflevector <4 x double> %24, <4 x double> %25, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %interleaved.vec = shufflevector <8 x double> %26, <8 x double> %27, <16 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14, i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>\n store <16 x double> %interleaved.vec, ptr %21, align 8\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "singleop", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i8> @singleop(<4 x i8> %a, <4 x i8> %b) {\n %a1 = shufflevector <4 x i8> %a, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %b1 = shufflevector <4 x i8> %b, <4 x i8> poison, <4 x i32> zeroinitializer\n %a2 = zext <4 x i8> %a1 to <4 x i16>\n %b2 = zext <4 x i8> %b1 to <4 x i16>\n %ab = add <4 x i16> %a2, %b2\n %t = trunc <4 x i16> %ab to <4 x i8>\n %r = shufflevector <4 x i8> %t, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_bitcast", "test_body": "target triple = \"aarch64\"\n\ndefine i32 @not_bitcast(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bitcast = bitcast <4 x i8> %shuf to i32\n ret i32 %bitcast\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "zext_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @zext_chain(<4 x i16> %x) {\n %shuf = shufflevector <4 x i16> %x, <4 x i16> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i16> %shuf to <4 x i32>\n %sext = sext <4 x i32> %zext to <4 x i64>\n %revshuf = shufflevector <4 x i64> %sext, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "intrinsics_different", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_different(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.smin.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.umin.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.smin.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.umin.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "operandbundles_second", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @operandbundles_second(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cast_mismatched_types", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @cast_mismatched_types(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <2 x i32> <i32 0, i32 2>\n %zext = zext <2 x i32> %shuf to <2 x i64>\n %extshuf = shufflevector <2 x i64> %zext, <2 x i64> poison, <4 x i32> <i32 0, i32 2, i32 1, i32 3>\n ret <4 x i64> %extshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "operandbundles_first", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @operandbundles_first(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "wrong_lanes", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @wrong_lanes(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 6, i32 7, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "first_scalar_select", "test_body": "target triple = \"aarch64\"\n\ndefine <2 x float> @first_scalar_select(<2 x float> %0, <2 x float> %1, float %x) {\nentry:\n %cmp.i903 = fcmp ogt float %x, 0.000000e+00\n %sel1639 = select i1 %cmp.i903, <2 x float> %0, <2 x float> %1\n %2 = fcmp ogt <2 x float> %0, zeroinitializer\n %sel48.i913 = select <2 x i1> %2, <2 x float> %0, <2 x float> %1\n %3 = shufflevector <2 x float> %sel1639, <2 x float> %sel48.i913, <2 x i32> <i32 0, i32 3>\n ret <2 x float> %3\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "splat0", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splat0(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> zeroinitializer\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "splatandidentity", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splatandidentity(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bs = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> zeroinitializer\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "trivial", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @trivial(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %r = shufflevector <4 x i8> %at, <4 x i8> %ab, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "constantsplat", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @constantsplat(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, splat (i8 10)\n %abb = add <4 x i8> %ab, splat (i8 10)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "bitcast_srcty_mismatch", "test_body": "target triple = \"aarch64\"\n\ndefine void @bitcast_srcty_mismatch() {\nentry:\n %shuffle.i.i = shufflevector <2 x i64> zeroinitializer, <2 x i64> zeroinitializer, <2 x i32> <i32 1, i32 3>\n %0 = bitcast <4 x i32> zeroinitializer to <4 x float>\n %1 = bitcast <2 x i64> %shuffle.i.i to <4 x float>\n %shufp.i196 = shufflevector <4 x float> %0, <4 x float> %1, <4 x i32> <i32 2, i32 1, i32 4, i32 7>\n store <4 x float> %shufp.i196, ptr null, align 16\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "zext_add_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @zext_add_chain(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i32> %shuf to <4 x i64>\n %add = add <4 x i64> %zext, %zext\n %revshuf = shufflevector <4 x i64> %add, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "add_chain", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i32> @add_chain(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %add = add <4 x i32> %shuf, %shuf\n %add2 = add <4 x i32> %add, %add\n %revshuf = shufflevector <4 x i32> %add2, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i32> %revshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "splat2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @splat2(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bs = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 2, i32 2, i32 2, i32 2>\n %abt = fadd <4 x half> %at, %bs\n %abb = fadd <4 x half> %ab, %bs\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "trunc", "test_body": "target triple = \"aarch64\"\n\ndefine void @trunc(<8 x i64> %a, <8 x i64> %b, ptr %p) {\n %ab = shufflevector <8 x i64> %a, <8 x i64> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i64> %a, <8 x i64> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %abb1 = trunc <4 x i64> %ab to <4 x i32>\n %abt1 = trunc <4 x i64> %at to <4 x i32>\n %r = shufflevector <4 x i32> %abb1, <4 x i32> %abt1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sext", "test_body": "target triple = \"aarch64\"\n\ndefine void @sext(<8 x i16> %a, <8 x i16> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %bb = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %bt = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = sext <4 x i16> %ab to <4 x i32>\n %at1 = sext <4 x i16> %at to <4 x i32>\n %bb1 = sext <4 x i16> %bb to <4 x i32>\n %bt1 = sext <4 x i16> %bt to <4 x i32>\n %abb = add <4 x i32> %ab1, %bb1\n %abt = add <4 x i32> %at1, %bt1\n %r = shufflevector <4 x i32> %abb, <4 x i32> %abt, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null }, { "test_name": "callinst", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @othercall(<4 x half> %at)\n %abb = call <4 x half> @llvm.fabs.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "fma", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fma(<8 x half> %a, <8 x half> %b, <8 x half> %c) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x half> %b, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x half> %c, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x half> %c, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abb = call <4 x half> @llvm.fma.v4f16(<4 x half> %ab, <4 x half> %bb, <4 x half> %cb)\n %abt = call <4 x half> @llvm.fma.v4f16(<4 x half> %at, <4 x half> %bt, <4 x half> %ct)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fma.v4f16(<4 x half>, <4 x half>, <4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "extrause_shuffle", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @extrause_shuffle(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n call void @use(<4 x i8> %bt)\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\ndeclare void @use(<4 x i8>)\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "intrinsics_addsat", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @intrinsics_addsat(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> %at, <4 x i8> %bt)\n %abb = call <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8> %ab, <4 x i8> %bb)\n %abt1 = call <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8> %abt, <4 x i8> %bt)\n %abb1 = call <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8> %abb, <4 x i8> %bb)\n %abt2 = call <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8> %abt1, <4 x i8> %bt)\n %abb2 = call <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8> %abb1, <4 x i8> %bb)\n %abt3 = call <4 x i8> @llvm.usub.sat.v4i8(<4 x i8> %abt2, <4 x i8> %bt)\n %abb3 = call <4 x i8> @llvm.usub.sat.v4i8(<4 x i8> %abb2, <4 x i8> %bb)\n %r = shufflevector <4 x i8> %abt3, <4 x i8> %abb3, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.sadd.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.ssub.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.uadd.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.usub.sat.v4i8(<4 x i8>, <4 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "zext", "test_body": "target triple = \"aarch64\"\n\ndefine void @zext(<8 x i16> %a, <8 x i16> %b, ptr %p) {\n %ab = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i16> %a, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %bb = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %bt = shufflevector <8 x i16> %b, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = zext <4 x i16> %ab to <4 x i32>\n %at1 = zext <4 x i16> %at to <4 x i32>\n %bb1 = zext <4 x i16> %bb to <4 x i32>\n %bt1 = zext <4 x i16> %bt to <4 x i32>\n %abb = add <4 x i32> %ab1, %bb1\n %abt = add <4 x i32> %at1, %bt1\n %r = shufflevector <4 x i32> %abb, <4 x i32> %abt, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i32> %r, ptr %p, align 32\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "div", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @div(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = udiv <4 x i8> %at, %bt\n %abb = udiv <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 poison, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "bitcast_smax_v8i32_v4i32", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @bitcast_smax_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b) {\n %a.bc0 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc0 = bitcast <4 x i64> %b to <8 x i32>\n %cmp = icmp slt <8 x i32> %a.bc0, %b.bc0\n %cmp.lo = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %cmp.hi = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %a.bc1 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc1 = bitcast <4 x i64> %b to <8 x i32>\n %a.lo = shufflevector <8 x i32> %a.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %b.lo = shufflevector <8 x i32> %b.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %lo = select <4 x i1> %cmp.lo, <4 x i32> %b.lo, <4 x i32> %a.lo\n %a.bc2 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc2 = bitcast <4 x i64> %b to <8 x i32>\n %a.hi = shufflevector <8 x i32> %a.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %b.hi = shufflevector <8 x i32> %b.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %hi = select <4 x i1> %cmp.hi, <4 x i32> %b.hi, <4 x i32> %a.hi\n %concat = shufflevector <4 x i32> %lo, <4 x i32> %hi, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %res = bitcast <8 x i32> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_bitcast2", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i16> @not_bitcast2(<4 x i32> %x, <8 x i16> %y) {\n %cast = bitcast <4 x i32> %x to <8 x i16>\n %out = shufflevector <8 x i16> %y, <8 x i16> %cast, <8 x i32> <i32 8, i32 1, i32 10, i32 3, i32 12, i32 5, i32 14, i32 7>\n ret <8 x i16> %out\n}\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null }, { "test_name": "maximal_legal_fpmath", "test_body": "target triple = \"aarch64\"\n\ndefine void @maximal_legal_fpmath(ptr %addr1, ptr %addr2, ptr %result, float %val) {\n %splatinsert = insertelement <4 x float> poison, float %val, i64 0\n %incoming.vec = shufflevector <4 x float> %splatinsert, <4 x float> poison, <4 x i32> zeroinitializer\n %vec1 = load <16 x float>, ptr %addr1, align 4\n %strided.vec1 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>\n %strided.vec2 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 1, i32 5, i32 9, i32 13>\n %strided.vec3 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 2, i32 6, i32 10, i32 14>\n %strided.vec4 = shufflevector <16 x float> %vec1, <16 x float> poison, <4 x i32> <i32 3, i32 7, i32 11, i32 15>\n %vec2 = load <16 x float>, ptr %addr2, align 4\n %strided.vec6 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 0, i32 4, i32 8, i32 12>\n %strided.vec7 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 1, i32 5, i32 9, i32 13>\n %strided.vec8 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 2, i32 6, i32 10, i32 14>\n %strided.vec9 = shufflevector <16 x float> %vec2, <16 x float> poison, <4 x i32> <i32 3, i32 7, i32 11, i32 15>\n %1 = fmul fast <4 x float> %incoming.vec, %strided.vec6\n %2 = fadd fast <4 x float> %strided.vec1, %1\n %3 = fmul contract <4 x float> %incoming.vec, %strided.vec7\n %4 = fadd fast <4 x float> %strided.vec2, %3\n %5 = fmul reassoc contract <4 x float> %incoming.vec, %strided.vec8\n %6 = fadd fast <4 x float> %strided.vec3, %5\n %7 = fmul reassoc contract <4 x float> %incoming.vec, %strided.vec9\n %8 = fadd reassoc contract <4 x float> %strided.vec4, %7\n %9 = shufflevector <4 x float> %2, <4 x float> %4, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %10 = shufflevector <4 x float> %6, <4 x float> %8, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %interleaved.vec = shufflevector <8 x float> %9, <8 x float> %10, <16 x i32> <i32 0, i32 4, i32 8, i32 12, i32 1, i32 5, i32 9, i32 13, i32 2, i32 6, i32 10, i32 14, i32 3, i32 7, i32 11, i32 15>\n store <16 x float> %interleaved.vec, ptr %result, align 4\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_zext", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @not_zext(<4 x i32> %x) {\n %zext = zext <4 x i32> %x to <4 x i64>\n %revshuf = shufflevector <4 x i64> %zext, <4 x i64> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n ret <4 x i64> %revshuf\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "undeflane", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @undeflane(<8 x i8> %a, <8 x i8> %b) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = add <4 x i8> %at, %bt\n %abb = add <4 x i8> %ab, %bb\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 poison, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "operandbundles", "test_body": "target triple = \"aarch64\"\n\ndefine <16 x i64> @operandbundles(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) {\n %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>\n %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n ret <16 x i64> %shufflevector1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "fneg", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @fneg(<8 x half> %a, <8 x half> %b) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = fneg <4 x half> %at\n %abb = fneg <4 x half> %ab\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmpsel", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @icmpsel(<8 x i8> %a, <8 x i8> %b, <8 x i8> %c, <8 x i8> %d) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %bb = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %bt = shufflevector <8 x i8> %b, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %cb = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %ct = shufflevector <8 x i8> %c, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %db = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %dt = shufflevector <8 x i8> %d, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt1 = icmp slt <4 x i8> %at, %bt\n %abb1 = icmp slt <4 x i8> %ab, %bb\n %abt = select <4 x i1> %abt1, <4 x i8> %ct, <4 x i8> %dt\n %abb = select <4 x i1> %abb1, <4 x i8> %cb, <4 x i8> %db\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "szext", "test_body": "target triple = \"aarch64\"\n\ndefine void @szext(<8 x i32> %a, <8 x i32> %b, ptr %p) {\n %ab = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>\n %at = shufflevector <8 x i32> %a, <8 x i32> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>\n %ab1 = sext <4 x i32> %ab to <4 x i64>\n %at1 = zext <4 x i32> %at to <4 x i64>\n %r = shufflevector <4 x i64> %ab1, <4 x i64> %at1, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 3, i32 7>\n store <8 x i64> %r, ptr %p, align 64\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "constantsplatf", "test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @constantsplatf(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = fadd <4 x half> %at, splat (half 0xH4900)\n %abb = fadd <4 x half> %ab, splat (half 0xH4900)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_zext2", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @not_zext2(<4 x i32> %x) {\n %shuf = shufflevector <4 x i32> %x, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %zext = zext <4 x i32> %shuf to <4 x i64>\n ret <4 x i64> %zext\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion Failure in Vector Combine", "body": "Runnning vector-combine pass on \r\n```llvm\r\nsource_filename = \"text\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:10:11:12:13\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine nonnull ptr addrspace(10) @wombat() {\r\n %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> zeroinitializer, <4 x i64> zeroinitializer, <4 x i64> <i64 45, i64 45, i64 45, i64 45>) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\r\n %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>\r\n %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\r\n ret ptr addrspace(10) null\r\n}\r\n\r\ndeclare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)\r\n```\r\nproduces\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::Type]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=vector-combine <source>\r\n1.\tRunning pass \"function(vector-combine)\" on module \"<source>\"\r\n2.\tRunning pass \"vector-combine\" on function \"wombat\"\r\n #0 0x0000000005079b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5079b38)\r\n #1 0x00000000050774ec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074d0dce42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074d0dce969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074d0dce42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074d0dce287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000074d0dce2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000074d0dce39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004186458 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\r\n #9 0x0000000004190f01 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\r\n#10 0x0000000004191c25 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4191c25)\r\n#11 0x0000000002f2defe llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f2defe)\r\n#12 0x0000000004e7c978 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7c978)\r\n#13 0x0000000000e157ce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe157ce)\r\n#14 0x0000000004e7b39e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7b39e)\r\n#15 0x0000000000e14f7e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe14f7e)\r\n#16 0x0000000004e7add0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7add0)\r\n#17 0x0000000000904cc2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x904cc2)\r\n#18 0x00000000008f7b4c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f7b4c)\r\n#19 0x000074d0dce29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x000074d0dce29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008ef61e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ef61e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nGodbolt: https://godbolt.org/z/MGefYs3M5", "author": "Zentrik", "labels": [ "release:backport", "vectorizers", "crash" ], "comments": [ { "author": "Heresh83", "body": "> Runnning vector-combine pass on \n> ```llvm\n> source_filename = \"text\"\n> target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:10:11:12:13\"\n> target triple = \"x86_64-unknown-linux-gnu\"\n> \n> define nonnull ptr addrspace(10) @wombat() {\n> %call = call <4 x i64> @llvm.fshl.v4i64(<4 x i64> zeroinitializer, <4 x i64> zeroinitializer, <4 x i64> <i64 45, i64 45, i64 45, i64 45>) [ \"jl_roots\"(ptr addrspace(10) null, ptr addrspace(10) null) ]\n> %shufflevector = shufflevector <4 x i64> %call, <4 x i64> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>\n> %shufflevector1 = shufflevector <16 x i64> %shufflevector, <16 x i64> undef, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n> ret ptr addrspace(10) null\n> }\n> \n> declare <4 x i64> @llvm.fshl.v4i64(<4 x i64>, <4 x i64>, <4 x i64>)\n> ```\n> produces\n> ```\n> opt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::FixedVectorType; From = llvm::Type]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\n> PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\n> Stack dump:\n> 0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=vector-combine <source>\n> 1.\tRunning pass \"function(vector-combine)\" on module \"<source>\"\n> 2.\tRunning pass \"vector-combine\" on function \"wombat\"\n> #0 0x0000000005079b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5079b38)\n> #1 0x00000000050774ec SignalHandler(int) Signals.cpp:0:0\n> #2 0x000074d0dce42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n> #3 0x000074d0dce969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n> #4 0x000074d0dce42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n> #5 0x000074d0dce287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n> #6 0x000074d0dce2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n> #7 0x000074d0dce39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n> #8 0x0000000004186458 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\n> #9 0x0000000004190f01 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\n> #10 0x0000000004191c25 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4191c25)\n> #11 0x0000000002f2defe llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f2defe)\n> #12 0x0000000004e7c978 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7c978)\n> #13 0x0000000000e157ce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe157ce)\n> #14 0x0000000004e7b39e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7b39e)\n> #15 0x0000000000e14f7e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe14f7e)\n> #16 0x0000000004e7add0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7add0)\n> #17 0x0000000000904cc2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x904cc2)\n> #18 0x00000000008f7b4c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f7b4c)\n> #19 0x000074d0dce29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n> #20 0x000074d0dce29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n> #21 0x00000000008ef61e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ef61e)\n> Program terminated with signal: SIGSEGV\n> Compiler returned: 139\n> ```\n> Godbolt: https://godbolt.org/z/MGefYs3M5\n\n" }, { "author": "RKSimon", "body": "Looks like foldShuffleToIdentity is attempting to fold the operand bundle on the fshl call" } ] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [ [ 2341, 2351 ], [ 2361, 2372 ], [ 2375, 2380 ] ], "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [ "InstCombiner::getFreelyInvertedImpl" ], "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
106523
https://github.com/llvm/llvm-project/issues/106523
crash
2002533802dbe74c82476e30d093baf6d4cdee50
2024-08-29T10:12:29
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2dfb1c664c0a0afc512b900c45989e247406e523", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ [ 772, 777 ], [ 795, 801 ] ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": [ [ 36, 46 ] ], "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::adjustFixedOrderRecurrences", "sinkRecurrenceUsersAfterPrevious" ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 2dfb1c664c0a0afc512b900c45989e247406e523 Author: Florian Hahn <[email protected]> Date: Wed Oct 23 13:12:03 2024 -0700 [VPlan] Try to hoist Previous (and operands), if sinking fails for FORs. (#108945) In some cases, Previous (and its operands) can be hoisted. This allows supporting additional cases where sinking of all users of to FOR fails, e.g. due having to sink recipes with side-effects. This fixes a crash where we fail to create a scalar VPlan for a first-order recurrence, but can create a vector VPlan, because the trunc instruction of an IV which generates the previous value of the recurrence has been optimized to a truncated induction recipe, thus hoisting it to the beginning. Fixes https://github.com/llvm/llvm-project/issues/106523. PR: https://github.com/llvm/llvm-project/pull/108945 diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index d50f3c0c3f3e..c6e09c4f2e6e 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -772,6 +772,105 @@ sinkRecurrenceUsersAfterPrevious(VPFirstOrderRecurrencePHIRecipe *FOR, return true; } +/// Try to hoist \p Previous and its operands before all users of \p FOR. +static bool hoistPreviousBeforeFORUsers(VPFirstOrderRecurrencePHIRecipe *FOR, + VPRecipeBase *Previous, + VPDominatorTree &VPDT) { + if (Previous->mayHaveSideEffects() || Previous->mayReadFromMemory()) + return false; + + // Collect recipes that need hoisting. + SmallVector<VPRecipeBase *> HoistCandidates; + SmallPtrSet<VPRecipeBase *, 8> Visited; + VPRecipeBase *HoistPoint = nullptr; + // Find the closest hoist point by looking at all users of FOR and selecting + // the recipe dominating all other users. + for (VPUser *U : FOR->users()) { + auto *R = dyn_cast<VPRecipeBase>(U); + if (!R) + continue; + if (!HoistPoint || VPDT.properlyDominates(R, HoistPoint)) + HoistPoint = R; + } + assert(all_of(FOR->users(), + [&VPDT, HoistPoint](VPUser *U) { + auto *R = dyn_cast<VPRecipeBase>(U); + return !R || HoistPoint == R || + VPDT.properlyDominates(HoistPoint, R); + }) && + "HoistPoint must dominate all users of FOR"); + + auto NeedsHoisting = [HoistPoint, &VPDT, + &Visited](VPValue *HoistCandidateV) -> VPRecipeBase * { + VPRecipeBase *HoistCandidate = HoistCandidateV->getDefiningRecipe(); + if (!HoistCandidate) + return nullptr; + VPRegionBlock *EnclosingLoopRegion = + HoistCandidate->getParent()->getEnclosingLoopRegion(); + assert((!HoistCandidate->getParent()->getParent() || + HoistCandidate->getParent()->getParent() == EnclosingLoopRegion) && + "CFG in VPlan should still be flat, without replicate regions"); + // Hoist candidate was already visited, no need to hoist. + if (!Visited.insert(HoistCandidate).second) + return nullptr; + + // Candidate is outside loop region or a header phi, dominates FOR users w/o + // hoisting. + if (!EnclosingLoopRegion || isa<VPHeaderPHIRecipe>(HoistCandidate)) + return nullptr; + + // If we reached a recipe that dominates HoistPoint, we don't need to + // hoist the recipe. + if (VPDT.properlyDominates(HoistCandidate, HoistPoint)) + return nullptr; + return HoistCandidate; + }; + auto CanHoist = [&](VPRecipeBase *HoistCandidate) { + // Avoid hoisting candidates with side-effects, as we do not yet analyze + // associated dependencies. + return !HoistCandidate->mayHaveSideEffects(); + }; + + if (!NeedsHoisting(Previous->getVPSingleValue())) + return true; + + // Recursively try to hoist Previous and its operands before all users of FOR. + HoistCandidates.push_back(Previous); + + for (unsigned I = 0; I != HoistCandidates.size(); ++I) { + VPRecipeBase *Current = HoistCandidates[I]; + assert(Current->getNumDefinedValues() == 1 && + "only recipes with a single defined value expected"); + if (!CanHoist(Current)) + return false; + + for (VPValue *Op : Current->operands()) { + // If we reach FOR, it means the original Previous depends on some other + // recurrence that in turn depends on FOR. If that is the case, we would + // also need to hoist recipes involving the other FOR, which may break + // dependencies. + if (Op == FOR) + return false; + + if (auto *R = NeedsHoisting(Op)) + HoistCandidates.push_back(R); + } + } + + // Order recipes to hoist by dominance so earlier instructions are processed + // first. + sort(HoistCandidates, [&VPDT](const VPRecipeBase *A, const VPRecipeBase *B) { + return VPDT.properlyDominates(A, B); + }); + + for (VPRecipeBase *HoistCandidate : HoistCandidates) { + HoistCandidate->moveBefore(*HoistPoint->getParent(), + HoistPoint->getIterator()); + } + + return true; +} + bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan, VPBuilder &LoopBuilder) { VPDominatorTree VPDT; @@ -795,7 +894,8 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan, Previous = PrevPhi->getBackedgeValue()->getDefiningRecipe(); } - if (!sinkRecurrenceUsersAfterPrevious(FOR, Previous, VPDT)) + if (!sinkRecurrenceUsersAfterPrevious(FOR, Previous, VPDT) && + !hoistPreviousBeforeFORUsers(FOR, Previous, VPDT)) return false; // Introduce a recipe to combine the incoming and previous values of a diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h index 60a44bfb0dca..11e094db6294 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h @@ -36,11 +36,11 @@ struct VPlanTransforms { GetIntOrFpInductionDescriptor, ScalarEvolution &SE, const TargetLibraryInfo &TLI); - /// Sink users of fixed-order recurrences after the recipe defining their - /// previous value. Then introduce FirstOrderRecurrenceSplice VPInstructions - /// to combine the value from the recurrence phis and previous values. The - /// current implementation assumes all users can be sunk after the previous - /// value, which is enforced by earlier legality checks. + /// Try to have all users of fixed-order recurrences appear after the recipe + /// defining their previous value, by either sinking users or hoisting recipes + /// defining their previous value (and its operands). Then introduce + /// FirstOrderRecurrenceSplice VPInstructions to combine the value from the + /// recurrence phis and previous values. /// \returns true if all users of fixed-order recurrences could be re-arranged /// as needed or false if it is not possible. In the latter case, \p Plan is /// not valid.
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/fixed-order-recurrence.ll", "commands": [ "opt -passes=loop-vectorize -S -o - %s" ], "tests": [ { "test_name": "test_pr62954_scalar_epilogue_required", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc_linux\"\n\ndefine i64 @test_pr62954_scalar_epilogue_required(ptr %A, ptr noalias %B, ptr %C) {\nentry:\n %gep = getelementptr i8, ptr %A, i64 872\n %rec.start = load i64, ptr %gep, align 8\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]\n %for = phi i64 [ %rec.start, %entry ], [ %neg.iv, %loop ]\n %gep.B = getelementptr double, ptr %B, i64 %iv\n %l.B = load double, ptr %gep.B, align 8\n %neg.iv = sub nsw i64 0, %iv\n store i64 %neg.iv, ptr %gep, align 8\n %iv.next = add nuw nsw i64 %iv, 2\n %ec = icmp ugt i64 %iv, 74\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %.in.lcssa = phi i64 [ %for, %loop ]\n %.lcssa = phi double [ %l.B, %loop ]\n store double %.lcssa, ptr %C, align 8\n ret i64 %.in.lcssa\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "thirdorderrec", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc_linux\"\n\ndefine void @thirdorderrec(ptr nocapture noundef readonly %x, ptr noalias nocapture noundef writeonly %y, i32 noundef %n) {\nentry:\n %cmp38 = icmp sgt i32 %n, 3\n br i1 %cmp38, label %for.body.preheader, label %for.cond.cleanup\n\nfor.body.preheader: ; preds = %entry\n %wide.trip.count = zext i32 %n to i64\n %.pre = load i8, ptr %x, align 1\n %arrayidx5.phi.trans.insert = getelementptr inbounds i8, ptr %x, i64 1\n %.pre44 = load i8, ptr %arrayidx5.phi.trans.insert, align 1\n %arrayidx12.phi.trans.insert = getelementptr inbounds i8, ptr %x, i64 2\n %.pre45 = load i8, ptr %arrayidx12.phi.trans.insert, align 1\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 %0 = phi i8 [ %.pre45, %for.body.preheader ], [ %3, %for.body ]\n %1 = phi i8 [ %.pre44, %for.body.preheader ], [ %0, %for.body ]\n %2 = phi i8 [ %.pre, %for.body.preheader ], [ %1, %for.body ]\n %indvars.iv = phi i64 [ 3, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %add8 = add i8 %1, %2\n %add15 = add i8 %add8, %0\n %arrayidx18 = getelementptr inbounds i8, ptr %x, i64 %indvars.iv\n %3 = load i8, ptr %arrayidx18, align 1\n %add21 = add i8 %add15, %3\n %arrayidx24 = getelementptr inbounds i8, ptr %y, i64 %indvars.iv\n store i8 %add21, ptr %arrayidx24, align 1\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count\n br i1 %exitcond.not, label %for.cond.cleanup, label %for.body\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "for_iv_trunc_optimized", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc_linux\"\n\ndefine void @for_iv_trunc_optimized(ptr %dst) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %iv = phi i64 [ 1, %bb ], [ %add, %loop ]\n %for.1 = phi i32 [ 1, %bb ], [ %trunc, %loop ]\n %for.2 = phi i32 [ 0, %bb ], [ %or, %loop ]\n %or = or i32 %for.1, 3\n %add = add i64 %iv, 1\n store i32 %for.2, ptr %dst, align 4\n %icmp = icmp ult i64 %iv, 337\n %trunc = trunc i64 %iv to i32\n br i1 %icmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "firstorderrec", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc_linux\"\n\ndefine void @firstorderrec(ptr nocapture noundef readonly %x, ptr noalias nocapture noundef writeonly %y, i32 noundef %n) {\nentry:\n %cmp18 = icmp sgt i32 %n, 1\n br i1 %cmp18, label %for.body.preheader, label %for.cond.cleanup\n\nfor.body.preheader: ; preds = %entry\n %wide.trip.count = zext i32 %n to i64\n %.pre = load i8, ptr %x, align 1\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 %0 = phi i8 [ %.pre, %for.body.preheader ], [ %1, %for.body ]\n %indvars.iv = phi i64 [ 1, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %arrayidx4 = getelementptr inbounds i8, ptr %x, i64 %indvars.iv\n %1 = load i8, ptr %arrayidx4, align 1\n %add7 = add i8 %1, %0\n %arrayidx10 = getelementptr inbounds i8, ptr %y, i64 %indvars.iv\n store i8 %add7, ptr %arrayidx10, align 1\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count\n br i1 %exitcond.not, label %for.cond.cleanup, label %for.body\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains-vplan.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -debug-only=loop-vectorize -disable-output -S %s 2>&1" ], "tests": [ { "test_name": "test_chained_first_order_recurrences_4", "test_body": "define i32 @test_chained_first_order_recurrences_4(ptr %base, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]\n %for.x = phi i64 [ %for.x.next, %loop ], [ 0, %entry ]\n %for.y = phi i32 [ %for.x.prev, %loop ], [ 0, %entry ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr i64, ptr %base, i64 %iv\n %for.x.prev = trunc i64 %for.x to i32\n %for.y.i64 = sext i32 %for.y to i64\n store i64 %for.y.i64, ptr %gep, align 4\n %for.x.next = mul i64 %x, 2\n %icmp = icmp ugt i64 %iv, 4096\n br i1 %icmp, label %ret, label %loop\n\nret: ; preds = %loop\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_chained_first_order_recurrences_3", "test_body": "define void @test_chained_first_order_recurrences_3(ptr %ptr) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %for.1 = phi i16 [ 22, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi i16 [ 33, %entry ], [ %for.1, %loop ]\n %for.3 = phi i16 [ 33, %entry ], [ %for.2, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add nuw nsw i64 %iv, 1\n %gep.ptr = getelementptr inbounds i16, ptr %ptr, i64 %iv\n %for.1.next = load i16, ptr %gep.ptr, align 2\n %add.1 = add i16 %for.1, %for.2\n %add.2 = add i16 %add.1, %for.3\n store i16 %add.2, ptr %gep.ptr, align 2\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_chained_first_order_recurrences_1", "test_body": "define void @test_chained_first_order_recurrences_1(ptr %ptr) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %for.1 = phi i16 [ 22, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi i16 [ 33, %entry ], [ %for.1, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add nuw nsw i64 %iv, 1\n %gep.ptr = getelementptr inbounds i16, ptr %ptr, i64 %iv\n %for.1.next = load i16, ptr %gep.ptr, align 2\n %add = add i16 %for.1, %for.2\n store i16 %add, ptr %gep.ptr, align 2\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_chained_first_order_recurrences_5_hoist_to_load", "test_body": "define i32 @test_chained_first_order_recurrences_5_hoist_to_load(ptr %base) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]\n %for.x = phi i64 [ %for.x.next, %loop ], [ 0, %entry ]\n %for.y = phi i32 [ %for.x.prev, %loop ], [ 0, %entry ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr i64, ptr %base, i64 %iv\n %l = load i64, ptr %gep, align 4\n %for.x.prev = trunc i64 %for.x to i32\n %for.y.i64 = sext i32 %for.y to i64\n store i64 %for.y.i64, ptr %gep, align 4\n %for.x.next = mul i64 %l, 2\n %icmp = icmp ugt i64 %iv, 4096\n br i1 %icmp, label %ret, label %loop\n\nret: ; preds = %loop\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-multiply-recurrences.ll", "commands": [], "tests": [ { "test_name": "test_pr54223_sink_after_insertion_order", "test_body": "define void @test_pr54223_sink_after_insertion_order(ptr noalias %a, ptr noalias %b, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for.1 = phi float [ 0.000000e+00, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %entry ], [ %for.2.next, %loop ]\n %neg = fneg float %for.2\n %muladd = call float @llvm.fmuladd.f32(float %for.1, float %neg, float 0.000000e+00)\n %dst.gep = getelementptr inbounds float, ptr %dst, i64 %iv\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %a, align 4\n %for.2.next = load float, ptr %b, align 4\n store float %muladd, ptr %dst.gep, align 4\n %exitcond.not = icmp eq i64 %iv.next, 10000\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 float @llvm.fmuladd.f32(float, float, float) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_pr54233_for_depend_on_each_other", "test_body": "define void @test_pr54233_for_depend_on_each_other(ptr noalias %a, ptr noalias %b) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for.1 = phi i32 [ 0, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi i32 [ 0, %entry ], [ %for.2.next, %loop ]\n %or = or i32 %for.2, 10\n %shl = shl i32 %for.2, %for.1\n %xor = xor i32 %shl, 255\n %and = and i32 %xor, %or\n %for.1.next = xor i32 12, %for.2\n %for.2.next = load i32, ptr %b, align 4\n %a.gep = getelementptr inbounds i32, ptr %a, i64 %iv\n store i32 %and, ptr %a.gep, align 4\n %iv.next = add nuw i64 %iv, 1\n %exitcond = icmp eq i64 %iv, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `hasPlanWithVF(ScalarVF) && \"More than a single plan/VF w/o any plan having scalar VF\"' failed.", "body": "To reproduce run the following test 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 = %bb1, %bb\r\n %phi = phi i64 [ %add, %bb1 ], [ 1, %bb ]\r\n %phi2 = phi i32 [ %trunc, %bb1 ], [ 1, %bb ]\r\n %phi3 = phi i32 [ %or, %bb1 ], [ 0, %bb ]\r\n %or = or i32 %phi2, 0\r\n %add = add i64 %phi, 1\r\n store i32 %phi3, ptr addrspace(1) null, align 4\r\n %icmp = icmp ult i64 %phi, 337\r\n %trunc = trunc i64 %phi to i32\r\n br i1 %icmp, label %bb1, label %bb4\r\n\r\nbb4: ; preds = %bb1\r\n ret void\r\n}\r\n```\r\n\r\nReproducer: https://godbolt.org/z/e14eWvxMb\r\n\r\nStack dump:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7304: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `hasPlanWithVF(ScalarVF) && \"More than a single plan/VF w/o any plan having scalar VF\"' 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\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 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 0x000073e073a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000073e073a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000073e073a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000073e073a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000073e073a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000073e073a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003fe5276 llvm::LoopVectorizationPlanner::computeBestVF() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe5276)\r\n #9 0x0000000004001214 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4001214)\r\n#10 0x0000000004003eb9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4003eb9)\r\n#11 0x0000000004004543 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4004543)\r\n#12 0x0000000002ec85ae 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+0x2ec85ae)\r\n#13 0x0000000004da08f8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4da08f8)\r\n#14 0x0000000000df11be 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+0xdf11be)\r\n#15 0x0000000004d9f2fe llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d9f2fe)\r\n#16 0x0000000000df0aae 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+0xdf0aae)\r\n#17 0x0000000004d9d490 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d9d490)\r\n#18 0x00000000008e8002 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+0x8e8002)\r\n#19 0x00000000008daedc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8daedc)\r\n#20 0x000073e073a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#21 0x000073e073a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#22 0x00000000008d296e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d296e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "fhahn", "body": "Very interesting issue thanks! Proposed fix https://github.com/llvm/llvm-project/issues/106523" } ] }
true
null
107016
https://github.com/llvm/llvm-project/issues/107016
crash
a586b5a49dbd3b6c658f9edbf0b4a9be0b108a14
2024-09-02T19:14:36
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "50a02e7c68f964c5d8338369746c849ed8d3bef4", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 965, 972 ] ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPWidenCallRecipe::computeCost" ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 50a02e7c68f964c5d8338369746c849ed8d3bef4 Author: Florian Hahn <[email protected]> Date: Mon Sep 2 20:47:36 2024 +0100 [VPlan] Pass intrinsic inst to TTI in VPWidenCallRecipe::computeCost. Follow-up to 9ccf825, adjust computeCost to also pass IntrinsicInst to TTI if available, as there are multiple places in TTI which use the IntrinsicInst. Fixes https://github.com/llvm/llvm-project/issues/107016. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index e782ac444d02..c91ea2d1663c 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -965,8 +965,10 @@ InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF, ParamTys.push_back( ToVectorTy(Ctx.Types.inferScalarType(getOperand(I)), VF)); - IntrinsicCostAttributes CostAttrs(VectorIntrinsicID, RetTy, Arguments, - ParamTys, FMF); + // TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst. + IntrinsicCostAttributes CostAttrs( + VectorIntrinsicID, RetTy, Arguments, ParamTys, FMF, + dyn_cast_or_null<IntrinsicInst>(getUnderlyingValue())); return Ctx.TTI.getIntrinsicInstrCost(CostAttrs, CostKind); }
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/call-costs.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] clang crash", "body": "Failure since https://github.com/llvm/llvm-project/pull/106047\r\n\r\n[repro.zip](https://github.com/user-attachments/files/16840758/repro.zip)\r\n\r\n```\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: /scratch3/packages/llvm/main-20240902/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -main-file-name PairCorrEstimator.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -menable-no-infs -menable-no-nans -fapprox-func -funsafe-math-optimizations -fno-signed-zeros -mreassociate -freciprocal-math -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -complex-range=basic -mconstructor-aliases -funwind-tables=2 -target-cpu skylake-avx512 -target-feature +prfchw -target-feature -cldemote -target-feature +avx -target-feature +aes -target-feature +sahf -target-feature +pclmul -target-feature -xop -target-feature +crc32 -target-feature +xsaves -target-feature -avx512fp16 -target-feature -usermsr -target-feature -sm4 -target-feature -egpr -target-feature +sse4.1 -target-feature -avx512ifma -target-feature +xsave -target-feature +sse4.2 -target-feature -tsxldtrk -target-feature -sm3 -target-feature -ptwrite -target-feature -widekl -target-feature +invpcid -target-feature +64bit -target-feature +xsavec -target-feature -avx10.1-512 -target-feature -avx512vpopcntdq -target-feature +cmov -target-feature -avx512vp2intersect -target-feature +avx512cd -target-feature +movbe -target-feature -avxvnniint8 -target-feature -ccmp -target-feature -amx-int8 -target-feature -kl -target-feature -avx10.1-256 -target-feature +evex512 -target-feature -avxvnni -target-feature +rtm -target-feature +adx -target-feature +avx2 -target-feature -hreset -target-feature -movdiri -target-feature -serialize -target-feature -sha512 -target-feature -vpclmulqdq -target-feature +avx512vl -target-feature -uintr -target-feature -cf -target-feature +clflushopt -target-feature -raoint -target-feature -cmpccxadd -target-feature +bmi -target-feature -amx-tile -target-feature +sse -target-feature -avx10.2-256 -target-feature -gfni -target-feature -avxvnniint16 -target-feature -amx-fp16 -target-feature -zu -target-feature -ndd -target-feature +xsaveopt -target-feature +rdrnd -target-feature +avx512f -target-feature -amx-bf16 -target-feature -avx512bf16 -target-feature -avx512vnni -target-feature -push2pop2 -target-feature +cx8 -target-feature +avx512bw -target-feature +sse3 -target-feature +pku -target-feature -nf -target-feature +fsgsbase -target-feature -clzero -target-feature -mwaitx -target-feature -lwp -target-feature +lzcnt -target-feature -sha -target-feature -movdir64b -target-feature -ppx -target-feature -wbnoinvd -target-feature -enqcmd -target-feature -avx10.2-512 -target-feature -avxneconvert -target-feature -tbm -target-feature -pconfig -target-feature -amx-complex -target-feature +ssse3 -target-feature +cx16 -target-feature +bmi2 -target-feature +fma -target-feature +popcnt -target-feature -avxifma -target-feature +f16c -target-feature -avx512bitalg -target-feature -rdpru -target-feature +clwb -target-feature +mmx -target-feature +sse2 -target-feature +rdseed -target-feature -avx512vbmi2 -target-feature -prefetchi -target-feature -rdpid -target-feature -fma4 -target-feature -avx512vbmi -target-feature -shstk -target-feature -vaes -target-feature -waitpkg -target-feature -sgx -target-feature +fxsr -target-feature +avx512dq -target-feature -sse4a -debugger-tuning=gdb -fdebug-compilation-dir=/scratch3/opt/qmcpack/build_clangPatched_real/src/QMCHamiltonians -fcoverage-compilation-dir=/scratch3/opt/qmcpack/build_clangPatched_real/src/QMCHamiltonians -sys-header-deps -D ADD_ -D H5_USE_110_API -D HAVE_CONFIG_H -D HAVE_EINSPLINE -D HAVE_LIBBOOST -D HAVE_LIBFFTW -D HAVE_MKL -D HAVE_MKL_VML -D MPICH_SKIP_MPICXX -D OMPI_SKIP_MPICXX -D OPENMP_NO_COMPLEX -D _MPICC_H -D restrict=__restrict__ -D NDEBUG -O3 -Wvla -Wall -Wno-unused-variable -Wno-overloaded-virtual -Wno-unused-private-field -Wno-unused-local-typedef -Wsuggest-override -Wno-unknown-pragmas -Wmisleading-indentation -std=c++17 -fdeprecated-macro -ferror-limit 19 -fopenmp -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -x c++ PairCorrEstimator-40412c.cpp\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-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;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-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;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"PairCorrEstimator-40412c.cpp\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"_ZN11qmcplusplus17PairCorrEstimator15set_norm_factorEv\"\r\n #0 0x00005590c1746c00 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x2cb6c00)\r\n #1 0x00005590c174400f llvm::sys::RunSignalHandlers() (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x2cb400f)\r\n #2 0x00005590c1744165 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fb046e53520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00005590bfa8725a llvm::BasicTTIImplBase<llvm::X86TTIImpl>::getIntrinsicInstrCost(llvm::IntrinsicCostAttributes const&, llvm::TargetTransformInfo::TargetCostKind) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0xff725a)\r\n #5 0x00005590c07fac92 llvm::TargetTransformInfo::getIntrinsicInstrCost(llvm::IntrinsicCostAttributes const&, llvm::TargetTransformInfo::TargetCostKind) const (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x1d6ac92)\r\n #6 0x00005590c31a87b9 llvm::VPWidenCallRecipe::computeCost(llvm::ElementCount, llvm::VPCostContext&) const (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x47187b9)\r\n #7 0x00005590c31ab682 llvm::VPRecipeBase::cost(llvm::ElementCount, llvm::VPCostContext&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x471b682)\r\n #8 0x00005590c31744af llvm::VPBasicBlock::cost(llvm::ElementCount, llvm::VPCostContext&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x46e44af)\r\n #9 0x00005590c317b4b5 llvm::VPRegionBlock::cost(llvm::ElementCount, llvm::VPCostContext&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x46eb4b5)\r\n#10 0x00005590c305cfb4 llvm::LoopVectorizationPlanner::cost(llvm::VPlan&, llvm::ElementCount) const (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x45ccfb4)\r\n#11 0x00005590c3064878 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x45d4878)\r\n#12 0x00005590c307c6fb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x45ec6fb)\r\n#13 0x00005590c307f711 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x45ef711)\r\n#14 0x00005590c307fd87 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x45efd87)\r\n#15 0x00005590c2bdf2e6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x414f2e6)\r\n#16 0x00005590c10e652f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x265652f)\r\n#17 0x00005590bfaa9996 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x1019996)\r\n#18 0x00005590c10e52ab llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x26552ab)\r\n#19 0x00005590bfaaa356 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x101a356)\r\n#20 0x00005590c10e32ed llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x26532ed)\r\n#21 0x00005590c19d36b6 (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#22 0x00005590c19d70e9 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*) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x2f470e9)\r\n#23 0x00005590c206a4b5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x35da4b5)\r\n#24 0x00005590c3cfd42c clang::ParseAST(clang::Sema&, bool, bool) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x526d42c)\r\n#25 0x00005590c2318d19 clang::FrontendAction::Execute() (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x3888d19)\r\n#26 0x00005590c22972b5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x38072b5)\r\n#27 0x00005590c23ef9d3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0x395f9d3)\r\n#28 0x00005590bfa2dc87 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0xf9dc87)\r\n#29 0x00005590bfa269ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#30 0x00005590bfa29be3 clang_main(int, char**, llvm::ToolContext const&) (/scratch3/packages/llvm/main-20240902/bin/clang-20+0xf99be3)\r\n#31 0x00005590bf955c4b main (/scratch3/packages/llvm/main-20240902/bin/clang-20+0xec5c4b)\r\n#32 0x00007fb046e3ad90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#33 0x00007fb046e3ae40 call_init ./csu/../csu/libc-start.c:128:20\r\n#34 0x00007fb046e3ae40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#35 0x00005590bfa26115 _start (/scratch3/packages/llvm/main-20240902/bin/clang-20+0xf96115)\r\nPairCorrEstimator-40412c.sh: line 4: 840679 Segmentation fault (core dumped) \"/scratch3/packages/llvm/main-20240902/bin/clang-20\" \"-cc1\" \"-triple\" \"x86_64-unknown-linux-gnu\" \"-emit-obj\" \"-disable-free\" \"-clear-ast-before-backend\" \"-main-file-name\" \"PairCorrEstimator.cpp\" \"-mrelocation-model\" \"pic\" \"-pic-level\" \"2\" \"-pic-is-pie\" \"-mframe-pointer=none\" \"-menable-no-infs\" \"-menable-no-nans\" \"-fapprox-func\" \"-funsafe-math-optimizations\" \"-fno-signed-zeros\" \"-mreassociate\" \"-freciprocal-math\" \"-ffp-contract=fast\" \"-fno-rounding-math\" \"-ffast-math\" \"-ffinite-math-only\" \"-complex-range=basic\" \"-mconstructor-aliases\" \"-funwind-tables=2\" \"-target-cpu\" \"skylake-avx512\" \"-target-feature\" \"+prfchw\" \"-target-feature\" \"-cldemote\" \"-target-feature\" \"+avx\" \"-target-feature\" \"+aes\" \"-target-feature\" \"+sahf\" \"-target-feature\" \"+pclmul\" \"-target-feature\" \"-xop\" \"-target-feature\" \"+crc32\" \"-target-feature\" \"+xsaves\" \"-target-feature\" \"-avx512fp16\" \"-target-feature\" \"-usermsr\" \"-target-feature\" \"-sm4\" \"-target-feature\" \"-egpr\" \"-target-feature\" \"+sse4.1\" \"-target-feature\" \"-avx512ifma\" \"-target-feature\" \"+xsave\" \"-target-feature\" \"+sse4.2\" \"-target-feature\" \"-tsxldtrk\" \"-target-feature\" \"-sm3\" \"-target-feature\" \"-ptwrite\" \"-target-feature\" \"-widekl\" \"-target-feature\" \"+invpcid\" \"-target-feature\" \"+64bit\" \"-target-feature\" \"+xsavec\" \"-target-feature\" \"-avx10.1-512\" \"-target-feature\" \"-avx512vpopcntdq\" \"-target-feature\" \"+cmov\" \"-target-feature\" \"-avx512vp2intersect\" \"-target-feature\" \"+avx512cd\" \"-target-feature\" \"+movbe\" \"-target-feature\" \"-avxvnniint8\" \"-target-feature\" \"-ccmp\" \"-target-feature\" \"-amx-int8\" \"-target-feature\" \"-kl\" \"-target-feature\" \"-avx10.1-256\" \"-target-feature\" \"+evex512\" \"-target-feature\" \"-avxvnni\" \"-target-feature\" \"+rtm\" \"-target-feature\" \"+adx\" \"-target-feature\" \"+avx2\" \"-target-feature\" \"-hreset\" \"-target-feature\" \"-movdiri\" \"-target-feature\" \"-serialize\" \"-target-feature\" \"-sha512\" \"-target-feature\" \"-vpclmulqdq\" \"-target-feature\" \"+avx512vl\" \"-target-feature\" \"-uintr\" \"-target-feature\" \"-cf\" \"-target-feature\" \"+clflushopt\" \"-target-feature\" \"-raoint\" \"-target-feature\" \"-cmpccxadd\" \"-target-feature\" \"+bmi\" \"-target-feature\" \"-amx-tile\" \"-target-feature\" \"+sse\" \"-target-feature\" \"-avx10.2-256\" \"-target-feature\" \"-gfni\" \"-target-feature\" \"-avxvnniint16\" \"-target-feature\" \"-amx-fp16\" \"-target-feature\" \"-zu\" \"-target-feature\" \"-ndd\" \"-target-feature\" \"+xsaveopt\" \"-target-feature\" \"+rdrnd\" \"-target-feature\" \"+avx512f\" \"-target-feature\" \"-amx-bf16\" \"-target-feature\" \"-avx512bf16\" \"-target-feature\" \"-avx512vnni\" \"-target-feature\" \"-push2pop2\" \"-target-feature\" \"+cx8\" \"-target-feature\" \"+avx512bw\" \"-target-feature\" \"+sse3\" \"-target-feature\" \"+pku\" \"-target-feature\" \"-nf\" \"-target-feature\" \"+fsgsbase\" \"-target-feature\" \"-clzero\" \"-target-feature\" \"-mwaitx\" \"-target-feature\" \"-lwp\" \"-target-feature\" \"+lzcnt\" \"-target-feature\" \"-sha\" \"-target-feature\" \"-movdir64b\" \"-target-feature\" \"-ppx\" \"-target-feature\" \"-wbnoinvd\" \"-target-feature\" \"-enqcmd\" \"-target-feature\" \"-avx10.2-512\" \"-target-feature\" \"-avxneconvert\" \"-target-feature\" \"-tbm\" \"-target-feature\" \"-pconfig\" \"-target-feature\" \"-amx-complex\" \"-target-feature\" \"+ssse3\" \"-target-feature\" \"+cx16\" \"-target-feature\" \"+bmi2\" \"-target-feature\" \"+fma\" \"-target-feature\" \"+popcnt\" \"-target-feature\" \"-avxifma\" \"-target-feature\" \"+f16c\" \"-target-feature\" \"-avx512bitalg\" \"-target-feature\" \"-rdpru\" \"-target-feature\" \"+clwb\" \"-target-feature\" \"+mmx\" \"-target-feature\" \"+sse2\" \"-target-feature\" \"+rdseed\" \"-target-feature\" \"-avx512vbmi2\" \"-target-feature\" \"-prefetchi\" \"-target-feature\" \"-rdpid\" \"-target-feature\" \"-fma4\" \"-target-feature\" \"-avx512vbmi\" \"-target-feature\" \"-shstk\" \"-target-feature\" \"-vaes\" \"-target-feature\" \"-waitpkg\" \"-target-feature\" \"-sgx\" \"-target-feature\" \"+fxsr\" \"-target-feature\" \"+avx512dq\" \"-target-feature\" \"-sse4a\" \"-debugger-tuning=gdb\" \"-fdebug-compilation-dir=/scratch3/opt/qmcpack/build_clangPatched_real/src/QMCHamiltonians\" \"-fcoverage-compilation-dir=/scratch3/opt/qmcpack/build_clangPatched_real/src/QMCHamiltonians\" \"-sys-header-deps\" \"-D\" \"ADD_\" \"-D\" \"H5_USE_110_API\" \"-D\" \"HAVE_CONFIG_H\" \"-D\" \"HAVE_EINSPLINE\" \"-D\" \"HAVE_LIBBOOST\" \"-D\" \"HAVE_LIBFFTW\" \"-D\" \"HAVE_MKL\" \"-D\" \"HAVE_MKL_VML\" \"-D\" \"MPICH_SKIP_MPICXX\" \"-D\" \"OMPI_SKIP_MPICXX\" \"-D\" \"OPENMP_NO_COMPLEX\" \"-D\" \"_MPICC_H\" \"-D\" \"restrict=__restrict__\" \"-D\" \"NDEBUG\" \"-O3\" \"-Wvla\" \"-Wall\" \"-Wno-unused-variable\" \"-Wno-overloaded-virtual\" \"-Wno-unused-private-field\" \"-Wno-unused-local-typedef\" \"-Wsuggest-override\" \"-Wno-unknown-pragmas\" \"-Wmisleading-indentation\" \"-std=c++17\" \"-fdeprecated-macro\" \"-ferror-limit\" \"19\" \"-fopenmp\" \"-fgnuc-version=4.2.1\" \"-fskip-odr-check-in-gmf\" \"-fcxx-exceptions\" \"-fexceptions\" \"-fcolor-diagnostics\" \"-vectorize-loops\" \"-vectorize-slp\" \"-faddrsig\" \"-D__GCC_HAVE_DWARF2_CFI_ASM=1\" \"-x\" \"c++\" \"PairCorrEstimator-40412c.cpp\"\r\n```", "author": "ye-luo", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
97053
https://github.com/llvm/llvm-project/issues/97053
miscompilation
a3571376ad9555de07e4d8f74f92de1eaa4c486e
2024-06-28T12:58:31
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "4d2ae88d1617a910ec3a1436ce53579523ac2f97", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [ [ 419, 424 ], [ 426, 431 ], [ 471, 478 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [ "InstCombinerImpl::visitExtractElementInst" ], "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 4d2ae88d1617a910ec3a1436ce53579523ac2f97 Author: Nikita Popov <[email protected]> Date: Wed Jul 3 10:58:38 2024 +0200 [InstCombine] Fix invalid scalarization of div If the binop is not speculatable, and the extract index is out of range, then scalarizing will perform the operation on a poison operand, resulting in immediate UB, instead of the previous poison result. Fixes https://github.com/llvm/llvm-project/issues/97053. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 3de56a403803..753ed55523c8 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -419,6 +419,7 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) { // If extracting a specified index from the vector, see if we can recursively // find a previously computed scalar that was inserted into the vector. auto *IndexC = dyn_cast<ConstantInt>(Index); + bool HasKnownValidIndex = false; if (IndexC) { // Canonicalize type of constant indices to i64 to simplify CSE if (auto *NewIdx = getPreferredVectorIndex(IndexC)) @@ -426,6 +427,7 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) { ElementCount EC = EI.getVectorOperandType()->getElementCount(); unsigned NumElts = EC.getKnownMinValue(); + HasKnownValidIndex = IndexC->getValue().ult(NumElts); if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(SrcVec)) { Intrinsic::ID IID = II->getIntrinsicID(); @@ -471,8 +473,11 @@ Instruction *InstCombinerImpl::visitExtractElementInst(ExtractElementInst &EI) { return UnaryOperator::CreateWithCopiedFlags(UO->getOpcode(), E, UO); } + // If the binop is not speculatable, we cannot hoist the extractelement if + // it may make the operand poison. BinaryOperator *BO; - if (match(SrcVec, m_BinOp(BO)) && cheapToScalarize(SrcVec, Index)) { + if (match(SrcVec, m_BinOp(BO)) && cheapToScalarize(SrcVec, Index) && + (HasKnownValidIndex || isSafeToSpeculativelyExecute(BO))) { // extelt (binop X, Y), Index --> binop (extelt X, Index), (extelt Y, Index) Value *X = BO->getOperand(0), *Y = BO->getOperand(1); Value *E0 = Builder.CreateExtractElement(X, Index);
[ { "file": "llvm/test/Transforms/InstCombine/scalarization.ll", "commands": [ "opt -passes=instcombine -S < %s" ], "tests": [ { "test_name": "extract_element_binop_splat_variable_index_may_trap", "test_body": "define i8 @extract_element_binop_splat_variable_index_may_trap(<4 x i8> %x, <4 x i8> %y, i32 %z) {\n %b = sdiv <4 x i8> splat (i8 42), %y\n %r = extractelement <4 x i8> %b, i32 %z\n ret i8 %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "extract_element_binop_splat_variable_index", "test_body": "define i8 @extract_element_binop_splat_variable_index(<4 x i8> %x, i32 %y) {\n %b = sdiv <4 x i8> %x, splat (i8 42)\n %r = extractelement <4 x i8> %b, i32 %y\n ret i8 %r\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Wrong swap between `sdiv` and `extractelement` by InstCombine", "body": "https://alive2.llvm.org/ce/z/mGNeLx\r\n\r\n\r\n```ll\r\n----------------------------------------\r\ndefine i8 @fun0(<4 x i8> %val0, i32 %val1) {\r\n#0:\r\n %val2 = sdiv <4 x i8> { 42, 42, 42, 42 }, %val0\r\n %val3 = extractelement <4 x i8> %val2, i32 %val1\r\n ret i8 %val3\r\n}\r\n=>\r\ndefine i8 @fun0(<4 x i8> %val0, i32 %val1) {\r\n#0:\r\n %#1 = extractelement <4 x i8> %val0, i32 %val1\r\n %val3 = sdiv i8 42, %#1\r\n ret i8 %val3\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\n<4 x i8> %val0 = < #x01 (1), #x08 (8), #x02 (2), #x04 (4) >\r\ni32 %val1 = #x20000000 (536870912)\r\n\r\nSource:\r\n<4 x i8> %val2 = < #x2a (42), #x05 (5), #x15 (21), #x0a (10) >\r\ni8 %val3 = poison\r\n\r\nTarget:\r\ni8 %#1 = poison\r\ni8 %val3 = UB triggered!\r\n\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```\r\n\r\n\r\n`sdiv` and `extractelement` cannot be swapped for vector operands as it can trigger UB, diving an integer by `poison`.", "author": "bongjunj", "labels": [ "miscompilation", "llvm:instcombine" ], "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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": [ [ 1058, 1063 ] ], "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": [ "classof" ], "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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)", "lli_expected_out": null, "additional_args": 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
100298
https://github.com/llvm/llvm-project/issues/100298
miscompilation
75642a00e15b722bdfb90726be31f1c8adaeb0c5
2024-07-24T04:19:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "59eae919c938f890e9b9b4be8a3fa3cb1b11ed89", "components": [ "ValueTracking" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 1435, 1441 ], [ 1468, 1474 ], [ 1546, 1552 ], [ 2329, 2335 ], [ 2943, 2949 ], [ 3509, 3515 ], [ 4001, 4007 ], [ 5909, 5918 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": [ [ 130, 135 ] ], "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ "ComputeNumSignBitsImpl", "computeKnownBitsFromOperator", "computeKnownFPClass", "isKnownNonZeroFromOperator", "isKnownToBeAPowerOfTwo", "isNonEqualPHIs" ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": [ "getWithCondContext" ], "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit a87fbeb3a77a53ded341277c5b326f7696d47594 Author: Yingwei Zheng <[email protected]> Date: Wed Jul 24 20:06:36 2024 +0800 [ValueTracking] Don't use CondContext in dataflow analysis of phi nodes (#100316) See the following case: ``` define i16 @pr100298() { entry: br label %for.inc for.inc: %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ] %add = add nsw i32 %indvar, 9 %mask = and i32 %add, 65535 %cmp1 = icmp ugt i32 %mask, 5 br i1 %cmp1, label %for.inc, label %for.end for.end: %conv = trunc i32 %add to i16 %cmp2 = icmp ugt i32 %mask, 3 %shl = shl nuw i16 %conv, 14 %res = select i1 %cmp2, i16 %conv, i16 %shl ret i16 %res } ``` When computing knownbits of `%shl` with `%cmp2=false`, we cannot use this condition in the analysis of `%mask (%for.inc -> %for.inc)`. Fixes https://github.com/llvm/llvm-project/issues/100298. (cherry picked from commit 59eae919c938f890e9b9b4be8a3fa3cb1b11ed89) diff --git a/llvm/include/llvm/Analysis/SimplifyQuery.h b/llvm/include/llvm/Analysis/SimplifyQuery.h index a560744f0122..e8f43c8c2e91 100644 --- a/llvm/include/llvm/Analysis/SimplifyQuery.h +++ b/llvm/include/llvm/Analysis/SimplifyQuery.h @@ -130,6 +130,12 @@ struct SimplifyQuery { Copy.CC = &CC; return Copy; } + + SimplifyQuery getWithoutCondContext() const { + SimplifyQuery Copy(*this); + Copy.CC = nullptr; + return Copy; + } }; } // end namespace llvm diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 40fe1ffe13f1..4b77c0046cc7 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1435,7 +1435,7 @@ static void computeKnownBitsFromOperator(const Operator *I, // inferred hold at original context instruction. TODO: It may be // correct to use the original context. IF warranted, explore and // add sufficient tests to cover. - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); RecQ.CxtI = P; computeKnownBits(R, DemandedElts, Known2, Depth + 1, RecQ); switch (Opcode) { @@ -1468,7 +1468,7 @@ static void computeKnownBitsFromOperator(const Operator *I, // phi. This is important because that is where the value is actually // "evaluated" even though it is used later somewhere else. (see also // D69571). - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); unsigned OpNum = P->getOperand(0) == R ? 0 : 1; Instruction *RInst = P->getIncomingBlock(OpNum)->getTerminator(); @@ -1546,7 +1546,7 @@ static void computeKnownBitsFromOperator(const Operator *I, // phi. This is important because that is where the value is actually // "evaluated" even though it is used later somewhere else. (see also // D69571). - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); RecQ.CxtI = P->getIncomingBlock(u)->getTerminator(); Known2 = KnownBits(BitWidth); @@ -2329,7 +2329,7 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth, // it is an induction variable where in each step its value is a power of // two. auto *PN = cast<PHINode>(I); - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); // Check if it is an induction variable and always power of two. if (isPowerOfTwoRecurrence(PN, OrZero, Depth, RecQ)) @@ -2943,7 +2943,7 @@ static bool isKnownNonZeroFromOperator(const Operator *I, return true; // Check if all incoming values are non-zero using recursion. - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); unsigned NewDepth = std::max(Depth, MaxAnalysisRecursionDepth - 1); return llvm::all_of(PN->operands(), [&](const Use &U) { if (U.get() == PN) @@ -3509,7 +3509,7 @@ static bool isNonEqualPHIs(const PHINode *PN1, const PHINode *PN2, if (UsedFullRecursion) return false; - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); RecQ.CxtI = IncomBB->getTerminator(); if (!isKnownNonEqual(IV1, IV2, DemandedElts, Depth + 1, RecQ)) return false; @@ -4001,7 +4001,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V, // Take the minimum of all incoming values. This can't infinitely loop // because of our depth threshold. - SimplifyQuery RecQ = Q; + SimplifyQuery RecQ = Q.getWithoutCondContext(); Tmp = TyBits; for (unsigned i = 0, e = NumIncomingValues; i != e; ++i) { if (Tmp == 1) return Tmp; @@ -5909,10 +5909,10 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts, // Recurse, but cap the recursion to two levels, because we don't want // to waste time spinning around in loops. We need at least depth 2 to // detect known sign bits. - computeKnownFPClass( - IncValue, DemandedElts, InterestedClasses, KnownSrc, - PhiRecursionLimit, - Q.getWithInstruction(P->getIncomingBlock(U)->getTerminator())); + computeKnownFPClass(IncValue, DemandedElts, InterestedClasses, KnownSrc, + PhiRecursionLimit, + Q.getWithoutCondContext().getWithInstruction( + P->getIncomingBlock(U)->getTerminator())); if (First) { Known = KnownSrc;
[ { "file": "llvm/test/Transforms/InstCombine/pr100298.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr100298", "test_body": "define i16 @pr100298() {\nentry:\n br label %for.inc\n\nfor.inc: ; preds = %for.inc, %entry\n %indvar = phi i32 [ -15, %entry ], [ %mask, %for.inc ]\n %add = add nsw i32 %indvar, 9\n %mask = and i32 %add, 65535\n %cmp1 = icmp ugt i32 %mask, 5\n br i1 %cmp1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.inc\n %conv = trunc i32 %add to i16\n %cmp2 = icmp ugt i32 %mask, 3\n %shl = shl nuw i16 %conv, 14\n %res = select i1 %cmp2, i16 %conv, i16 %shl\n ret i16 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Miscompilation at O3", "body": "```\r\n#include \"csmith.h\"\r\nuint32_t a;\r\nint16_t c;\r\nvoid d() {\r\n for (a = -15; a >= 6; a = safe_add_func_uint16_t_u_u(a, 9))\r\n ;\r\n c = safe_lshift_func_int16_t_s_u(safe_lshift_func_uint16_t_u_s(a,14), 0);\r\n}\r\nint main() {\r\n d();\r\n printf(\"%d\\n\", c);\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ gcc -O0 test.c -fsanitize=undefined -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n-16384\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ bin/clang -O3 test.c -I/usr/include/csmith -w\r\ndtcxzyw@dtcxzyw:~/WorkSpace/Projects/compilers/LLVM/llvm-build$ ./a.out \r\n0\r\n```\r\n\r\nllvm version: 2d6ff0c533aa1b0fe6d91764846f636c4a4e911c", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced testcase: https://alive2.llvm.org/ce/z/9fExrA\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i16 @src() {\r\nentry:\r\n br label %for.inc\r\n\r\nfor.inc:\r\n %storemerge6 = phi i32 [ -15, %entry ], [ %conv1, %for.inc ]\r\n %add.i = add nsw i32 %storemerge6, 9\r\n %conv1 = and i32 %add.i, 65535\r\n %cmp = icmp ugt i32 %conv1, 5\r\n br i1 %cmp, label %for.inc, label %for.end\r\n\r\nfor.end:\r\n %conv2 = trunc nuw nsw i32 %conv1 to i16\r\n %cmp3.i = icmp ugt i32 %conv1, 3\r\n %0 = shl nuw i16 %conv2, 14\r\n %cond.in.i = select i1 %cmp3.i, i16 %conv2, i16 %0\r\n ret i16 %cond.in.i\r\n}\r\n```" } ] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": [ [ 1988, 1994 ] ], "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": [ "InstCombinerImpl::visitCallInst" ], "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
104422
https://github.com/llvm/llvm-project/issues/104422
miscompilation
13a6a7975256ebdbce85f1174ae2eec735fa0d7a
2024-08-15T09:29:27
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "56140a8258a3498cfcd9f0f05c182457d43cbfd2", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 15663, 15669 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::collectValuesToDemote" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 56140a8258a3498cfcd9f0f05c182457d43cbfd2 Author: Alexey Bataev <[email protected]> Date: Thu Aug 15 07:57:37 2024 -0700 [SLP]Fix PR104422: Wrong value truncation The minbitwidth restrictions can be skipped only for immediate reduced values, for other nodes still need to check if external users allow bitwidth reduction. Fixes https://github.com/llvm/llvm-project/issues/104422 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 81841a8f6928..87b4ed599b5b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -15663,7 +15663,8 @@ bool BoUpSLP::collectValuesToDemote( if (any_of(E.Scalars, [&](Value *V) { return !all_of(V->users(), [=](User *U) { return getTreeEntry(U) || - (UserIgnoreList && UserIgnoreList->contains(U)) || + (E.Idx == 0 && UserIgnoreList && + UserIgnoreList->contains(U)) || (!isa<CmpInst>(U) && U->getType()->isSized() && !U->getType()->isScalableTy() && DL->getTypeSizeInBits(U->getType()) <= BitWidth);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/operand-is-reduced-val.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s -slp-threshold=-10" ], "tests": [ { "test_name": "src", "test_body": "define i64 @src(i32 %a) {\nentry:\n %0 = sext i32 %a to i64\n %1 = add nsw i64 %0, 4294967297\n %2 = sext i32 %a to i64\n %3 = add nsw i64 %2, 4294967297\n %4 = add i64 %3, %1\n %5 = and i64 %3, 1\n %6 = add i64 %4, %5\n %7 = sext i32 %a to i64\n %8 = add nsw i64 %7, 4294967297\n %9 = add i64 %8, %6\n %10 = and i64 %8, 1\n %11 = add i64 %9, %10\n %12 = sext i32 %a to i64\n %13 = add nsw i64 %12, 4294967297\n %14 = add i64 %13, %11\n %15 = and i64 %13, 1\n %16 = add i64 %14, %15\n %17 = sext i32 %a to i64\n %18 = add nsw i64 %17, 4294967297\n %19 = add i64 %18, %16\n %20 = and i64 %18, 1\n %21 = add i64 %19, %20\n ret i64 %21\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Wrong value truncation ", "body": "- There seems to be an issue with SLPVectorizer. In the following example, a 2-byte wide value is incorrectly truncated:\r\n\r\n```\r\ndefine i64 @test(ptr addrspace(1) %arr, i32 %a) {\r\nentry:\r\n br label %loop\r\n\r\nloop:\r\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\r\n %local_1_7 = phi i64 [ 0, %entry ], [ %4, %loop ]\r\n %0 = sext i32 %a to i64\r\n %1 = add nsw i64 %0, 4294967297\r\n %2 = add i64 %1, %local_1_7\r\n %3 = and i64 %1, 1\r\n %4 = add i64 %2, %3\r\n %iv.next = add nuw nsw i64 %iv, 1\r\n %5 = icmp ugt i64 %iv, 355\r\n br i1 %5, label %exit, label %loop\r\n\r\nexit:\r\n ret i64 %4\r\n}\r\n```\r\n- In the loop we summarize the constant 4294967297 (`0x1'0000'0001`), but after running SLPVectorizer over the unrolled loop, the constant is truncated to `1`:\r\n```\r\nloop: \r\n %iv = phi i64 [ 0, %entry ], [ %iv.next.16, %loop ]\r\n %local_1_7 = phi i64 [ 0, %entry ], [ %op.rdx3, %loop ]\r\n %2 = add <16 x i32> %1, <i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1>\r\n %3 = sext <16 x i32> %2 to <16 x i64>\r\n...\r\n```\r\n- Command to reproduce: `opt -passes=loop-unroll,slp-vectorizer -unroll-count=17`\r\n- https://godbolt.org/z/zcPefTPzW\r\n- Looks like the issue was caused by the https://github.com/llvm/llvm-project/commit/7f2167868d8c1cedd3915883412b9c787a2f01db\r\n\r\n@alexey-bataev Could you please take a look?\r\n", "author": "aleks-tmb", "labels": [ "miscompilation", "release:backport", "llvm:SLPVectorizer" ], "comments": [ { "author": "nikic", "body": "This probably needs an LLVM 19 backport?\r\n\r\n/cherry-pick 65ac12d3c9877ecf5b97552364e7eead887d94eb 56140a8258a3498cfcd9f0f05c182457d43cbfd2" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ [ 935, 943 ], [ 945, 955 ], [ 3362, 3370 ] ], "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ "InstCombinerImpl::foldAndOrOfICmps", "foldIsPowerOf2OrZero" ], "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
95520
https://github.com/llvm/llvm-project/issues/95520
crash
e7acb3792b8ba971bda2c9564ed26c2a60a2ddbc
2024-06-14T09:26:34
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "40a72f8cc414726a8be234a260650fd62354da21", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 577, 583 ] ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": [ [ 231, 236 ] ], "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPInstruction::generatePerPart" ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": [ "VPTransformState::get" ], "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 40a72f8cc414726a8be234a260650fd62354da21 Author: Florian Hahn <[email protected]> Date: Fri Jun 14 22:16:51 2024 +0100 [VPlan] Support extracting any lane of uniform value. If the value we are extracting a lane from is uniform, only the first lane will be set. Return lane 0 for any requested lane. This fixes a crash when trying to extract the last lane for a first-order recurrence resume value. Fixes https://github.com/llvm/llvm-project/issues/95520. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index f17be451e684..348a2be5072b 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -231,6 +231,11 @@ Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) { return Data .PerPartScalars[Def][Instance.Part][Instance.Lane.mapToCacheIndex(VF)]; } + if (!Instance.Lane.isFirstLane() && + vputils::isUniformAfterVectorization(Def) && + hasScalarValue(Def, {Instance.Part, VPLane::getFirstLane()})) { + return Data.PerPartScalars[Def][Instance.Part][0]; + } assert(hasVectorValue(Def, Instance.Part)); auto *VecPart = Data.PerPartOutput[Def][Instance.Part]; diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 7a482455473e..a3ff6395bb39 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -577,7 +577,8 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) { // When loop is unrolled without vectorizing, retrieve UF - Offset. Res = State.get(getOperand(0), State.UF - Offset); } - Res->setName(Name); + if (isa<ExtractElementInst>(Res)) + Res->setName(Name); return Res; } case VPInstruction::LogicalAnd: {
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/reduction-recurrence-costs-sve.ll", "commands": [ "opt -p loop-vectorize -S %s", "opt -p loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S %s" ], "tests": [ { "test_name": "chained_recurrences", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\ndefine i32 @chained_recurrences(i32 %x, i64 %y, ptr %src.1, i32 %z, ptr %src.2) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %0 = phi i32 [ 0, %entry ], [ %3, %loop ]\n %1 = phi i32 [ 0, %entry ], [ %0, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %sum.red = phi i32 [ 0, %entry ], [ %red.2, %loop ]\n %2 = add i64 %y, 1\n %gep.1 = getelementptr i32, ptr %src.1, i64 %2\n %3 = load i32, ptr %gep.1, align 4\n %or3 = or i32 %1, %x\n %iv.next = add i64 %iv, 1\n %shr = lshr i32 %x, 1\n %4 = shl i32 %or3, 1\n %5 = or i32 %4, 2\n %shl19 = shl i32 %x, 1\n %6 = or i32 %shr, %shl19\n %7 = or i32 %6, %5\n %8 = or i32 %7, %x\n %or20 = or i32 %z, %x\n %not = and i32 %or20, 1\n %and = xor i32 %not, 1\n %idx.ext.1 = zext i32 %and to i64\n %gep.2 = getelementptr i32, ptr %src.2, i64 %idx.ext.1\n %9 = load i32, ptr %gep.2, align 4\n %shr24 = lshr i32 %8, 1\n %idx.ext.2 = zext i32 %shr24 to i64\n %gep.3 = getelementptr i32, ptr %src.2, i64 %idx.ext.2\n %10 = load i32, ptr %gep.3, align 4\n %red.1 = or i32 %9, %sum.red\n %red.2 = or i32 %red.1, %10\n %ec = icmp eq i64 %iv, %y\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %red.2\n}\n\nattributes #0 = { \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test_resinking_required", "test_body": "define double @test_resinking_required(ptr %p, ptr noalias %a, ptr noalias %b) {\nEntry:\n br label %Loop\n\nLoop: ; preds = %Loop, %Entry\n %for.1 = phi double [ %l1, %Loop ], [ 0.000000e+00, %Entry ]\n %for.2 = phi double [ %l2, %Loop ], [ 0.000000e+00, %Entry ]\n %for.3 = phi double [ %for.2, %Loop ], [ 0.000000e+00, %Entry ]\n %iv = phi i64 [ %iv.next, %Loop ], [ 0, %Entry ]\n %USE_2_FORS = fdiv double %for.3, %for.1\n %div = fdiv double 0.000000e+00, %for.1\n %l1 = load double, ptr %a, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %l2 = load double, ptr %b, align 8\n store double %div, ptr %p, align 8\n %cond = icmp eq i64 %iv.next, 0\n br i1 %cond, label %End, label %Loop\n\nEnd: ; preds = %Loop\n %res.1 = fadd double %for.1, %for.2\n %res.2 = fadd double %res.1, %for.3\n ret double %res.2\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-complex.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "instruction_with_2_FOR_operands_and_multiple_other_uses_chain", "test_body": "define void @instruction_with_2_FOR_operands_and_multiple_other_uses_chain(ptr noalias %dst.1, ptr noalias %dst.2, ptr noalias %dst.3, ptr noalias %for.ptr.1, ptr noalias %for.ptr.2) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %for.1 = phi float [ 0.000000e+00, %bb ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %bb ], [ %for.2.next, %loop ]\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %for.1.use.1 = fmul fast float %for.1, 2.000000e+00\n %for.1.use.c = fmul fast float %for.1.use.1, 2.000000e+00\n %used.by.both = fmul fast float %for.1.use.c, %for.2\n %for.2.next = load float, ptr %for.ptr.2, align 4\n %for.1.use.3 = fadd fast float %for.1, 1.000000e+00\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %for.ptr.1, align 4\n %gep.dst.1 = getelementptr inbounds float, ptr %dst.1, i64 %iv\n store float %used.by.both, ptr %gep.dst.1, align 4\n %gep.dst.2 = getelementptr inbounds float, ptr %dst.2, i64 %iv\n store float %for.1.use.1, ptr %gep.dst.2, align 4\n %gep.dst.3 = getelementptr inbounds float, ptr %dst.3, i64 %iv\n store float %for.1.use.3, ptr %gep.dst.3, align 4\n %ec = icmp slt i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "instruction_with_2_FOR_operands_and_multiple_other_uses", "test_body": "define void @instruction_with_2_FOR_operands_and_multiple_other_uses(ptr noalias %dst.1, ptr noalias %dst.2, ptr noalias %dst.3, ptr noalias %for.ptr.1, ptr noalias %for.ptr.2) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %for.1 = phi float [ 0.000000e+00, %bb ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %bb ], [ %for.2.next, %loop ]\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %for.1.use.1 = fmul fast float %for.1, 2.000000e+00\n %used.by.both = fmul fast float %for.1, %for.2\n %for.2.next = load float, ptr %for.ptr.2, align 4\n %for.1.use.3 = fadd fast float %for.1, 1.000000e+00\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %for.ptr.1, align 4\n %gep.dst.1 = getelementptr inbounds float, ptr %dst.1, i64 %iv\n store float %used.by.both, ptr %gep.dst.1, align 4\n %gep.dst.2 = getelementptr inbounds float, ptr %dst.2, i64 %iv\n store float %for.1.use.1, ptr %gep.dst.2, align 4\n %gep.dst.3 = getelementptr inbounds float, ptr %dst.3, i64 %iv\n store float %for.1.use.3, ptr %gep.dst.3, align 4\n %ec = icmp slt i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "instruction_with_2_FOR_operands", "test_body": "define void @instruction_with_2_FOR_operands(ptr noalias %A, ptr noalias %B, ptr noalias %C) {\nbb:\n br label %bb13\n\nbb13: ; preds = %bb13, %bb\n %tmp37 = phi float [ %tmp60, %bb13 ], [ 0.000000e+00, %bb ]\n %tmp27 = phi float [ %tmp49, %bb13 ], [ 1.000000e+00, %bb ]\n %iv = phi i64 [ %iv.next, %bb13 ], [ 0, %bb ]\n %tmp38 = fmul fast float %tmp37, %tmp27\n %iv.next = add nuw nsw i64 %iv, 1\n %gep = getelementptr inbounds float, ptr %C, i64 %iv\n %tmp49 = load float, ptr %A, align 4\n %tmp60 = load float, ptr %B, align 4\n store float %tmp38, ptr %gep, align 4\n %tmp12 = icmp slt i64 %iv, 1000\n br i1 %tmp12, label %bb13, label %bb74\n\nbb74: ; preds = %bb13\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-multiply-recurrences.ll", "commands": [], "tests": [ { "test_name": "test_pr54233_for_depend_on_each_other", "test_body": "define void @test_pr54233_for_depend_on_each_other(ptr noalias %a, ptr noalias %b) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for.1 = phi i32 [ 0, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi i32 [ 0, %entry ], [ %for.2.next, %loop ]\n %or = or i32 %for.2, 10\n %shl = shl i32 %for.2, %for.1\n %xor = xor i32 %shl, 255\n %and = and i32 %xor, %or\n %for.1.next = xor i32 12, %for.2\n %for.2.next = load i32, ptr %b, align 4\n %a.gep = getelementptr inbounds i32, ptr %a, i64 %iv\n store i32 %and, ptr %a.gep, align 4\n %iv.next = add nuw i64 %iv, 1\n %exitcond = icmp eq i64 %iv, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_pr54223_sink_after_insertion_order", "test_body": "define void @test_pr54223_sink_after_insertion_order(ptr noalias %a, ptr noalias %b, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for.1 = phi float [ 0.000000e+00, %entry ], [ %for.1.next, %loop ]\n %for.2 = phi float [ 0.000000e+00, %entry ], [ %for.2.next, %loop ]\n %neg = fneg float %for.2\n %muladd = call float @llvm.fmuladd.f32(float %for.1, float %neg, float 0.000000e+00)\n %dst.gep = getelementptr inbounds float, ptr %dst, i64 %iv\n %iv.next = add nuw nsw i64 %iv, 1\n %for.1.next = load float, ptr %a, align 4\n %for.2.next = load float, ptr %b, align 4\n store float %muladd, ptr %dst.gep, align 4\n %exitcond.not = icmp eq i64 %iv.next, 10000\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 float @llvm.fmuladd.f32(float, float, float) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -force-widen-divrem-via-safe-divisor=0 -S" ], "tests": [ { "test_name": "recurence_uniform_load", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @recurence_uniform_load(ptr %src, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 0, %entry ], [ %add, %loop ]\n %recur = phi i32 [ 0, %entry ], [ %load, %loop ]\n %add = add i64 %phi, 1\n %load = load i32, ptr %src, align 4\n %icmp = icmp ult i64 %phi, 1\n br i1 %icmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `hasVectorValue(Def, Instance.Part)' failed.", "body": "To reproduce run the following test 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 i32 @wombat() gc \"statepoint-example\" {\r\nbb:\r\n br label %bb2\r\n\r\nbb1: ; preds = %bb2\r\n ret i32 0\r\n\r\nbb2: ; preds = %bb2, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb2 ]\r\n %phi3 = phi i32 [ 0, %bb ], [ %load, %bb2 ]\r\n %add = add i64 %phi, 1\r\n %load = load i32, ptr addrspace(1) null, align 4\r\n %icmp = icmp ult i64 %phi, 1\r\n br i1 %icmp, label %bb2, label %bb1\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/cv7Tf3vba\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\n #0 0x0000000004e41688 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e41688)\r\n #1 0x0000000004e3eddc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007ec2abe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ec2abe969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ec2abe42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ec2abe287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ec2abe2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ec2abe39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003fecdce (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fecdce)\r\n #9 0x0000000004008abe llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4008abe)\r\n#10 0x000000000400ae5e llvm::VPInstruction::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x400ae5e)\r\n#11 0x0000000003fe5fbf llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe5fbf)\r\n#12 0x0000000003fe9cb0 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe9cb0)\r\n#13 0x0000000003feda3e llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3feda3e)\r\n#14 0x0000000003eda4e5 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+0x3eda4e5)\r\n#15 0x0000000003eef18b llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3eef18b)\r\n#16 0x0000000003ef1a4d 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+0x3ef1a4d)\r\n#17 0x0000000003ef2c5b llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ef2c5b)\r\n#18 0x0000000002e0679e 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+0x2e0679e)\r\n#19 0x0000000004c49a6c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c49a6c)\r\n#20 0x0000000000dbabee 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+0xdbabee)\r\n#21 0x0000000004c483ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c483ae)\r\n#22 0x0000000000dbc65e 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+0xdbc65e)\r\n#23 0x0000000004c462bc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c462bc)\r\n#24 0x00000000008db912 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+0x8db912)\r\n#25 0x00000000008ceabc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ceabc)\r\n#26 0x00007ec2abe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007ec2abe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008c5f0e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c5f0e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n\r\n", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "cc @fhahn " } ] }
true
null
129236
https://github.com/llvm/llvm-project/issues/129236
crash
fa5db05ca36a732bffb8128ff017c575ec6e1201
2025-02-28T12:37:14
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "f937b17e8570082d4710b6dca7a91b5c235c1c70", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6673, 6679 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInstructionCost" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit f937b17e8570082d4710b6dca7a91b5c235c1c70 Author: Florian Hahn <[email protected]> Date: Sun Mar 2 10:55:42 2025 +0000 [LV] Don't query SCEV for non-invariant values in cost model. This fixes a divergence between VPlan and legacy cost model, matching behavior further up in getInstructionCost as well. Fixes https://github.com/llvm/llvm-project/issues/129236. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c447fa484359..f3bdc95713af 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6673,7 +6673,8 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, // Certain instructions can be cheaper to vectorize if they have a constant // second vector operand. One example of this are shifts on x86. Value *Op2 = I->getOperand(1); - if (!isa<Constant>(Op2) && PSE.getSE()->isSCEVable(Op2->getType()) && + if (!isa<Constant>(Op2) && TheLoop->isLoopInvariant(Op2) && + PSE.getSE()->isSCEVable(Op2->getType()) && isa<SCEVConstant>(PSE.getSCEV(Op2))) { Op2 = cast<SCEVConstant>(PSE.getSCEV(Op2))->getValue(); }
[ { "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_ashr_with_op_known_invariant_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 i32 @cost_ashr_with_op_known_invariant_via_scev(i8 %a) {\nentry:\n %cmp.i = icmp eq i16 0, 0\n %conv.i = sext i16 0 to i32\n %conv5.i = sext i8 %a to i32\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i8 [ 100, %entry ], [ %iv.next, %loop.latch ]\n br i1 %cmp.i, label %then, label %else\n\nthen: ; preds = %else, %loop.header\n %p.1 = phi i32 [ %rem.i, %else ], [ 0, %loop.header ]\n %shr.i = ashr i32 %conv5.i, %p.1\n %tobool6.not.i = icmp eq i32 %shr.i, 0\n %sext.i = shl i32 %p.1, 24\n %0 = ashr exact i32 %sext.i, 24\n %1 = select i1 %tobool6.not.i, i32 %0, i32 0\n br label %loop.latch\n\nelse: ; preds = %loop.header\n %rem.i = urem i32 -1, %conv.i\n %cmp3.i = icmp sgt i32 %rem.i, 1\n br i1 %cmp3.i, label %loop.latch, label %then\n\nloop.latch: ; preds = %else, %then\n %p.2 = phi i32 [ 0, %else ], [ %1, %then ]\n %iv.next = add i8 %iv, -1\n %ec = icmp eq i8 %iv.next, 0\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 %p.2\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Crash at -O2: Assertion Assertion `(BestFactor.Width == LegacyVF.Width || PlanForEarlyExitLoop...' failed.", "body": "This code crashes at `-O2`:\n\n```c\nchar a;\nstruct b {\n short c;\n char d;\n long e;\n int f;\n} static g;\nint h;\nvoid i(struct b j) {\n char k;\n int l;\n for (; j.d; --j.d) {\n l = g.c == 0 ? 0 : 4294967295U % g.c;\n k = l >= 2 || a >> l ? 0 : l;\n h = k;\n }\n}\nvoid m() { i(g); }\n```\n\nCompiler Explorer: https://godbolt.org/z/WG85qYnc6\n\nBisected to https://github.com/llvm/llvm-project/commit/30f3752e54fa7cd595a434a985efbe9a7abe9b65, which was committed by @fhahn \n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7589: 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.\n```\n\nBacktrace:\n\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wall -Wextra <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"i\"\n #0 0x0000000003e76828 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e76828)\n #1 0x0000000003e744e4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e744e4)\n #2 0x0000000003dc0e18 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007e3b78e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007e3b78e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007e3b78e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007e3b78e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007e3b78e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007e3b78e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00000000059b6042 llvm::LoopVectorizationPlanner::computeBestVF() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59b6042)\n#10 0x00000000059cd46c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59cd46c)\n#11 0x00000000059cfb19 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59cfb19)\n#12 0x00000000059d0193 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x59d0193)\n#13 0x0000000005546d4e 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+0x5546d4e)\n#14 0x000000000381d3f0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381d3f0)\n#15 0x000000000119ab8e 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+0x119ab8e)\n#16 0x000000000381bd0b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381bd0b)\n#17 0x0000000001199e3e 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+0x1199e3e)\n#18 0x000000000381b710 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x381b710)\n#19 0x00000000041305e8 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#20 0x000000000413485e 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+0x413485e)\n#21 0x0000000004835d60 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4835d60)\n#22 0x000000000642100c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x642100c)\n#23 0x0000000004836168 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4836168)\n#24 0x0000000004afe6e5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4afe6e5)\n#25 0x0000000004a81dce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a81dce)\n#26 0x0000000004bec53e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bec53e)\n#27 0x0000000000d4401f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd4401f)\n#28 0x0000000000d3b93a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#29 0x000000000487e099 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#30 0x0000000003dc12c4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dc12c4)\n#31 0x000000000487e68f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#32 0x00000000048412ad clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48412ad)\n#33 0x000000000484232e 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+0x484232e)\n#34 0x000000000484a2c5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x484a2c5)\n#35 0x0000000000d40e13 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd40e13)\n#36 0x0000000000c11aa4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc11aa4)\n#37 0x00007e3b78e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#38 0x00007e3b78e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#39 0x0000000000d3b3e5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd3b3e5)\n```", "author": "cardigan1008", "labels": [ "regression", "vectorizers", "crash" ], "comments": [] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": 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/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": 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/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
91178
https://github.com/llvm/llvm-project/issues/91178
miscompilation
7098cd215b95286794d9e0c822e8323ad0509750
2024-05-06T09:44:48
[ "llvm/test/Transforms/InstCombine", "llvm/test/Transforms/PGOProfile" ]
{ "fix_commit": "d085b42cbbefe79a41113abcd2b1e1f2a203acef", "components": [ "InstructionSimplify" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": [ [ 4312, 4317 ] ], "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": [ "simplifyWithOpReplaced" ], "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit d085b42cbbefe79a41113abcd2b1e1f2a203acef Author: Yingwei Zheng <[email protected]> Date: Wed May 8 10:04:09 2024 +0800 [InstSimplify] Do not simplify freeze in `simplifyWithOpReplaced` (#91215) See the LangRef: > All uses of a value returned by the same ‘freeze’ instruction are guaranteed to always observe the same value, while different ‘freeze’ instructions may yield different values. It is incorrect to replace freezes with the simplified value. Proof: https://alive2.llvm.org/ce/z/3Dn9Cd https://alive2.llvm.org/ce/z/Qyh5h6 Fixes https://github.com/llvm/llvm-project/issues/91178 diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 4061dae83c10..37a7259a5cd0 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4312,6 +4312,10 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, if (match(I, m_Intrinsic<Intrinsic::is_constant>())) return nullptr; + // Don't simplify freeze. + if (isa<FreezeInst>(I)) + return nullptr; + // Replace Op with RepOp in instruction operands. SmallVector<Value *, 8> NewOps; bool AnyReplaced = false;
[ { "file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "icmp_freeze_sext", "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_freeze_sext(i16 %x, i16 %y) {\n %cmp1 = icmp uge i16 %x, %y\n %ext = sext i1 %cmp1 to i16\n %ext.fr = freeze i16 %ext\n %cmp2 = icmp uge i16 %ext.fr, %y\n ret i1 %cmp2\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/select.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_replace_freeze_oneuse", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @test_replace_freeze_oneuse(i1 %x, i8 %y) {\n %ext = zext i1 %x to i8\n %shl = shl nuw i8 %ext, %y\n %shl.fr = freeze i8 %shl\n %sel = select i1 %x, i8 0, i8 %shl.fr\n ret i8 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sequence_select_with_same_cond_extra_use", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndeclare void @use32(i32)\n\ndefine i32 @sequence_select_with_same_cond_extra_use(i1 %c1, i1 %c2) {\n %s1 = select i1 %c1, i32 23, i32 45\n call void @use32(i32 %s1)\n %s2 = select i1 %c2, i32 666, i32 %s1\n %s3 = select i1 %c1, i32 789, i32 %s2\n ret i32 %s3\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_replace_freeze_multiuse", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @test_replace_freeze_multiuse(i1 %x, i8 %y) {\n %ext = zext i1 %x to i8\n %shl = shl nuw i8 %ext, %y\n %shl.fr = freeze i8 %shl\n %sel = select i1 %x, i8 0, i8 %shl.fr\n %add = add i8 %shl.fr, %sel\n ret i8 %add\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Miscompilation which simplifies a use of a multi-use freeze", "body": "Reduced test case: https://alive2.llvm.org/ce/z/_JyUGw\r\n```\r\ndefine i8 @func78(i1 %0, i8 %1) {\r\n %3 = zext i1 %0 to i8\r\n %4 = shl i8 %3, %1\r\n %5 = freeze i8 %4\r\n %6 = select i1 %0, i8 0, i8 %5\r\n %7 = call i8 @llvm.fshr.i8(i8 0, i8 %5, i8 %6)\r\n ret i8 %7\r\n}\r\n```\r\n\r\n```\r\n----------------------------------------\r\ndefine i8 @func78(i1 %#0, i8 %#1) {\r\n#2:\r\n %#3 = zext i1 %#0 to i8\r\n %#4 = shl i8 %#3, %#1\r\n %#5 = freeze i8 %#4\r\n %#6 = select i1 %#0, i8 0, i8 %#5\r\n %#7 = fshr i8 0, i8 %#5, i8 %#6\r\n ret i8 %#7\r\n}\r\n=>\r\ndefine i8 @func78(i1 %#0, i8 %#1) nofree noundef willreturn memory(none) {\r\n#2:\r\n %#3 = zext i1 %#0 to i8\r\n %#4 = shl nuw i8 %#3, %#1\r\n %#5 = freeze i8 %#4\r\n ret i8 %#5\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\ni1 %#0 = #x0 (0)\r\ni8 %#1 = #x08 (8)\r\n\r\nSource:\r\ni8 %#3 = #x00 (0)\r\ni8 %#4 = poison\r\ni8 %#5 = #x00 (0)\r\ni8 %#6 = #x00 (0)\r\ni8 %#7 = #x00 (0)\r\n\r\nTarget:\r\ni8 %#3 = #x00 (0)\r\ni8 %#4 = poison\r\ni8 %#5 = #x9d (157, -99)\r\nSource value: #x00 (0)\r\nTarget value: #x9d (157, -99)\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [ [ 2066, 2079 ], [ 2095, 2101 ], [ 2108, 2114 ], [ 2131, 2137 ] ], "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [ "simplifyIRemMulShl" ], "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
118798
https://github.com/llvm/llvm-project/issues/118798
hang
8a90b5b31776957cb9cfa4f9547d19544640c5cc
2024-12-05T13:19:25
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "27eaa8a40ef338bea611f693fa8e810b1fc8d78d", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": [ [ 427, 433 ] ], "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": [ "InstCombinerImpl::commonShiftTransforms" ], "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 27eaa8a40ef338bea611f693fa8e810b1fc8d78d Author: Maurice Heumann <[email protected]> Date: Thu Dec 5 16:57:27 2024 +0100 [InstCombine] Prevent infinite loop with two shifts (#118806) The following pattern: `(C2 << X) << C1` will usually be transformed into `(C2 << C1) << X`, essentially swapping `X` and `C1`. However, this should only be done when `C1` is an immediate constant, otherwise thiscan lead to both constants being swapped forever. This fixes #118798. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index 10c3ccdb2243..d511e79e3e48 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -427,7 +427,8 @@ Instruction *InstCombinerImpl::commonShiftTransforms(BinaryOperator &I) { if (Instruction *R = FoldOpIntoSelect(I, SI)) return R; - if (Constant *CUI = dyn_cast<Constant>(Op1)) + Constant *CUI; + if (match(Op1, m_ImmConstant(CUI))) if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I)) return Res;
[ { "file": "llvm/test/Transforms/InstCombine/shl-twice-constant.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "testfunc", "test_body": "@c = external constant i8\n@c2 = external constant i8\n\ndefine i64 @testfunc() {\n %shl1 = shl i64 1, ptrtoint (ptr @c2 to i64)\n %shl2 = shl i64 %shl1, ptrtoint (ptr @c to i64)\n ret i64 %shl2\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Infinite loop when combining two `shl` instructions", "body": "The following sample triggers an infinite loop in instcombine:\n\n```\n@c = external constant i8\n@c2 = external constant i8\n\ndefine i16 @testfunc() {\nentry:\n %0 = shl i64 1, ptrtoint (ptr @c2 to i64)\n %1 = shl i64 %0, ptrtoint (ptr @c to i64)\n %2 = inttoptr i64 %1 to ptr\n %3 = load i16, ptr %2, align 1\n ret i16 %3\n}\n```\n\nhttps://godbolt.org/z/WP6YvGjPq\n", "author": "momo5502", "labels": [ "llvm:instcombine", "llvm:hang" ], "comments": [ { "author": "momo5502", "body": "I have a potential fix and will create a PR soon" } ] }
true
null
89390
https://github.com/llvm/llvm-project/issues/89390
miscompilation
d674f45d51bffbba474b12e07f7d57a2390d2f31
2024-04-19T14:44:07
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 1405, 1410 ] ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::foldShuffleOfBinops" ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 4cc9c6d98dfef90d1ffa69977d13ffa2894a10f7 Author: Simon Pilgrim <[email protected]> Date: Mon Apr 22 09:00:20 2024 +0100 [VectorCombine] foldShuffleOfBinops - don't fold shuffle(divrem(x,y),divrem(z,w)) if mask contains poison Fixes #89390 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 4918cee1fa82..f23b10540338 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1405,6 +1405,11 @@ bool VectorCombine::foldShuffleOfBinops(Instruction &I) { B0->getOpcode() != B1->getOpcode() || B0->getType() != VecTy) return false; + // Don't introduce poison into div/rem. + if (any_of(Mask, [](int M) { return M == PoisonMaskElem; }) && + B0->isIntDivRem()) + return false; + // Try to replace a binop with a shuffle if the shuffle is not costly. // The new shuffle will choose from a single, common operand, so it may be // cheaper than the existing two-operand shuffle.
[ { "file": "llvm/test/Transforms/VectorCombine/X86/shuffle-of-binops.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=SSE2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=AVX2" ], "tests": [ { "test_name": "shuf_and_v16i16_yy_expensive_shuf", "test_body": "define <16 x i16> @shuf_and_v16i16_yy_expensive_shuf(<16 x i16> %x, <16 x i16> %y, <16 x i16> %z) {\n %b0 = and <16 x i16> %x, %y\n %b1 = and <16 x i16> %y, %z\n %r = shufflevector <16 x i16> %b0, <16 x i16> %b1, <16 x i32> <i32 15, i32 22, i32 25, i32 13, i32 28, i32 0, i32 poison, i32 3, i32 0, i32 30, i32 3, i32 7, i32 9, i32 19, i32 2, i32 22>\n ret <16 x i16> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "shuf_srem_v4i32_poison", "test_body": "define <4 x i32> @shuf_srem_v4i32_poison(<4 x i32> %a0, <4 x i32> %a1) {\n %srem0 = srem <4 x i32> %a1, %a0\n %srem1 = srem <4 x i32> splat (i32 1), %a0\n %r = shufflevector <4 x i32> %srem0, <4 x i32> %srem1, <4 x i32> <i32 0, i32 poison, i32 6, i32 3>\n ret <4 x i32> %r\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "VectorCombine transform leading to srem by poison", "body": "https://alive2.llvm.org/ce/z/HRAkAK\r\n\r\nthis:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0, <4 x i32> %1) {\r\n %3 = srem <4 x i32> %1, %0\r\n %4 = srem <4 x i32> <i32 1, i32 1, i32 1, i32 1>, %0\r\n %5 = shufflevector <4 x i32> %3, <4 x i32> %4, <4 x i32> <i32 0, i32 poison, i32 6, i32 3>\r\n ret <4 x i32> %5\r\n}\r\n```\r\nis getting vector-combined to this:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0, <4 x i32> %1) {\r\n %3 = shufflevector <4 x i32> %1, <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> <i32 0, i32 poison, i32 6, i32 3>\r\n %4 = shufflevector <4 x i32> %0, <4 x i32> poison, <4 x i32> <i32 0, i32 poison, i32 2, i32 3>\r\n %5 = srem <4 x i32> %3, %4\r\n ret <4 x i32> %5\r\n}\r\n```\r\n\r\nbut that poison in lane 1 is now problematic, this gives us full UB when it hits the srem\r\n\r\ncc @nunoplopes @hatsunespica\r\n", "author": "regehr", "labels": [ "miscompilation", "vectorizers" ], "comments": [ { "author": "RKSimon", "body": "I'll take a look at this" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": [ [ 164, 169 ], [ 178, 186 ] ], "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": [ "runMoveAutoInit" ], "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": [ [ 43, 49 ], [ 1297, 1303 ], [ 1329, 1336 ], [ 1534, 1541 ], [ 1818, 1824 ], [ 1863, 1869 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": [ "SCCPInstVisitor::handleCallResult", "SCCPInstVisitor::handleExtractOfWithOverflow", "SCCPInstVisitor::visitBinaryOperator", "SCCPInstVisitor::visitCastInst", "getConstantRange" ], "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
126012
https://github.com/llvm/llvm-project/issues/126012
miscompilation
52a02b6d1e0c6b492495ff79a3a06ce93e6180b8
2025-02-06T05:45:23
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "7aed53eb1982113e825534f0f66d0a0e46e7a5ed", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ [ 12400, 12405 ] ], "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::isImpliedViaMerge" ], "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 7aed53eb1982113e825534f0f66d0a0e46e7a5ed Author: Nikita Popov <[email protected]> Date: Mon Feb 10 10:07:21 2025 +0100 [ScalarEvolution] Handle addrec incoming value in isImpliedViaMerge() (#126236) The code already guards against values coming from a previous iteration using properlyDominates(). However, addrecs are considered to properly dominate the loop they are defined in. Handle this special case separately, by checking for expressions that have computable loop evolution (this should cover cases like a zext of an addrec as well). I considered changing the definition of properlyDominates() instead, but decided against it. The current definition is useful in other context, e.g. when deciding whether an expression is safe to expand in a given block. Fixes https://github.com/llvm/llvm-project/issues/126012. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index f89887118d8d..46a5c44f4e41 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -12400,6 +12400,12 @@ bool ScalarEvolution::isImpliedViaMerge(CmpPredicate Pred, const SCEV *LHS, // iteration of a loop. if (!properlyDominates(L, LBB)) return false; + // Addrecs are considered to properly dominate their loop, so are missed + // by the previous check. Discard any values that have computable + // evolution in this loop. + if (auto *Loop = LI.getLoopFor(LBB)) + if (hasComputableLoopEvolution(L, Loop)) + return false; if (!ProvedEasily(L, RHS)) return false; }
[ { "file": "llvm/test/Transforms/IndVarSimplify/pr126012.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test() {\nentry:\n br label %for.preheader\n\nfor.preheader: ; preds = %for.inc, %entry\n %indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]\n %indvar2 = phi i32 [ 1, %entry ], [ %indvar3, %for.inc ]\n %indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %cond1 = icmp eq i32 %indvar3, 0\n br i1 %cond1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.preheader\n %cmp = icmp sgt i32 %indvar2, 0\n %ext = zext i1 %cmp to i32\n br label %for.inc\n\nfor.inc: ; preds = %for.end, %for.preheader\n %phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]\n %inc = add i32 %indvar3, 1\n %exitcond = icmp eq i32 %indvar3, 2\n br i1 %exitcond, label %for.exit, label %for.preheader\n\nfor.exit: ; preds = %for.inc\n ret i32 %indvar1\n}\n", "lli_expected_out": null, "additional_args": "-src-unroll=4 -tgt-unroll=4" } ] } ]
{ "title": "[IndVarSimplify] Miscompilation at O2", "body": "Reproducer: https://alive2.llvm.org/ce/z/UTnMBe\n```\n; bin/opt -passes=indvars reduced.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n br label %for.cond1.preheader.i.i\n\nfor.cond1.preheader.i.i: ; preds = %for.inc18.i.i, %entry\n %.pre.i.i = phi i64 [ 0, %entry ], [ %1, %for.inc18.i.i ]\n %j.sroa.0.043.i.i = phi i64 [ 1, %entry ], [ %storemerge42.i.i, %for.inc18.i.i ]\n %storemerge42.i.i = phi i64 [ 0, %entry ], [ %inc22.i.i, %for.inc18.i.i ]\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i\n\nfor.end.i.i: ; preds = %for.cond1.preheader.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0\n %dec.348.i.i = add i64 %.pre.i.i, 1\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0\n br label %for.inc18.i.i\n\nfor.inc18.i.i: ; preds = %for.end.i.i, %for.cond1.preheader.i.i\n %1 = phi i64 [ %spec.select.i.i, %for.end.i.i ], [ 0, %for.cond1.preheader.i.i ]\n %inc22.i.i = add i64 %storemerge42.i.i, 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i\n\ng.exit: ; preds = %for.inc18.i.i\n %conv = trunc i64 %.pre.i.i to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)\n```\nBefore:\n```\nEntering function main\n br label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %j.sroa.0.043.i.i -> i64 1\n phi i64 %storemerge42.i.i -> i64 0\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> T\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 0\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %j.sroa.0.043.i.i -> i64 0\n phi i64 %storemerge42.i.i -> i64 1\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> F\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 1\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 0\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 0\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 2\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %j.sroa.0.043.i.i -> i64 1\n phi i64 %storemerge42.i.i -> i64 2\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 1\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 1\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 1\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 3\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 1\n phi i64 %j.sroa.0.043.i.i -> i64 2\n phi i64 %storemerge42.i.i -> i64 3\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 2\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 2\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 2\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 4\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 2\n phi i64 %j.sroa.0.043.i.i -> i64 3\n phi i64 %storemerge42.i.i -> i64 4\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 3\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 3\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 3\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 5\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 3\n phi i64 %j.sroa.0.043.i.i -> i64 4\n phi i64 %storemerge42.i.i -> i64 5\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 4\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 4\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 4\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 6\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 4\n phi i64 %j.sroa.0.043.i.i -> i64 5\n phi i64 %storemerge42.i.i -> i64 6\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 5\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 5\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 5\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 7\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 5\n phi i64 %j.sroa.0.043.i.i -> i64 6\n phi i64 %storemerge42.i.i -> i64 7\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 6\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 6\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 6\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 8\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 6\n phi i64 %j.sroa.0.043.i.i -> i64 7\n phi i64 %storemerge42.i.i -> i64 8\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 7\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 7\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 7\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 9\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 7\n phi i64 %j.sroa.0.043.i.i -> i64 8\n phi i64 %storemerge42.i.i -> i64 9\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %0 = icmp sgt i64 %j.sroa.0.043.i.i, 0 -> T\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 8\n %spec.select.i.i = select i1 %0, i64 %dec.348.i.i, i64 0 -> i64 8\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %1 -> i64 8\n %inc22.i.i = add i64 %storemerge42.i.i, 1 -> i64 10\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> T\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %g.exit\n %conv = trunc i64 %.pre.i.i to i32 -> i32 7\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n Printf: 7\n -> i32 2\n ret i32 0\nExiting function main\n```\nAfter:\n```\n; ModuleID = 'reduced.ll'\nsource_filename = \"reduced.ll\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n br label %for.cond1.preheader.i.i\n\nfor.cond1.preheader.i.i: ; preds = %for.inc18.i.i, %entry\n %.pre.i.i = phi i64 [ 0, %entry ], [ %0, %for.inc18.i.i ]\n %storemerge42.i.i = phi i64 [ 0, %entry ], [ %inc22.i.i, %for.inc18.i.i ]\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i\n\nfor.end.i.i: ; preds = %for.cond1.preheader.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0\n br label %for.inc18.i.i\n\nfor.inc18.i.i: ; preds = %for.end.i.i, %for.cond1.preheader.i.i\n %0 = phi i64 [ %spec.select.i.i, %for.end.i.i ], [ 0, %for.cond1.preheader.i.i ]\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i\n\ng.exit: ; preds = %for.inc18.i.i\n %.pre.i.i.lcssa = phi i64 [ %.pre.i.i, %for.inc18.i.i ]\n %conv = trunc i64 %.pre.i.i.lcssa to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)\n```\n```\nEntering function main\n br label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %storemerge42.i.i -> i64 0\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> T\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 0\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 1\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 0\n phi i64 %storemerge42.i.i -> i64 1\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 1\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 1\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 1\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 2\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 1\n phi i64 %storemerge42.i.i -> i64 2\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 2\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 2\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 2\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 3\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 2\n phi i64 %storemerge42.i.i -> i64 3\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 3\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 3\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 3\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 4\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 3\n phi i64 %storemerge42.i.i -> i64 4\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 4\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 4\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 4\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 5\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 4\n phi i64 %storemerge42.i.i -> i64 5\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 5\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 5\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 5\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 6\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 5\n phi i64 %storemerge42.i.i -> i64 6\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 6\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 6\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 6\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 7\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 6\n phi i64 %storemerge42.i.i -> i64 7\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 7\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 7\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 7\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 8\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 7\n phi i64 %storemerge42.i.i -> i64 8\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 8\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 8\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 8\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 9\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> F\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %for.cond1.preheader.i.i\n phi i64 %.pre.i.i -> i64 8\n phi i64 %storemerge42.i.i -> i64 9\n %tobool.not.i.i = icmp eq i64 %storemerge42.i.i, 0 -> F\n br i1 %tobool.not.i.i, label %for.inc18.i.i, label %for.end.i.i jump to %for.end.i.i\n %dec.348.i.i = add i64 %.pre.i.i, 1 -> i64 9\n %spec.select.i.i = select i1 true, i64 %dec.348.i.i, i64 0 -> i64 9\n br label %for.inc18.i.i jump to %for.inc18.i.i\n phi i64 %0 -> i64 9\n %inc22.i.i = add nuw nsw i64 %storemerge42.i.i, 1 -> i64 10\n %exitcond50.not.i.i = icmp eq i64 %storemerge42.i.i, 9 -> T\n br i1 %exitcond50.not.i.i, label %g.exit, label %for.cond1.preheader.i.i jump to %g.exit\n phi i64 %.pre.i.i.lcssa -> i64 8\n %conv = trunc i64 %.pre.i.i.lcssa to i32 -> i32 8\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n Printf: 8\n -> i32 2\n ret i32 0\nExiting function main\n```\nllvm version: 52fc6ffcda0895c0c7b976ad1f5cb5a282b571d2", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://alive2.llvm.org/ce/z/_x96gs\n```\n; bin/opt -passes=indvars reduced.ll -S --debug\ndefine i32 @src() {\nentry:\n br label %for.preheader\n\nfor.preheader:\n %indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]\n %indvar2 = phi i32 [ 1, %entry ], [ %indvar3, %for.inc ]\n %indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %cond1 = icmp eq i32 %indvar3, 0\n br i1 %cond1, label %for.inc, label %for.end\n\nfor.end:\n %cmp = icmp sgt i32 %indvar2, 0\n %ext = zext i1 %cmp to i32\n br label %for.inc\n\nfor.inc:\n %phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]\n %inc = add i32 %indvar3, 1\n %exitcond = icmp eq i32 %indvar3, 2\n br i1 %exitcond, label %for.exit, label %for.preheader\n\nfor.exit:\n ret i32 %indvar1\n}\n\n```\n```\nINDVARS: Eliminated comparison: %cmp = icmp sgt i32 %indvar2, 0\n\ndefine i32 @src() {\nentry:\n br label %for.preheader\n\nfor.preheader: ; preds = %for.inc, %entry\n %indvar1 = phi i32 [ 0, %entry ], [ %phi, %for.inc ]\n %indvar3 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %cond1 = icmp eq i32 %indvar3, 0\n br i1 %cond1, label %for.inc, label %for.end\n\nfor.end: ; preds = %for.preheader\n %ext = zext i1 true to i32\n br label %for.inc\n\nfor.inc: ; preds = %for.end, %for.preheader\n %phi = phi i32 [ %ext, %for.end ], [ 0, %for.preheader ]\n %inc = add nuw nsw i32 %indvar3, 1\n %exitcond = icmp eq i32 %indvar3, 2\n br i1 %exitcond, label %for.exit, label %for.preheader\n\nfor.exit: ; preds = %for.inc\n %indvar1.lcssa = phi i32 [ %indvar1, %for.inc ]\n ret i32 %indvar1.lcssa\n}\n```\n`ScalarEvolution::isImpliedViaMerge(sgt, %indvar2, 0, {0,+,1}<nuw><nsw><%for.preheader>(= %indvar3), 0)` wrongly returns true.\nI can't quite understand why `%indvar3` properly dominates `%for.preheader`: https://github.com/llvm/llvm-project/blob/26ecddb05d13c101ccd840a6710eb5f8b82de841/llvm/lib/Analysis/ScalarEvolution.cpp#L14131-L14141\n\n@nikic @fhahn Can you help fix this issue?\n\n\n" }, { "author": "nikic", "body": "Related previous fix: https://reviews.llvm.org/D101829" } ] }
true
null
107036
https://github.com/llvm/llvm-project/issues/107036
crash
70a19adbc60c738903bbbb8e6d5ef2d41b681089
2024-09-03T01:22:22
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "f381cd069965dabfeb277f30a4e532d7fd498f6e", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 16055, 16069 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::computeMinimumValueSizes" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit f381cd069965dabfeb277f30a4e532d7fd498f6e Author: Alexey Bataev <[email protected]> Date: Tue Sep 3 04:52:47 2024 -0700 [SLP]Fix PR107036: Check if the type of the user is sizable before requesting its size. Only some instructions should be considered as potentially reducing the size of the operands types, not all instructions should be considered. Fixes https://github.com/llvm/llvm-project/issues/107036 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 58137cd6f543..f58803fc56a2 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -16055,15 +16055,16 @@ void BoUpSLP::computeMinimumValueSizes() { const TreeEntry *UserTE = E.UserTreeIndices.back().UserTE; if (TE == UserTE || !TE) return false; + if (!isa<CastInst, BinaryOperator, FreezeInst, PHINode, + SelectInst>(U) || + !isa<CastInst, BinaryOperator, FreezeInst, PHINode, + SelectInst>(UserTE->getMainOp())) + return true; unsigned UserTESz = DL->getTypeSizeInBits( UserTE->Scalars.front()->getType()); 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/minbw-user-non-sizable.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s -slp-threshold=-100" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %i) {\nbb:\n %i1 = getelementptr i8, ptr %i, i64 4\n br label %bb2\n\nbb2: ; preds = %bb2, %bb\n %i3 = phi i32 [ %i6, %bb2 ], [ 0, %bb ]\n %i4 = phi i32 [ %i8, %bb2 ], [ 0, %bb ]\n store i32 %i3, ptr %i, align 4\n store i32 %i4, ptr %i1, align 4\n %i5 = trunc i32 0 to i1\n %i6 = select i1 %i5, i32 0, i32 0\n %i7 = trunc i32 %i4 to i1\n %i8 = select i1 %i7, i32 0, i32 0\n br label %bb2\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLP] Cannot getTypeInfo() on a type that is unsized!", "body": "I tried the following IR with SLP:\r\n\r\n```llvm\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @foo(ptr %i) {\r\nbb:\r\n %i1 = getelementptr i8, ptr %i, i64 4\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb2, %bb\r\n %i3 = phi i32 [ %i6, %bb2 ], [ 0, %bb ]\r\n %i4 = phi i32 [ %i8, %bb2 ], [ 0, %bb ]\r\n store i32 %i3, ptr %i\r\n store i32 %i4, ptr %i1\r\n %i5 = trunc i32 0 to i1\r\n %i6 = select i1 %i5, i32 0, i32 0\r\n %i7 = trunc i32 %i4 to i1\r\n %i8 = select i1 %i7, i32 0, i32 0\r\n br label %bb2\r\n}\r\n```\r\n\r\nIt failed with an error output:`Ty->isSized() && \"Cannot getTypeInfo() on a type that is unsized!\"' failed`. It's getting the size returned by the `store i32 %i4, ptr %i1` instruction.​\r\n\r\nhttps://llvm.godbolt.org/z/fMx9qMcfK\r\n\r\ncc f6e01b9ece1e73f6eda6e1dbff3aa72e917f4007 @alexey-bataev\r\n", "author": "DianQK", "labels": [ "release:backport", "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "https://github.com/llvm/llvm-project/blob/2cbd1bc830861bc08f78fb6cc11747b82f66c4c6/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp#L16067\r\n\r\n`U` is `store i32 %i4, ptr %i1`.\r\n" }, { "author": "DianQK", "body": "Reverting f6e01b9ece1e73f6eda6e1dbff3aa72e917f4007 seems reasonable to me. What do you think? @alexey-bataev ^^" }, { "author": "alexey-bataev", "body": "will fix it asap today" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6551, 6564 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInstructionCost" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
97475
https://github.com/llvm/llvm-project/issues/97475
miscompilation
b77e734e4e6c8f5e016ba3ac49526862e6039482
2024-07-02T20:25:03
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "3969d2c3b5f42e4a180f5205efa780b0f950d733", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 4049, 4055 ] ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "InstCombinerImpl::visitSelectInst" ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 3969d2c3b5f42e4a180f5205efa780b0f950d733 Author: Nikita Popov <[email protected]> Date: Wed Jul 3 09:47:01 2024 +0200 [InstCombine] Disable select known bits fold for vectors This is not safe if the simplification ends up looking through lane-crossing operations. For now, we don't have a good way to limit this in computeKnownBits(), so just disable vector handling entirely. Fixes https://github.com/llvm/llvm-project/issues/97475. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 736013395e8c..394dfca262e1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -4049,7 +4049,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { if (CondVal->getType() == SI.getType() && isKnownInversion(FalseVal, TrueVal)) return BinaryOperator::CreateXor(CondVal, FalseVal); - if (SelType->isIntOrIntVectorTy() && + // For vectors, this transform is only safe if the simplification does not + // look through any lane-crossing operations. For now, limit to scalars only. + if (SelType->isIntegerTy() && (!isa<Constant>(TrueVal) || !isa<Constant>(FalseVal))) { // Try to simplify select arms based on KnownBits implied by the condition. CondContext CC(CondVal);
[ { "file": "llvm/test/Transforms/InstCombine/select-binop-cmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "select_xor_icmp_vec_bad", "test_body": "define <2 x i8> @select_xor_icmp_vec_bad(<2 x i8> %x, <2 x i8> %y, <2 x i8> %z) {\n %A = icmp eq <2 x i8> %x, <i8 5, i8 3>\n %B = xor <2 x i8> %x, %z\n %C = select <2 x i1> %A, <2 x i8> %B, <2 x i8> %y\n ret <2 x i8> %C\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "vec_select_no_equivalence", "test_body": "define <2 x i32> @vec_select_no_equivalence(<2 x i32> %x) {\n %x10 = shufflevector <2 x i32> %x, <2 x i32> undef, <2 x i32> <i32 1, i32 0>\n %cond = icmp eq <2 x i32> %x, zeroinitializer\n %s = select <2 x i1> %cond, <2 x i32> %x10, <2 x i32> %x\n ret <2 x i32> %s\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "integer vector miscompile from instcombine", "body": "I believe this is being mis-optimized:\r\n```lllvm\r\ndefine <4 x i32> @f(<4 x i32> %0) {\r\n %2 = icmp eq <4 x i32> %0, zeroinitializer\r\n %3 = shufflevector <4 x i32> %0, <4 x i32> zeroinitializer, <4 x i32> <i32 1, i32 1, i32 0, i32 3>\r\n %4 = select <4 x i1> %2, <4 x i32> %3, <4 x i32> zeroinitializer\r\n ret <4 x i32> %4\r\n}\r\n```\r\nI'll just give Alive's reasoning, which is pretty easy to follow and seems correct:\r\n```\r\nregehr@ohm:~$ ~/alive2-regehr/build/alive-tv -passes=instcombine foo.ll\r\n\r\n----------------------------------------\r\ndefine <4 x i32> @f(<4 x i32> %#0) {\r\n#1:\r\n %#2 = icmp eq <4 x i32> %#0, { 0, 0, 0, 0 }\r\n %#3 = shufflevector <4 x i32> %#0, <4 x i32> { 0, 0, 0, 0 }, 1, 1, 0, 3\r\n %#4 = select <4 x i1> %#2, <4 x i32> %#3, <4 x i32> { 0, 0, 0, 0 }\r\n ret <4 x i32> %#4\r\n}\r\n=>\r\ndefine <4 x i32> @f(<4 x i32> %#0) {\r\n#1:\r\n ret <4 x i32> { 0, 0, 0, 0 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<4 x i32> %#0 = < #x00000000 (0), #x00000001 (1), #x00000000 (0), poison >\r\n\r\nSource:\r\n<4 x i1> %#2 = < #x1 (1), #x0 (0), #x1 (1), poison >\r\n<4 x i32> %#3 = < #x00000001 (1), #x00000001 (1), #x00000000 (0), poison >\r\n<4 x i32> %#4 = < #x00000001 (1), #x00000000 (0), #x00000000 (0), poison >\r\n\r\nTarget:\r\nSource value: < #x00000001 (1), #x00000000 (0), #x00000000 (0), poison >\r\nTarget value: < #x00000000 (0), #x00000000 (0), #x00000000 (0), #x00000000 (0) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\nregehr@ohm:~$ \r\n```\r\ncc @nunoplopes ", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "nikic", "body": "Probably caused by https://github.com/llvm/llvm-project/commit/77eb05683082dd3751ccfab963f5160f1852058d. Fell into the vector select trap again." } ] }
true
null
119063
https://github.com/llvm/llvm-project/issues/119063
crash
118f7b95c8546826f222c13daea47cde4aa97bc9
2024-12-07T08:46:55
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "f4f6566e44566f3d8cf9517767d457227125ca93", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 3622, 3628 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ "InstCombinerImpl::foldICmpBinOpEqualityWithConstant" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit f4f6566e44566f3d8cf9517767d457227125ca93 Author: Yingwei Zheng <[email protected]> Date: Sun Dec 8 13:21:34 2024 +0800 [InstCombine] Fix type mismatch in `foldICmpBinOpEqualityWithConstant` (#119068) Closes https://github.com/llvm/llvm-project/issues/119063. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index b694fde30927..54053c4c9e28 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3622,7 +3622,8 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant( m_OneUse(m_c_Or(m_CombineAnd(m_Value(Sel), m_Select(m_Value(Cond), m_Value(TV), m_Value(FV))), - m_Value(Other))))) { + m_Value(Other)))) && + Cond->getType() == Cmp.getType()) { const SimplifyQuery Q = SQ.getWithInstruction(&Cmp); // Easy case is if eq/ne matches whether 0 is trueval/falseval. if (Pred == ICmpInst::ICMP_EQ
[ { "file": "llvm/test/Transforms/InstCombine/icmp-or-of-select-with-zero.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "pr119063", "test_body": "define <4 x i1> @pr119063(<4 x i32> %x, i1 %cond) {\nentry:\n %sel = select i1 %cond, <4 x i32> splat (i32 1), <4 x i32> zeroinitializer\n %or = or <4 x i32> %sel, %x\n %cmp = icmp ne <4 x i32> %or, zeroinitializer\n ret <4 x i1> %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_tv_ne_invert", "test_body": "declare void @use.i8(i8)\n\ndeclare void @use.i1(i1)\n\ndefine i1 @src_tv_ne_invert(i1 %c1, i8 %a, i8 %b, i8 %x, i8 %yy) {\n %not_c0 = icmp ugt i8 %a, %b\n call void @use.i1(i1 %not_c0)\n %c0 = xor i1 %not_c0, true\n %y = add nuw i8 %yy, 1\n %sel = select i1 %c0, i8 0, i8 %y\n %cc = or i1 %c0, %c1\n %sel_other = select i1 %cc, i8 %y, i8 %b\n %selx = or i8 %sel, %x\n %r = icmp ne i8 %selx, 0\n call void @use.i8(i8 %sel)\n call void @use.i8(i8 %sel_other)\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Assertion `S1->getType() == S2->getType() && \"Cannot create binary operator with two operands of differing type!\"' failed.", "body": "This code crashes at O2/3:\n```c\nint a, b;\nstatic int c;\nstatic int *d = &c;\nshort e;\nchar g;\nunsigned short h;\nint *i;\nint j(int k) {\n if (k & a)\n return 1;\n return 0;\n}\nint l(int k) {\n int f = j(k);\n return f;\n}\nvoid n() { int *m[] = {0, &d}; }\nvoid o() {\n for (; g; g++) {\n int *p = &b;\n short *q = &e;\n int r = l(*d + 5);\n *p = 0;\n *q = *i || (unsigned short)(r + 22158 + 36566 + *d - 1641080165) + h;\n }\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/n7GPEKsxb\n\nBisected to https://github.com/llvm/llvm-project/commit/4eb98384099cbd1d901d8ef6a210af95d9c36adf, which was committed by @fhahn \n\nCrash: \n```\nclang: /root/llvm-project/llvm/lib/IR/Instructions.cpp:2642: static llvm::BinaryOperator* llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, const llvm::Twine&, llvm::InsertPosition): Assertion `S1->getType() == S2->getType() && \"Cannot create binary operator with two operands of differing type!\"' failed.\n```\n\nBacktrace:\n```\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 -Wall -Wextra <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 \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"o\"\n #0 0x0000000003c05148 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c05148)\n #1 0x0000000003c02e54 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c02e54)\n #2 0x0000000003b503b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007bfb65442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007bfb654969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007bfb65442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007bfb654287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007bfb6542871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007bfb65439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x000000000351a1f3 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x351a1f3)\n#10 0x0000000003523d7c (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3523d7c)\n#11 0x00000000037edc06 llvm::InstCombinerImpl::foldICmpBinOpEqualityWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x37edc06)\n#12 0x0000000003810ac9 llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3810ac9)\n#13 0x0000000003819aad llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3819aad)\n#14 0x0000000003775251 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3775251)\n#15 0x0000000003776bc6 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 0x000000000377805c llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x377805c)\n#17 0x0000000003ea39ae 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+0x3ea39ae)\n#18 0x00000000035b5920 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b5920)\n#19 0x00000000010f19ce 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+0x10f19ce)\n#20 0x00000000035b423b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b423b)\n#21 0x00000000010f105e 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+0x10f105e)\n#22 0x00000000035b3c40 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b3c40)\n#23 0x0000000003eb5912 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#24 0x0000000003eb918d 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+0x3eb918d)\n#25 0x00000000045875de clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45875de)\n#26 0x000000000654152c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x654152c)\n#27 0x00000000045879b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45879b8)\n#28 0x0000000004842b39 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4842b39)\n#29 0x00000000047c27ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47c27ce)\n#30 0x000000000492db9e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x492db9e)\n#31 0x0000000000cb21bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcb21bf)\n#32 0x0000000000ca9d5a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x00000000045cad09 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#34 0x0000000003b50864 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b50864)\n#35 0x00000000045cb2ff 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#36 0x000000000459149d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x459149d)\n#37 0x000000000459258d 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+0x459258d)\n#38 0x0000000004599945 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4599945)\n#39 0x0000000000caf003 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcaf003)\n#40 0x0000000000b82f64 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb82f64)\n#41 0x00007bfb65429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#42 0x00007bfb65429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#43 0x0000000000ca9805 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xca9805)\n```", "author": "cardigan1008", "labels": [ "llvm:instcombine", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/najxdPz5h\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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7780, 7785 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::canMapToVector" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
127534
https://github.com/llvm/llvm-project/issues/127534
crash
6de5d1e46d1812de2bbbbe8d8d2c811e4d16acbe
2025-02-17T18:29:15
[ "llvm/test/Transforms/LoopSimplifyCFG" ]
{ "fix_commit": "41437a6067b2f9dc8e7c458ff6417397796be31c", "components": [ "LoopSimplifyCFG" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": [ [ 369, 375 ] ], "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": [ "handleDeadExits" ], "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 41437a6067b2f9dc8e7c458ff6417397796be31c Author: Aleksandr Popov <[email protected]> Date: Fri Feb 21 12:26:39 2025 +0100 [LoopSimplifyCFG] Fix SCEV invalidation after removing dead exit (#127536) Fixes #127534 diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp index 765b76e54068..4524446e5947 100644 --- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -369,7 +369,7 @@ private: DeadInstructions.emplace_back(LandingPad); for (Instruction *I : DeadInstructions) { - SE.forgetBlockAndLoopDispositions(I); + SE.forgetValue(I); I->replaceAllUsesWith(PoisonValue::get(I->getType())); I->eraseFromParent(); }
[ { "file": "llvm/test/Transforms/LoopSimplifyCFG/pr117537.ll", "commands": [ "opt -S -passes='print<scalar-evolution>,loop-mssa(licm,loop-simplifycfg,loop-predication)' -verify-scev < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Make sure we don't assert due to insufficient SCEV invalidation.\n\ndefine i64 @\"main\"(ptr addrspace(1) %p, i1 %check) {\n;\nentry:\n br label %loop0.pre\n\nloop0.pre:\n br i1 %check, label %exit, label %loop0\n\nloop0:\n %length = load atomic i32, ptr addrspace(1) %p unordered, align 4\n %28 = icmp ugt i32 %length, 1\n br i1 %28, label %loop0.out, label %loop1.preheader\n\nloop0.out:\n %t = add i32 0, 1\n br i1 false, label %loop1.preheader, label %mid\n\nloop1.preheader:\n %length.lcssa = phi i32 [ %length, %loop0.out ], [ %length, %loop0 ]\n %local = phi i32 [ 0, %loop0 ], [ %t, %loop0.out ]\n br label %loop1\n\nloop1:\n %iv1 = phi i32 [ 4, %loop1.preheader ], [ %iv1.next, %loop1.guarded ]\n %82 = icmp ult i32 %iv1, %length.lcssa\n %wc = call i1 @llvm.experimental.widenable.condition()\n %guard.chk = and i1 %82, %wc\n br i1 %guard.chk, label %loop1.guarded, label %deopt-exit\n\nloop1.guarded:\n %iv1.next = add nuw nsw i32 %iv1, 1\n %chk = icmp ugt i32 %iv1, 310\n br i1 %chk, label %loop1.exit, label %loop1\n\ndeopt-exit:\n %100 = call i64 (...) @llvm.experimental.deoptimize.i64(i32 13) [ \"deopt\"() ]\n ret i64 %100\n\nloop1.exit:\n ret i64 0\n\nmid:\n br label %loop0.pre\n\nexit:\n ret i64 0\n}\n\ndeclare i64 @foo()\n\ndeclare i64 @llvm.experimental.deoptimize.i64(...)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite)\ndeclare noundef i1 @llvm.experimental.widenable.condition()", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SCEV] Assertion `isAvailableAtLoopEntry(RHS, L) && \"RHS is not available at Loop Entry\"' failed", "body": "During our local testing, we encountered the assertion failure `isAvailableAtLoopEntry(RHS, L) && \"RHS is not available at Loop Entry\".\n\nReduced reproducer:\n\n```llvm\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 @\"main\"(ptr addrspace(1) %p, i1 %check) {\nentry:\n br label %loop0.pre\n\nloop0.pre:\n br i1 %check, label %exit, label %loop0\n\nloop0:\n %length = load atomic i32, ptr addrspace(1) %p unordered, align 4\n %28 = icmp ugt i32 %length, 1\n br i1 %28, label %loop0.out, label %loop1.preheader\n\nloop0.out:\n %t = add i32 0, 1\n br i1 false, label %loop1.preheader, label %mid\n\nloop1.preheader:\n %length.lcssa = phi i32 [ %length, %loop0.out ], [ %length, %loop0 ]\n %local = phi i32 [ 0, %loop0 ], [ %t, %loop0.out ]\n br label %loop1\n\nloop1:\n %iv1 = phi i32 [ 4, %loop1.preheader ], [ %iv1.next, %loop1.guarded ]\n %82 = icmp ult i32 %iv1, %length.lcssa\n %wc = call i1 @llvm.experimental.widenable.condition()\n %guard.chk = and i1 %82, %wc\n br i1 %guard.chk, label %loop1.guarded, label %deopt-exit\n\nloop1.guarded:\n %iv1.next = add nuw nsw i32 %iv1, 1\n %chk = icmp ugt i32 %iv1, 310\n br i1 %chk, label %loop1.exit, label %loop1\n\ndeopt-exit:\n %100 = call i64 (...) @llvm.experimental.deoptimize.i64(i32 13) [ \"deopt\"() ]\n ret i64 %100\n\nloop1.exit:\n ret i64 0\n\nmid:\n br label %loop0.pre\n\nexit:\n ret i64 0\n}\n\ndeclare i64 @foo()\n\ndeclare i64 @llvm.experimental.deoptimize.i64(...)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite)\ndeclare noundef i1 @llvm.experimental.widenable.condition()\n```\n\n\nSteps to reproduce:\n`$opt -passes='print<scalar-evolution>,loop-mssa(licm,loop-simplifycfg,loop-predication)'`\n\nProof: https://godbolt.org/z/8hsbahTjq\n\nLooks like `LoopSimplifyCFGPass` is guilty - it doesn’t invalidate SCEV when removing a dead exit:\n\n```c++\n void handleDeadExits() {\n...\n for (Instruction *I : DeadInstructions) {\n SE.forgetBlockAndLoopDispositions(I);\n I->replaceAllUsesWith(PoisonValue::get(I->getType()));\n I->eraseFromParent();\n }\n```\n\n", "author": "aleks-tmb", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "aleks-tmb", "body": "The `LoopSimplifyCFG` pass removes `%length.lcssa.ph`, but later, in the `LoopPredication` pass, we encounter an assertion failure for the `%length.lcssa` SCEV, which remains equal to `%length`\n\n<img width=\"935\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/4d630238-569e-4d2b-b760-b09d54b4450f\" />\n\n![Image](https://github.com/user-attachments/assets/49481d3d-102c-42e1-8836-5c970461993d)" }, { "author": "aleks-tmb", "body": "It seems the reason why forgetBlockAndLoopDispositions doesn't cover this case is that `%length.lcssa.ph` doesn't have an existing SCEV, since the instruction was just added by the previous LICM pass." }, { "author": "nikic", "body": "There is some pretty tricky interaction between LCSSA formation and SCEV invalidation, see:\nhttps://github.com/llvm/llvm-project/blob/7f69a399df384c86428d0c97e3afbc8146324226/llvm/lib/Transforms/Utils/LCSSA.cpp#L206-L211\n\nBasically, when forming LCSSA form, we take care not to break the invalidation chain, so that invalidation of the LCSSA phi node is sufficient.\n\nI think the LICM predecessor splitting effectively does manual LCSSA formation and doesn't maintain this special logic.\n\nI think the extra forgetValue() call works around this issue and variants of this might appear elsewhere. But TBH I'm not totally sure." } ] }
true
null
80954
https://github.com/llvm/llvm-project/issues/80954
crash
e60c4b61f8bab25a137a481e4d2d3dbfa656807b
2024-02-07T08:19:15
[ "llvm/test/Transforms/LoopIdiom" ]
{ "fix_commit": "bec7181d5b9d1828129d78d440fd9e02d5cb63e8", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [ [ 795, 801 ] ], "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [ "SCEVExpander::expandIVInc" ], "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit bec7181d5b9d1828129d78d440fd9e02d5cb63e8 Author: Nikita Popov <[email protected]> Date: Wed Feb 7 11:06:51 2024 +0100 [SCEVExpander] Don't use recursive expansion for ptr IV inc Similar to the non-ptr case, directly create the getelementptr instruction. Going through expandAddToGEP() no longer makes sense with opaque pointers, where generating the necessary instruction is trivial. This avoids recursive expansion of (the SCEV of) StepV while the IR is in an inconsistent state, in particular with an incomplete IV phi node, which utilities may not be prepared to deal with. Fixes https://github.com/llvm/llvm-project/issues/80954. diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp index 58dbac0e85fb..3a28909473d9 100644 --- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp @@ -795,7 +795,8 @@ Value *SCEVExpander::expandIVInc(PHINode *PN, Value *StepV, const Loop *L, Value *IncV; // If the PHI is a pointer, use a GEP, otherwise use an add or sub. if (PN->getType()->isPointerTy()) { - IncV = expandAddToGEP(SE.getSCEV(StepV), PN); + // TODO: Change name to IVName.iv.next. + IncV = Builder.CreatePtrAdd(PN, StepV, "scevgep"); } else { IncV = useSubtract ? Builder.CreateSub(PN, StepV, Twine(IVName) + ".iv.next") :
[ { "file": "llvm/test/Transforms/LoopIdiom/pr80954.ll", "commands": [ "opt -S -passes=loop-idiom < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %p, i8 %arg, i64 %arg1, i32 %arg2) {\nentry:\n %sext = sext i8 %arg to i64\n %add = add i64 %arg1, -1\n br label %loop\n\nloop: ; preds = %latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %latch ]\n %phi = phi i32 [ %arg2, %entry ], [ %add9, %latch ]\n br label %loop2\n\nloop2: ; preds = %loop2, %loop\n %iv2 = phi i64 [ %iv2.next, %loop2 ], [ 0, %loop ]\n %gep = getelementptr [4 x i8], ptr %p, i64 %iv, i64 %iv2\n store i8 0, ptr %gep, align 1\n %iv2.next = add i64 %iv2, 1\n %icmp = icmp eq i64 %iv2.next, 0\n br i1 %icmp, label %latch, label %loop2\n\nlatch: ; preds = %loop2\n %add9 = add nsw i32 %phi, 1\n %sext10 = sext i32 %phi to i64\n %add11 = add i64 %add, %sext10\n %add12 = add i64 %add11, %sext\n %iv.next = add i64 %add12, %iv\n br label %loop\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "llvm crash: Assertion `Idx >= 0 && \"Invalid basic block argument!\"' failed.", "body": "llvm crashes in `loop-idiom` pass.\r\n\r\nBisected to 1c6e6432ca0b6832e06b93a4bcf22ead1899c14d, which was committed by @nikic \r\n\r\nCompiler explorer: https://godbolt.org/z/nxhnoE1Mb\r\n\r\n**% cat reduced.ll**\r\n```llvm\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\ndefine void @m(i8 %0, i64 %1, i32 %a.promoted) {\r\nentry:\r\n %conv13 = sext i8 %0 to i64\r\n %add14 = add i64 %1, -1\r\n br label %for.cond5thread-pre-split.lr.ph.split.us.us\r\n\r\nfor.cond5thread-pre-split.lr.ph.split.us.us: ; preds = %for.cond2.loopexit.us.us, %entry\r\n %inc.i1417.us = phi i32 [ %a.promoted, %entry ], [ %inc.i.us20, %for.cond2.loopexit.us.us ]\r\n %add161516.us = phi i64 [ 0, %entry ], [ %add16.us24, %for.cond2.loopexit.us.us ]\r\n br label %for.body7.us.us\r\n\r\nfor.body7.us.us: ; preds = %for.body7.us.us, %for.cond5thread-pre-split.lr.ph.split.us.us\r\n %2 = phi i64 [ %add9.us.us, %for.body7.us.us ], [ 0, %for.cond5thread-pre-split.lr.ph.split.us.us ]\r\n %arrayidx8.us.us = getelementptr [1 x [5 x i8]], ptr null, i64 0, i64 %add161516.us, i64 %2\r\n store i8 0, ptr %arrayidx8.us.us, align 1\r\n %add9.us.us = add i64 %2, 1\r\n %tobool6.not.us.us = icmp eq i64 %add9.us.us, 0\r\n br i1 %tobool6.not.us.us, label %for.cond2.loopexit.us.us, label %for.body7.us.us\r\n\r\nfor.cond2.loopexit.us.us: ; preds = %for.body7.us.us\r\n %inc.i.us20 = add nsw i32 %inc.i1417.us, 1\r\n %conv.i.us21 = sext i32 %inc.i1417.us to i64\r\n %add15.us22 = add i64 %add14, %conv.i.us21\r\n %sub.us23 = add i64 %add15.us22, %conv13\r\n %add16.us24 = add i64 %sub.us23, %add161516.us\r\n br label %for.cond5thread-pre-split.lr.ph.split.us.us\r\n}\r\n```\r\n\r\n**% opt -disable-output -passes=loop-idiom reduced.ll**\r\n```console\r\nopt: /tmp/tmpxmdtc3mt/tmpn8inmjh2/llvm/include/llvm/IR/Instructions.h:2910: llvm::Value* llvm::PHINode::getIncomingValueForBlock(const llvm::BasicBlock*) const: Assertion `Idx >= 0 && \"Invalid basic block argument!\"' 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-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt -disable-output -passes=loop-idiom reduced.ll\r\n #0 0x00007fc24b876eaf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x914eaf)\r\n #1 0x00007fc24b874414 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fc24ab77090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\r\n #3 0x00007fc24ab7700b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007fc24ab56859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007fc24ab56729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007fc24ab56729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007fc24ab67fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x00007fc24d68155f llvm::Loop::getCanonicalInductionVariable() const (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x271f55f)\r\n #9 0x00007fc24ca39df5 llvm::SCEVExpander::visitAddRecExpr(llvm::SCEVAddRecExpr const*) (.part.0) ScalarEvolutionExpander.cpp:0:0\r\n#10 0x00007fc24ca36745 llvm::SCEVVisitor<llvm::SCEVExpander, llvm::Value*>::visit(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad4745)\r\n#11 0x00007fc24ca3711b llvm::SCEVExpander::expand(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad511b)\r\n#12 0x00007fc24ca37380 llvm::SCEVExpander::expandCodeForImpl(llvm::SCEV const*, llvm::Type*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad5380)\r\n#13 0x00007fc24ca399ec llvm::SCEVExpander::expandAddToGEP(llvm::SCEV const*, llvm::Type*, llvm::Value*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad79ec)\r\n#14 0x00007fc24ca3ab97 llvm::SCEVExpander::expandIVInc(llvm::PHINode*, llvm::Value*, llvm::Loop const*, llvm::Type*, llvm::Type*, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad8b97)\r\n#15 0x00007fc24ca3bb6e llvm::SCEVExpander::getAddRecExprPHILiterally(llvm::SCEVAddRecExpr const*, llvm::Loop const*, llvm::Type*, llvm::Type*, llvm::Type*&, bool&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad9b6e)\r\n#16 0x00007fc24ca3c5d4 llvm::SCEVExpander::expandAddRecExprLiterally(llvm::SCEVAddRecExpr const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ada5d4)\r\n#17 0x00007fc24ca36745 llvm::SCEVVisitor<llvm::SCEVExpander, llvm::Value*>::visit(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad4745)\r\n#18 0x00007fc24ca3711b llvm::SCEVExpander::expand(llvm::SCEV const*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad511b)\r\n#19 0x00007fc24ca37380 llvm::SCEVExpander::expandCodeForImpl(llvm::SCEV const*, llvm::Type*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ad5380)\r\n#20 0x00007fc24ce4bc8c (anonymous namespace)::LoopIdiomRecognize::processLoopStridedStore(llvm::Value*, llvm::SCEV const*, llvm::MaybeAlign, llvm::Value*, llvm::Instruction*, llvm::SmallPtrSetImpl<llvm::Instruction*>&, llvm::SCEVAddRecExpr const*, llvm::SCEV const*, bool, bool) LoopIdiomRecognize.cpp:0:0\r\n#21 0x00007fc24ce539b7 (anonymous namespace)::LoopIdiomRecognize::processLoopStores(llvm::SmallVectorImpl<llvm::StoreInst*>&, llvm::SCEV const*, (anonymous namespace)::LoopIdiomRecognize::ForMemset) LoopIdiomRecognize.cpp:0:0\r\n#22 0x00007fc24ce5494c (anonymous namespace)::LoopIdiomRecognize::runOnCountableLoop() LoopIdiomRecognize.cpp:0:0\r\n#23 0x00007fc24ce561fd llvm::LoopIdiomRecognizePass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1ef41fd)\r\n#24 0x00007fc24e6ee6c6 llvm::detail::PassModel<llvm::Loop, llvm::LoopIdiomRecognizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x378c6c6)\r\n#25 0x00007fc24ce7544f 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&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f1344f)\r\n#26 0x00007fc24ce756f6 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&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f136f6)\r\n#27 0x00007fc24ce76b0d 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&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f14b0d)\r\n#28 0x00007fc24ce77d62 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x1f15d62)\r\n#29 0x00007fc24e6eb0c6 llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37890c6)\r\n#30 0x00007fc24ba8a40d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb2840d)\r\n#31 0x00007fc24e6e41a6 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-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x37821a6)\r\n#32 0x00007fc24ba88c9d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb26c9d)\r\n#33 0x00007fc24e6eb026 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-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0x3789026)\r\n#34 0x00007fc24ba86c1d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/../lib/libLLVM-18git.so+0xb24c1d)\r\n#35 0x000055608ac0cc95 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-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt+0x25c95)\r\n#36 0x000055608ac00876 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt+0x19876)\r\n#37 0x00007fc24ab58083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#38 0x000055608ac0151e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-1c6e6432ca0b6832e06b93a4bcf22ead1899c14d/bin/opt+0x1a51e)\r\n[1] 1629345 abort -disable-output -passes=loop-idiom reduced.ll\r\n```\r\n\r\nThe IR is reduced from the following C code:\r\n```C\r\nint a, b;\r\nlong d, h, j;\r\nshort e;\r\nchar f;\r\nstatic char *g = &f;\r\nstatic long *i = &d;\r\nchar k[1][5];\r\nlong l() {\r\n long c = a++;\r\n return c;\r\n}\r\nvoid m() {\r\n for (; b;)\r\n for (;; j = l() + *g + *i - 1 + j) {\r\n e = 0;\r\n for (; *i + e; e = 1)\r\n for (; h; h = h + 1)\r\n k[j][h] = 4;\r\n }\r\n}\r\nint main() {}\r\n```", "author": "shao-hua-li", "labels": [ "llvm:crash", "llvm:SCEV" ], "comments": [] }
true
null
79742
https://github.com/llvm/llvm-project/issues/79742
crash
a9689c6029e3078e09e43a4efb2b2ced98e9020f
2024-01-28T09:40:40
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "17fb3e82f6c950267bb01cc2fd2a84b0d9e9d0d8", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ [ 1031, 1037 ], [ 1040, 1047 ] ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [ "VPlanTransforms::truncateToMinimalBitwidths" ], "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 17fb3e82f6c950267bb01cc2fd2a84b0d9e9d0d8 Author: Florian Hahn <[email protected]> Date: Tue Apr 23 11:50:25 2024 +0100 [VPlan] Skip extending ICmp results in trunateToMinimalBitwidth. Results of icmp don't need extending after truncating their operands, as the result will always be i1. Skip them during extending. Fixes https://github.com/llvm/llvm-project/issues/79742 Fixes https://github.com/llvm/llvm-project/issues/85185 diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 007dc3f89b3f..9580dc4a27f6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1031,7 +1031,9 @@ void VPlanTransforms::truncateToMinimalBitwidths( if (auto *VPW = dyn_cast<VPRecipeWithIRFlags>(&R)) VPW->dropPoisonGeneratingFlags(); - if (OldResSizeInBits != NewResSizeInBits) { + using namespace llvm::VPlanPatternMatch; + if (OldResSizeInBits != NewResSizeInBits && + !match(&R, m_Binary<Instruction::ICmp>(m_VPValue(), m_VPValue()))) { // Extend result to original width. auto *Ext = new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy); @@ -1040,8 +1042,9 @@ void VPlanTransforms::truncateToMinimalBitwidths( Ext->setOperand(0, ResultVPV); assert(OldResSizeInBits > NewResSizeInBits && "Nothing to shrink?"); } else - assert(cast<VPWidenRecipe>(&R)->getOpcode() == Instruction::ICmp && - "Only ICmps should not need extending the result."); + assert( + match(&R, m_Binary<Instruction::ICmp>(m_VPValue(), m_VPValue())) && + "Only ICmps should not need extending the result."); assert(!isa<VPWidenStoreRecipe>(&R) && "stores cannot be narrowed"); if (isa<VPWidenLoadRecipe>(&R))
[ { "file": "llvm/test/Transforms/LoopVectorize/trunc-extended-icmps.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test_icmp_and_op_zext", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @test_icmp_and_op_zext(ptr %dst, i64 %a) {\nentry:\n %and = and i64 %a, 7304878031173690989\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %c = icmp ne i64 %and, 0\n %c.ext = zext i1 %c to i64\n %or = or i64 %and, %c.ext\n %or.trunc = trunc i64 %or to i8\n %gep = getelementptr i8, ptr %dst, i16 %iv\n store i8 %or.trunc, ptr %gep, align 1\n %iv.next = add i16 %iv, 1\n %ec = icmp eq i16 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "ext_cmp", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @ext_cmp(ptr %src.1, ptr %src.2, ptr noalias %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src.1 = getelementptr inbounds i16, ptr %src.1, i64 %iv\n %i2 = load i16, ptr %gep.src.1, align 2\n %i3 = sext i16 %i2 to i32\n %c.1 = icmp sgt i32 0, %i3\n %gep.src.2 = getelementptr inbounds i8, ptr %src.2, i64 %iv\n %i4 = load i8, ptr %gep.src.2, align 2\n %i5 = zext i8 %i4 to i32\n %i6 = select i1 %c.1, i32 0, i32 %i5\n %i7 = and i32 %i6, 0\n %i8 = trunc nuw nsw i32 %i7 to i16\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %i8, ptr %gep.dst, align 2\n %iv.next = add nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_constant_op_zext", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @test_icmp_constant_op_zext(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %c = icmp ne i64 7304878031173690989, 0\n %c.ext = zext i1 %c to i64\n %or = or i64 7304878031173690989, %c.ext\n %or.trunc = trunc i64 %or to i8\n %gep = getelementptr i8, ptr %dst, i16 %iv\n store i8 %or.trunc, ptr %gep, align 1\n %iv.next = add i16 %iv, 1\n %ec = icmp eq i16 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "llvm crash on loop-vectorize: Assertion `OldResSizeInBits > NewResSizeInBits && \"Nothing to shrink?\"' failed.", "body": "llvm crashes on the following IR.\r\n\r\nBisected to 822c749aec69ace75bd3923a4c850e2fd2e34fb1, which was committed by @fhahn \r\n\r\nCompiler explorer: https://godbolt.org/z/rWj9dhvPo\r\n\r\n```llvm\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\ndefine void @i(i64 %0) {\r\nentry:\r\n %conv = sext i16 1 to i32\r\n br label %for.body\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %1 = phi i32 [ 0, %entry ], [ %inc, %for.body ]\r\n %tobool.not.i = icmp eq i64 %0, 0\r\n %..i = select i1 %tobool.not.i, i32 0, i32 0\r\n %cmp = icmp eq i32 %..i, 0\r\n %conv1 = zext i1 %tobool.not.i to i32\r\n %or = or i32 %conv1, %conv\r\n %cmp2 = icmp slt i32 %or, 7\r\n %conv4 = zext i1 %cmp2 to i64\r\n store i64 %conv4, ptr null, align 8\r\n %inc = add i32 %1, 1\r\n %tobool.not = icmp eq i32 %inc, 0\r\n br i1 %tobool.not, label %for.cond.for.end_crit_edge, label %for.body\r\n\r\nfor.cond.for.end_crit_edge: ; preds = %for.body\r\n ret void\r\n}\r\n```\r\n\r\n```console\r\n% opt -passes=loop-vectorize reduced.ll\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-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt -disable-output -passes=loop-vectorize reduced.ll\r\n #0 0x00007f5302fedeff llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x902eff)\r\n #1 0x00007f5302feb654 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f5302300090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\r\n #3 0x00007f5304a458f0 llvm::InnerLoopVectorizer::truncateToMinimalBitwidths(llvm::VPTransformState&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x235a8f0)\r\n #4 0x00007f5304a49d95 llvm::InnerLoopVectorizer::fixVectorizedLoop(llvm::VPTransformState&, llvm::VPlan&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x235ed95)\r\n #5 0x00007f5304a4abb1 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*>>*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x235fbb1)\r\n #6 0x00007f5304a4d564 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x2362564)\r\n #7 0x00007f5304a4fbdd 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*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x2364bdd)\r\n #8 0x00007f5304a50e20 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x2365e20)\r\n #9 0x00007f5305e0d916 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x3722916)\r\n#10 0x00007f53031fd3fd llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0xb123fd)\r\n#11 0x00007f5305e069f6 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-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x371b9f6)\r\n#12 0x00007f53031fbc8d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0xb10c8d)\r\n#13 0x00007f5305e0d696 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-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0x3722696)\r\n#14 0x00007f53031f9c0d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/../lib/libLLVM-18git.so+0xb0ec0d)\r\n#15 0x0000555c5281fcb5 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-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt+0x25cb5)\r\n#16 0x0000555c52813876 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt+0x19876)\r\n#17 0x00007f53022e1083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#18 0x0000555c5281451e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-822c749aec69ace75bd3923a4c850e2fd2e34fb1/bin/opt+0x1a51e)\r\n[1] 1975861 segmentation fault -disable-output -passes=loop-vectorize reduced.ll\r\n```\r\n\r\n\r\nThis IR is reduced from \r\n```C\r\nlong a, b;\r\nint c, d, f;\r\nstatic long *e = &b;\r\nstatic short g = 5;\r\nint h() {\r\n if (a)\r\n return 0;\r\n return 5;\r\n}\r\nvoid i() {\r\n int j;\r\n long **k = &e;\r\n for (; d; d++) {\r\n j = h();\r\n *e = 6 >= (g | (j + c == 0));\r\n }\r\n j = &k || 1;\r\n short *l[6];\r\n l[f] = &g;\r\n}\r\nint main() {}\r\n```", "author": "shao-hua-li", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
116249
https://github.com/llvm/llvm-project/issues/116249
miscompilation
c1f6cb74634509d0e4204dadd46566185fa33e2b
2024-11-14T15:57:03
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "40a647fc7dc6048c92e2d580b61f5feca0785980", "components": [ "IndVarSimplify" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": [ [ 1530, 1535 ] ], "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": [ "IndVarSimplify::canonicalizeExitCondition" ], "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 40a647fc7dc6048c92e2d580b61f5feca0785980 Author: Yingwei Zheng <[email protected]> Date: Fri Nov 15 09:15:37 2024 +0800 [IndVarSimplify] Drop samesign flags after narrowing compares (#116263) Samesign flag cannot be preserved after narrowing the compare since the position of the sign bit is changed. Closes https://github.com/llvm/llvm-project/issues/116249. diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 2b2d516a7079..8a3e0bc3eb97 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -1530,6 +1530,8 @@ bool IndVarSimplify::canonicalizeExitCondition(Loop *L) { L->getLoopPreheader()->getTerminator()->getIterator()); ICmp->setOperand(Swapped ? 1 : 0, LHSOp); ICmp->setOperand(Swapped ? 0 : 1, NewRHS); + // Samesign flag cannot be preserved after narrowing the compare. + ICmp->setSameSign(false); if (LHS->use_empty()) DeadInsts.push_back(LHS); };
[ { "file": "llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll", "commands": [ "opt -passes=indvars -S < %s -indvars-predicate-loops=0" ], "tests": [ { "test_name": "test_drop_icmp_samesign", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i8 @test_drop_icmp_samesign(i1 %cond, i32 range(i32 0, 32) %x) {\nentry:\n br i1 %cond, label %for.body, label %else\n\nelse: ; preds = %entry\n %call1 = call i8 @callee()\n br label %exit\n\nfor.body: ; preds = %for.body, %entry\n %call2 = call i8 @callee()\n %ext = zext i8 %call2 to i32\n %cond2 = icmp samesign ugt i32 %x, %ext\n br i1 %cond2, label %for.body, label %exit\n\nexit: ; preds = %for.body, %else\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\n ret i8 %res\n}\n\ndeclare i8 @callee()\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[IndVarSimplify] samesign flag should be dropped after narrowing", "body": "Found with https://github.com/dtcxzyw/llvm-ub-aware-interpreter.\r\nReproducer: https://alive2.llvm.org/ce/z/fcnvLv\r\n```\r\n; bin/opt -passes=indvars test.ll -S\r\ndefine i8 @test(i1 %cond, i32 range(i32 0, 32) %x) {\r\nentry:\r\n br i1 %cond, label %for.body, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %ext = zext i8 %call2 to i32\r\n %cond2 = icmp samesign ugt i32 %x, %ext\r\n br i1 %cond2, label %for.body, label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\r\n ret i8 %res\r\n}\r\n```\r\n```\r\n\r\n----------------------------------------\r\ndeclare i8 @callee()\r\n\r\ndefine i8 @test(i1 %cond, i32 %x) {\r\ninit:\r\n %#range_0_%x = !range i32 %x, i32 0, i32 32\r\n br label %entry\r\n\r\nentry:\r\n br i1 %cond, label %for.body, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %ext = zext i8 %call2 to i32\r\n %cond2 = icmp samesign ugt i32 %#range_0_%x, %ext\r\n br i1 %cond2, label %for.body, label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2, %for.body ]\r\n ret i8 %res\r\n}\r\n=>\r\ndeclare i8 @callee()\r\n\r\ndefine i8 @test(i1 %cond, i32 %x) {\r\ninit:\r\n %#range_0_%x = !range i32 %x, i32 0, i32 32\r\n br label %entry\r\n\r\nentry:\r\n br i1 %cond, label %for.body.preheader, label %else\r\n\r\nelse:\r\n %call1 = call i8 @callee()\r\n br label %exit\r\n\r\nfor.body.preheader:\r\n %#0 = trunc i32 %#range_0_%x to i8\r\n br label %for.body\r\n\r\nfor.body:\r\n %call2 = call i8 @callee()\r\n %cond2 = icmp samesign ugt i8 %#0, %call2\r\n br i1 %cond2, label %for.body, label %exit.loopexit\r\n\r\nexit.loopexit:\r\n %call2.lcssa = phi i8 [ %call2, %for.body ]\r\n br label %exit\r\n\r\nexit:\r\n %res = phi i8 [ %call1, %else ], [ %call2.lcssa, %exit.loopexit ]\r\n ret i8 %res\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni1 %cond = #x1 (1)\r\ni32 %x = #x00000000 (0)\r\n\r\nSource:\r\ni32 %#range_0_%x = #x00000000 (0)\r\n >> Jump to %entry\r\n >> Jump to %for.body\r\ni8 %call2 = #x80 (128, -128)\r\ni32 %ext = #x00000080 (128)\r\ni1 %cond2 = #x0 (0)\r\n >> Jump to %exit\r\ni8 %res = #x80 (128, -128)\r\n\r\nSOURCE MEMORY STATE\r\n===================\r\nNON-LOCAL BLOCKS:\r\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\r\nBlock 1 >\tsize: 4\talign: 1\talloc type: 0\talive: true\taddress: 1\r\n\r\nTarget:\r\ni32 %#range_0_%x = #x00000000 (0)\r\n >> Jump to %entry\r\n >> Jump to %for.body.preheader\r\ni8 %#0 = #x00 (0)\r\n >> Jump to %for.body\r\ni8 %call2 = #x80 (128, -128)\r\ni1 %cond2 = poison\r\nUB triggered on br\r\n\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [] }
true
null
91127
https://github.com/llvm/llvm-project/issues/91127
miscompilation
30367cb5982dfdab2655401f020711311e7d78b9
2024-05-05T15:35:24
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "d3dad7a74be50d90754bf5c072e1a2330e92712c", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 1510, 1515 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ "InstCombinerImpl::foldICmpTruncWithTruncOrExt" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit d3dad7a74be50d90754bf5c072e1a2330e92712c Author: Yingwei Zheng <[email protected]> Date: Mon May 6 16:30:07 2024 +0800 [InstCombine] Fix miscompilation caused by #90436 (#91133) Proof: https://alive2.llvm.org/ce/z/iRnJ4i Fixes https://github.com/llvm/llvm-project/issues/91127. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index c60a290ce72e..7092fb5e509b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1510,6 +1510,7 @@ InstCombinerImpl::foldICmpTruncWithTruncOrExt(ICmpInst &Cmp, std::swap(X, Y); Pred = Cmp.getSwappedPredicate(Pred); } + YIsSExt = !(NoWrapFlags & TruncInst::NoUnsignedWrap); } // Try to match icmp (trunc nuw X), (zext Y) else if (!Cmp.isSigned() &&
[ { "file": "llvm/test/Transforms/InstCombine/icmp-of-trunc-ext.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "trunc_equality_both_sext", "test_body": "define i1 @trunc_equality_both_sext(i32 %x, i8 %y) {\n %xt = trunc nuw nsw i32 %x to i16\n %ye = sext i8 %y to i16\n %c = icmp ne i16 %xt, %ye\n ret i1 %c\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_slt_nuw", "test_body": "define i1 @test_slt_nuw(i32 %x, i16 %y) {\n %conv1 = trunc nuw nsw i32 %x to i8\n %conv2 = trunc nuw nsw i16 %y to i8\n %cond = icmp slt i8 %conv1, %conv2\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_slt", "test_body": "define i1 @test_slt(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp slt i8 %conv1, %conv2\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_ult_nuw", "test_body": "define i1 @test_ult_nuw(i32 %x, i16 %y) {\n %conv1 = trunc nuw nsw i32 %x to i8\n %conv2 = trunc nuw nsw i16 %y to i8\n %cond = icmp ult i8 %conv1, %conv2\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_ult", "test_body": "define i1 @test_ult(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp ult i8 %conv1, %conv2\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_eq1", "test_body": "define i1 @test_eq1(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp eq i8 %conv1, %conv2\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_eq2", "test_body": "define i1 @test_eq2(i32 %x, i16 %y) {\n %conv1 = trunc nsw i32 %x to i8\n %conv2 = trunc nsw i16 %y to i8\n %cond = icmp eq i8 %conv2, %conv1\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Miscompilation which converts `icmp eq (trunc nsw i64 X), (trunc nsw i32 Y)` into `icmp eq (zext i32 Y), X`", "body": "Reduced test case: https://alive2.llvm.org/ce/z/MLgA5x\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 @src() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %if.end, %entry\r\n %storemerge = phi i32 [ 3, %entry ], [ %dec, %if.end ]\r\n %h = phi i32 [ 1, %entry ], [ %hres, %if.end ]\r\n %e = phi i32 [ 0, %entry ], [ -1, %if.end ]\r\n %tobool.not = icmp eq i32 %storemerge, 0\r\n br i1 %tobool.not, label %for.end9, label %for.body\r\n\r\nfor.body: ; preds = %for.cond\r\n %cmp = icmp eq i32 %h, 5\r\n %conv1 = zext i1 %cmp to i64\r\n %conv2 = sext i32 %e to i64\r\n %cond.i = call i64 @llvm.umax.i64(i64 %conv1, i64 %conv2)\r\n %conv3 = trunc nsw i64 %cond.i to i16\r\n %conv4 = trunc nsw i32 %e to i16\r\n %sub.i = sub i16 %conv3, %conv4\r\n %tobool6.not = icmp eq i16 %sub.i, 0\r\n br i1 %tobool6.not, label %if.end, label %if.then\r\n\r\nif.then: ; preds = %for.body\r\n br label %if.end\r\n\r\nif.end: ; preds = %if.then, %for.body\r\n %hres = phi i32 [ 0, %if.then ], [ %h, %for.body ]\r\n %dec = add nsw i32 %storemerge, -1\r\n br label %for.cond\r\n\r\nfor.end9: ; preds = %for.cond\r\n ret i32 %h\r\n}\r\n\r\ndefine i32 @tgt() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %if.end, %entry\r\n %storemerge = phi i32 [ 3, %entry ], [ %dec, %if.end ]\r\n %h = phi i32 [ 1, %entry ], [ %hres, %if.end ]\r\n %e = phi i32 [ 0, %entry ], [ -1, %if.end ]\r\n %tobool.not = icmp eq i32 %storemerge, 0\r\n br i1 %tobool.not, label %for.end9, label %for.body\r\n\r\nfor.body: ; preds = %for.cond\r\n %cmp = icmp eq i32 %h, 5\r\n %conv1 = zext i1 %cmp to i64\r\n %conv2 = sext i32 %e to i64\r\n %cond.i = call i64 @llvm.umax.i64(i64 %conv1, i64 %conv2)\r\n %0 = zext i32 %e to i64\r\n %tobool6.not = icmp eq i64 %cond.i, %0\r\n br i1 %tobool6.not, label %if.end, label %if.then\r\n\r\nif.then: ; preds = %for.body\r\n br label %if.end\r\n\r\nif.end: ; preds = %if.then, %for.body\r\n %hres = phi i32 [ 0, %if.then ], [ %h, %for.body ]\r\n %dec = add nsw i32 %storemerge, -1\r\n br label %for.cond\r\n\r\nfor.end9: ; preds = %for.cond\r\n ret i32 %h\r\n}\r\n```\r\n\r\nllvm version: de9b386f84b58ad0ffc12e221bc6d9161ca5b62d", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced test case: https://alive2.llvm.org/ce/z/ndR8PQ\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 @src(i64 %x, i32 %y) {\r\n %conv1 = trunc nsw i64 %x to i16\r\n %conv2 = trunc nsw i32 %y to i16\r\n %cond = icmp eq i16 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n\r\ndefine i1 @tgt(i64 %x, i32 %y) {\r\n %1 = zext i32 %y to i64\r\n %cond = icmp eq i64 %1, %x\r\n ret i1 %cond\r\n}\r\n```\r\n\r\nIt should be caused by https://github.com/llvm/llvm-project/pull/90436.\r\n\r\nI will post a fix later. cc @nikic\r\n" }, { "author": "dtcxzyw", "body": "POC without DataLayout:\r\n```\r\ndefine i1 @test_eq(i32 %x, i16 %y) {\r\n %conv1 = trunc nsw i32 %x to i8\r\n %conv2 = trunc nsw i16 %y to i8\r\n %cond = icmp eq i8 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n\r\ndefine i1 @test_ult(i32 %x, i16 %y) {\r\n %conv1 = trunc nsw i32 %x to i8\r\n %conv2 = trunc nsw i16 %y to i8\r\n %cond = icmp ult i8 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n\r\ndefine i1 @test_slt(i32 %x, i16 %y) {\r\n %conv1 = trunc nsw i32 %x to i8\r\n %conv2 = trunc nsw i16 %y to i8\r\n %cond = icmp slt i8 %conv1, %conv2\r\n ret i1 %cond\r\n}\r\n```" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.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/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildExternalUses", "tryToReduce" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
116852
https://github.com/llvm/llvm-project/issues/116852
crash
d8a1c6d72739c99f4b52a84e907b96b685b44c5e
2024-11-19T18:03:10
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "79682c4d57620e623fb30271cc8003d0c9e14a01", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13614, 13620 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::gather" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 79682c4d57620e623fb30271cc8003d0c9e14a01 Author: Alexey Bataev <[email protected]> Date: Tue Nov 19 11:03:11 2024 -0800 [SLP]Check if the buildvector root is not a part of the graph before deletion If the buildvector root has no uses, it might be still needed as a part of the graph, so need to check that it is not a part of the graph before deletion. Fixes #116852 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index dc0dffd9fcbf..e70627b6afc1 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13614,7 +13614,10 @@ Value *BoUpSLP::gather( } else { Vec = CreateShuffle(Root, Vec, Mask); if (auto *OI = dyn_cast<Instruction>(OriginalRoot); - OI && OI->hasNUses(0)) + OI && OI->hasNUses(0) && + none_of(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) { + return TE->VectorizedValue == OI; + })) eraseInstruction(OI); } }
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/bv-root-part-of-graph.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nbb:\n br label %bb1\n\nbb1:\n %phi = phi i32 [ 0, %bb ], [ %or21, %bb1 ]\n %sitofp = sitofp i32 0 to float\n %fadd = fadd float %sitofp, %sitofp\n %fadd2 = fadd float %fadd, 0.000000e+00\n %fcmp = fcmp ogt float %fadd2, 0.000000e+00\n %select = select i1 %fcmp, i32 0, i32 0\n %select3 = select i1 false, i32 %select, i32 0\n %fadd4 = fadd float %sitofp, 0.000000e+00\n %fadd5 = fadd float %fadd4, 0.000000e+00\n %fcmp6 = fcmp ogt float %fadd5, 0.000000e+00\n %select7 = select i1 %fcmp6, i32 0, i32 0\n %select8 = select i1 false, i32 %select7, i32 0\n %or = or i32 %select3, %select8\n %sitofp9 = sitofp i32 0 to float\n %fmul = fmul float 0.000000e+00, 0.000000e+00\n %fadd10 = fadd float %sitofp9, %fmul\n %fadd11 = fadd float %fadd10, 0.000000e+00\n %fcmp12 = fcmp ogt float %fadd11, 0.000000e+00\n %select13 = select i1 %fcmp12, i32 0, i32 0\n %select14 = select i1 false, i32 %select13, i32 0\n %or15 = or i32 %select14, %or\n %fadd16 = fadd float %fmul, 0.000000e+00\n %fadd17 = fadd float %fadd16, 0.000000e+00\n %fcmp18 = fcmp ogt float %fadd17, 0.000000e+00\n %select19 = select i1 %fcmp18, i32 0, i32 0\n %select20 = select i1 false, i32 %select19, i32 0\n %or21 = or i32 %or15, %select20\n br label %bb1\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run the test below with -passes=slp-vectorizer\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 = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %or21, %bb1 ]\r\n %sitofp = sitofp i32 0 to float\r\n %fadd = fadd float %sitofp, %sitofp\r\n %fadd2 = fadd float %fadd, 0.000000e+00\r\n %fcmp = fcmp ogt float %fadd2, 0.000000e+00\r\n %select = select i1 %fcmp, i32 0, i32 0\r\n %select3 = select i1 false, i32 %select, i32 0\r\n %fadd4 = fadd float %sitofp, 0.000000e+00\r\n %fadd5 = fadd float %fadd4, 0.000000e+00\r\n %fcmp6 = fcmp ogt float %fadd5, 0.000000e+00\r\n %select7 = select i1 %fcmp6, i32 0, i32 0\r\n %select8 = select i1 false, i32 %select7, i32 0\r\n %or = or i32 %select3, %select8\r\n %sitofp9 = sitofp i32 0 to float\r\n %fmul = fmul float 0.000000e+00, 0.000000e+00\r\n %fadd10 = fadd float %sitofp9, %fmul\r\n %fadd11 = fadd float %fadd10, 0.000000e+00\r\n %fcmp12 = fcmp ogt float %fadd11, 0.000000e+00\r\n %select13 = select i1 %fcmp12, i32 0, i32 0\r\n %select14 = select i1 false, i32 %select13, i32 0\r\n %or15 = or i32 %select14, %or\r\n %fadd16 = fadd float %fmul, 0.000000e+00\r\n %fadd17 = fadd float %fadd16, 0.000000e+00\r\n %fcmp18 = fcmp ogt float %fadd17, 0.000000e+00\r\n %select19 = select i1 %fcmp18, i32 0, i32 0\r\n %select20 = select i1 false, i32 %select19, i32 0\r\n %or21 = or i32 %or15, %select20\r\n br label %bb1\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/T8j1xEoKM\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\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 0x00007eacdf842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007eacdf8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007eacdf842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007eacdf8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007eacdf82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007eacdf839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000419bb4f (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x419bb4f)\r\n #9 0x000000000425f0bf 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#10 0x000000000425fa7b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x425fa7b)\r\n#11 0x0000000002fbe41e 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+0x2fbe41e)\r\n#12 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#13 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#14 0x0000000004f9340e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f9340e)\r\n#15 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#16 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#17 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#18 0x00000000008fc70a optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fc70a)\r\n#19 0x00007eacdf829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x00007eacdf829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008f3e9e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f3e9e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
107015
https://github.com/llvm/llvm-project/issues/107015
crash
50a02e7c68f964c5d8338369746c849ed8d3bef4
2024-09-02T18:45:19
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "954ed05c1001489802ae43d4bea403181570a799", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 8393, 8398 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": [ [ 174, 184 ] ], "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "VPRecipeBuilder::tryToWiden" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": [ "getVPValueOrAddLiveIn" ], "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 954ed05c1001489802ae43d4bea403181570a799 Author: Florian Hahn <[email protected]> Date: Mon Sep 2 21:25:30 2024 +0100 [VPlan] Simplify MUL operands at recipe construction. This moves the logic to create simplified operands using SCEV to MUL recipe creation. This is needed to match the behavior of the legacy's cost model. TODOs are to extend to other opcodes and move to a transform. Note that this also restricts the number of SCEV simplifications we apply to more precisely match the cases handled by the legacy cost model. Fixes https://github.com/llvm/llvm-project/issues/107015. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index a8722db654f5..a64848c1fdce 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8393,6 +8393,20 @@ 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); + 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())); + } return new VPWidenRecipe(*I, make_range(Operands.begin(), Operands.end())); }; } diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h index 0fbdeeddaf4a..25b8bf3e089e 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -174,11 +174,6 @@ 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/AArch64/mul-simplification.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "mul_select_operand_known_1_via_scev", "test_body": "target triple = \"arm64-apple-macosx\"\n\ndefine i64 @mul_select_operand_known_1_via_scev() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %red = phi i64 [ 12, %entry ], [ %red.next, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = and i32 %iv, 1\n %cmp1.i = icmp eq i32 %0, 0\n %narrow.i = select i1 %cmp1.i, i32 1, i32 %iv\n %mul = zext nneg i32 %narrow.i to i64\n %red.next = mul nsw i64 %red, %mul\n %iv.next = add nuw nsw i32 %iv, 1\n %ec = icmp eq i32 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %res = phi i64 [ %red.next, %loop ]\n ret i64 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Crash with assertion failed in Vectorize", "body": "The compiler crashed with -O2 in this code:\r\n\r\n```c\r\n#include<stdint.h>\r\nstatic uint8_t b[][1] = {127};\r\nlong a(int c, int e) {\r\n long d;\r\n for (; c <= e; c++)\r\n if (c % 2 == 0)\r\n ;\r\n else\r\n d *= c;\r\n return d;\r\n}\r\nint64_t f();\r\nint16_t g() {\r\n int32_t h = 1653000360;\r\n f(a(h - 1653000360, b[0][0] - 126));\r\n uint8_t *i[] = {b, b};\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\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\n```\r\n\r\nThe details can be found here: https://godbolt.org/z/eeWW6raPb", "author": "cardigan1008", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
123639
https://github.com/llvm/llvm-project/issues/123639
miscompilation
5e4c34a9b67d9ce15d14f83bcea96ccb69de1eae
2025-01-20T16:05:11
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "7d01a8f2b9ac28ffe73bef4b513d383d3edf34b5", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13205, 13213 ], [ 14497, 14503 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledSingleRegisterEntry", "add" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 7d01a8f2b9ac28ffe73bef4b513d383d3edf34b5 Author: Alexey Bataev <[email protected]> Date: Mon Jan 20 14:22:20 2025 -0800 [SLP]Fix vector factor for repeated node for bv When adding a node vector, when it is used already in the shuffle for buildvector, need to calculate vector factor from all vector, not only this single vector, to avoid incorrect result. Also, need to increase stability of the reused entries detection to avoid mismatch in cost estimation/codegen. Fixes #123639 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index fc3afed391a0..ad4855d90874 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13205,9 +13205,12 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( VTE = *MIt; } } - Instruction &LastBundleInst = getLastInstructionInBundle(VTE); - if (&LastBundleInst == TEInsertPt || !CheckOrdering(&LastBundleInst)) - continue; + if (none_of(TE->CombinedEntriesWithIndices, + [&](const auto &P) { return P.first == VTE->Idx; })) { + Instruction &LastBundleInst = getLastInstructionInBundle(VTE); + if (&LastBundleInst == TEInsertPt || !CheckOrdering(&LastBundleInst)) + continue; + } VToTEs.insert(VTE); } if (VToTEs.empty()) @@ -14497,7 +14500,9 @@ public: break; } } - int VF = getVF(V1); + unsigned VF = 0; + for (Value *V : InVectors) + VF = std::max(VF, getVF(V)); for (unsigned Idx = 0, Sz = CommonMask.size(); Idx < Sz; ++Idx) if (Mask[Idx] != PoisonMaskElem && CommonMask[Idx] == PoisonMaskElem) CommonMask[Idx] = Mask[Idx] + (It == InVectors.begin() ? 0 : VF);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/multi-node-reuse-in-bv.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx2 < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @main() {\nentry:\n %.neg15 = sub i32 0, 0\n %0 = trunc i64 1 to i32\n %.neg.1 = sub i32 0, 0\n %.neg15.1 = sub i32 0, %0\n %.neg16.1 = add i32 %.neg.1, %.neg15.1\n %1 = add i32 %.neg16.1, %.neg15\n %2 = trunc i64 0 to i32\n %.neg.2 = sub i32 0, %0\n %.neg15.2 = sub i32 0, %2\n %.neg16.2 = add i32 %.neg.2, %.neg15.2\n %3 = add i32 %.neg16.2, %1\n %4 = trunc i64 0 to i32\n %.neg.3 = sub i32 0, %2\n %.neg15.3 = sub i32 0, %4\n %.neg16.3 = add i32 %.neg.3, %.neg15.3\n %5 = add i32 %.neg16.3, %3\n %6 = trunc i64 0 to i32\n %.neg.4 = sub i32 0, %4\n %.neg15.4 = sub i32 0, %6\n %.neg16.4 = add i32 %.neg.4, %.neg15.4\n %7 = add i32 %.neg16.4, %5\n %.neg.5 = sub i32 0, %6\n %.neg15.5 = sub i32 0, 0\n %.neg16.5 = add i32 %.neg.5, %.neg15.5\n %8 = add i32 %.neg16.5, %7\n %.neg15.6 = sub i32 0, 0\n %.neg16.6 = add i32 0, %.neg15.6\n %9 = add i32 %.neg16.6, %8\n %.neg.7 = sub i32 0, 0\n %.neg15.7 = sub i32 0, 0\n %.neg16.7 = add i32 %.neg.7, %.neg15.7\n %10 = add i32 %.neg16.7, %9\n %11 = trunc i64 0 to i32\n %.neg.8 = sub i32 0, 0\n %.neg15.8 = sub i32 0, %11\n %.neg16.8 = add i32 %.neg.8, %.neg15.8\n %12 = add i32 %.neg16.8, %10\n %13 = trunc i64 0 to i32\n %.neg.9 = sub i32 0, %11\n %.neg15.9 = sub i32 0, %13\n %.neg16.9 = add i32 %.neg.9, %.neg15.9\n %14 = add i32 %.neg16.9, %12\n %15 = trunc i64 0 to i32\n %.neg.10 = sub i32 0, %13\n %.neg15.10 = sub i32 0, %15\n %.neg16.10 = add i32 %.neg.10, %.neg15.10\n %16 = add i32 %.neg16.10, %14\n %17 = trunc i64 0 to i32\n %.neg.11 = sub i32 0, %15\n %.neg15.11 = sub i32 0, %17\n %.neg16.11 = add i32 %.neg.11, %.neg15.11\n %18 = add i32 %.neg16.11, %16\n %19 = trunc i64 0 to i32\n %.neg.12 = sub i32 0, %17\n %.neg15.12 = sub i32 0, %19\n %.neg16.12 = add i32 %.neg.12, %.neg15.12\n %20 = add i32 %.neg16.12, %18\n %.neg.13 = sub i32 0, %19\n %.neg15.13 = sub i32 0, 0\n %.neg16.13 = add i32 %.neg.13, %.neg15.13\n %21 = add i32 %.neg16.13, %20\n %.neg.14 = sub i32 0, 0\n %.neg15.14 = sub i32 0, 0\n %.neg16.14 = add i32 %.neg.14, %.neg15.14\n %22 = add i32 %.neg16.14, %21\n %.neg.15 = sub i32 0, 0\n %.neg15.15 = sub i32 0, 0\n %.neg16.15 = add i32 %.neg.15, %.neg15.15\n %23 = add i32 %.neg16.15, %22\n %.neg.16 = sub i32 0, 0\n %.neg15.16 = sub i32 0, 0\n %.neg16.16 = add i32 %.neg.16, %.neg15.16\n %24 = add i32 %.neg16.16, %23\n %res = xor i32 %24, -2\n ret i32 %res\n}\n", "lli_expected_out": "", "additional_args": null } ] } ]
{ "title": "SLP Vectorizer miscompilation", "body": "During our local testing, we identified a miscompilation where the SLP Vectorizer appears to be the cause. Here is the reproducer we managed to prepare:\nhttps://godbolt.org/z/9nePcq7Go\n\nThe issue can be demonstrated using the `lli` tool. Unfortunately, I cannot use alive2 due to unknown libcall errors, such as @llvm.vector.insert.v32i32.v16i32 not being recognized by alive2\n\n```\n$ bin/opt -passes=slp-vectorizer -mattr=+avx2 src.ll -S > tgt.ll\n$ bin/lli src.ll\nResult: -256\n$ bin/lli tgt.ll\nResult: -272\n```\n\nThe pseudocode represented by the IR is\n```\nt = 0\nfor (i = 0; i < 16; i++) {\n s -= (t + i)\n t = i\n}\n```\n```\ns -= (1 + 0) + (2 + 1) + (3 + 2) + (4 + 3) + ... + (14 + 15) + (15 + 16)\ns = -256\n```\nThis indicates that the SLP Vectorizer pass produces incorrect IR.\n\nThe issue became reproducible after patch `[SLP] Match poison as instruction with the same opcode` made by @alexey-bataev \nhttps://github.com/llvm/llvm-project/commit/b8703369daf777706196ff914c0376c27adde3cf\n\nI'll provide more details on how the patch affects the issue as soon as I receive them.", "author": "aleks-tmb", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [ { "author": "alexey-bataev", "body": "No related directly to this patch, reveals the bug that can be triggered even without patch. I reduced the reproducer, will commit fix soon" } ] }
true
null
119665
https://github.com/llvm/llvm-project/issues/119665
crash
7ae78a6cdb6ce9ad1534ed10519649fb3d47aca9
2024-12-12T07:13:14
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "3706dfef660097f24fb5efbac0d7f14b424492ed", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 2937, 2946 ], [ 2950, 2955 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "InnerLoopVectorizer::fixVectorizedLoop" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 3706dfef660097f24fb5efbac0d7f14b424492ed Author: Florian Hahn <[email protected]> Date: Mon Feb 10 16:29:42 2025 +0000 [LV] Forget LCSSA phi with new pred before other SCEV invalidation. (#119897) `forgetLcssaPhiWithNewPredecessor` performs additional invalidation if there is an existing SCEV for the phi, but earlier `forgetBlockAndLoopDispositions` or `forgetLoop` may already invalidate the SCEV for the phi. Change the order to first call `forgetLcssaPhiWithNewPredecessor` to ensure it runs before its SCEV gets invalidated too eagerly. Fixes https://github.com/llvm/llvm-project/issues/119665. PR: https://github.com/llvm/llvm-project/pull/119897 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 610e4904a80a..f2241be60ce0 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2937,10 +2937,6 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) { if (EnableVPlanNativePath) fixNonInductionPHIs(State); - // Forget the original basic block. - PSE.getSE()->forgetLoop(OrigLoop); - PSE.getSE()->forgetBlockAndLoopDispositions(); - // After vectorization, the exit blocks of the original loop will have // additional predecessors. Invalidate SCEVs for the exit phis in case SE // looked through single-entry phis. @@ -2950,6 +2946,10 @@ void InnerLoopVectorizer::fixVectorizedLoop(VPTransformState &State) { for (PHINode &PN : Exit->phis()) PSE.getSE()->forgetLcssaPhiWithNewPredecessor(OrigLoop, &PN); + // Forget the original basic block. + PSE.getSE()->forgetLoop(OrigLoop); + PSE.getSE()->forgetBlockAndLoopDispositions(); + // Don't apply optimizations below when no vector region remains, as they all // require a vector loop at the moment. if (!State.Plan->getVectorLoopRegion())
[ { "file": "llvm/test/Transforms/LoopVectorize/invalidate-scev-at-scope-after-vectorization.ll", "commands": [ "opt -passes='print<scalar-evolution>,loop-vectorize' -force-vector-width=4 -scalar-evolution-classify-expressions=false -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Test case for https://github.com/llvm/llvm-project/issues/119665.\n\n; %loop.2's backedge-taken-count depends on %add.1 from %loop.1 via its\n; corresponding SCEV at the scope of %loop.2. After vectorizing %loop.1, %add.1\n; isn't available at the entry of %loop.2 anymore and %add.1 at %loop.2's scope\n; must be invalidated, as well as %loop.2's backedge-taken count.\ndefine void @test_invalidate_scevs_at_scope(ptr %p) {\n;\nentry:\n br label %loop.1\n\nloop.1:\n %iv.1 = phi i32 [ 0, %entry ], [ %iv.1.next, %loop.1 ]\n %1 = load i32, ptr %p, align 4\n %add.1 = add i32 %1, %iv.1\n %iv.1.next = add i32 %iv.1, 1\n %c.1 = icmp eq i32 %iv.1, 100\n br i1 %c.1, label %exit.1, label %loop.1\n\nexit.1:\n %add.lcssa = phi i32 [ %add.1, %loop.1 ]\n br label %loop.2\n\nloop.2:\n %iv.2 = phi i64 [ 0, %exit.1 ], [ %iv.2.next, %loop.2 ]\n %iv.2.trunc = trunc i64 %iv.2 to i32\n %iv.2.next = add i64 %iv.2, 1\n %gep = getelementptr inbounds i64, ptr %p, i64 %iv.2\n store i64 %iv.2, ptr %gep\n %add.2 = add i32 %add.lcssa, %iv.2.trunc\n %c.2 = icmp slt i32 %add.2, 100\n br i1 %c.2, label %loop.2, label %exit.2\n\nexit.2:\n ret void\n}\n\n;.\n;.", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Crash at -O2: Assertion `isAvailableAtLoopEntry(LHS, L) && \"LHS is not available at Loop Entry\"' failed.", "body": "This code crashes at `-O2`: \n```c\nint a, e;\nint *b;\nshort c[];\nshort d;\nvoid f() {\n int g;\n for (;;)\n for (; a - 3 + g < 6; g = g + 1)\n c[g] = d;\n}\nvoid h();\nvoid i() {\n h();\n f();\n}\nvoid h() {\n e = 0;\n for (; e <= 50; ++e) {\n int *j = &a;\n *j = *b + e;\n }\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/jfo65eK9x\n\nCrash:\n```console\nclang: /root/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp:11744: bool llvm::ScalarEvolution::isLoopEntryGuardedByCond(const llvm::Loop*, llvm::CmpInst::Predicate, const llvm::SCEV*, const llvm::SCEV*): Assertion `isAvailableAtLoopEntry(LHS, L) && \"LHS is not available at Loop Entry\"' failed.\n```\nBacktrace:\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wall -Wextra -fno-strict-aliasing <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"i\"\n #0 0x0000000003c19758 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c19758)\n #1 0x0000000003c17464 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c17464)\n #2 0x0000000003b649c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x000079aa17242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x000079aa172969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x000079aa17242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x000079aa172287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x000079aa1722871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x000079aa17239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000000002c90a7b llvm::ScalarEvolution::isLoopEntryGuardedByCond(llvm::Loop const*, llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c90a7b)\n#10 0x0000000002ca6d97 llvm::ScalarEvolution::getTripCountFromExitCount(llvm::SCEV const*, llvm::Type*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2ca6d97)\n#11 0x00000000058449e4 llvm::VPlan::createInitialVPlan(llvm::Type*, llvm::PredicatedScalarEvolution&, bool, bool, llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58449e4)\n#12 0x000000000572a8ce llvm::LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(llvm::VFRange&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x572a8ce)\n#13 0x000000000572dd5a llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x572dd5a)\n#14 0x000000000572e24f llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x572e24f)\n#15 0x000000000573044f llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x573044f)\n#16 0x0000000005732a89 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5732a89)\n#17 0x00000000057330c3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57330c3)\n#18 0x0000000005283abe 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+0x5283abe)\n#19 0x00000000035c8550 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35c8550)\n#20 0x00000000010fa0ee 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+0x10fa0ee)\n#21 0x00000000035c6e6b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35c6e6b)\n#22 0x00000000010f977e 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+0x10f977e)\n#23 0x00000000035c6870 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35c6870)\n#24 0x0000000003eca382 (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 0x0000000003ecdbfd 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+0x3ecdbfd)\n#26 0x000000000459e07e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x459e07e)\n#27 0x000000000655704c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x655704c)\n#28 0x000000000459e458 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x459e458)\n#29 0x0000000004856fc9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4856fc9)\n#30 0x00000000047d989e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47d989e)\n#31 0x000000000494267e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x494267e)\n#32 0x0000000000cb92df cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcb92df)\n#33 0x0000000000cb0d7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#34 0x00000000045e2229 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#35 0x0000000003b64e74 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b64e74)\n#36 0x00000000045e281f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#37 0x00000000045a7f3d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45a7f3d)\n#38 0x00000000045a902d 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+0x45a902d)\n#39 0x00000000045b0565 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45b0565)\n#40 0x0000000000cb6123 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcb6123)\n#41 0x0000000000b84564 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb84564)\n#42 0x000079aa17229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#43 0x000079aa17229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#44 0x0000000000cb0825 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcb0825)\n```\n", "author": "cardigan1008", "labels": [ "release:backport", "vectorizers", "crash", "regression:18" ], "comments": [ { "author": "shafik", "body": "Looks like a clang-18 regression: https://godbolt.org/z/K7MMKxjzb" }, { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/s4G9Yb1vG\n```\n; bin/opt -passes=\"print<scalar-evolution>,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 void @i(ptr %p) {\nentry:\n br label %for.body.i\n\nfor.body.i: ; preds = %for.body.i, %entry\n %0 = phi i32 [ 0, %entry ], [ %inc.i, %for.body.i ]\n %1 = load i32, ptr %p, align 4\n %add.i = add i32 %1, %0\n %inc.i = add i32 %0, 1\n %exitcond.not.i = icmp eq i32 %0, 1\n br i1 %exitcond.not.i, label %for.cond.i.preheader, label %for.body.i\n\nfor.cond.i.preheader: ; preds = %for.body.i\n br label %for.cond.i\n\nfor.cond.i.loopexit: ; preds = %for.body.i1\n br label %for.cond.i\n\nfor.cond.i: ; preds = %for.cond.i.loopexit, %for.cond.i.preheader\n br label %for.body.i1\n\nfor.body.i1: ; preds = %for.body.i1, %for.cond.i\n %indvars.iv.i = phi i64 [ %indvars.iv.next.i, %for.body.i1 ], [ 0, %for.cond.i ]\n %indvars4.i = trunc i64 %indvars.iv.i to i32\n %indvars.iv.next.i = add i64 %indvars.iv.i, 1\n %add.reass.i = add i32 %add.i, %indvars4.i\n %cmp.i = icmp slt i32 %add.reass.i, 0\n br i1 %cmp.i, label %for.body.i1, label %for.cond.i.loopexit\n}\n\n```" }, { "author": "fhahn", "body": "Thanks, let me take a look" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 15975, 15980 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::computeMinimumValueSizes" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 3914, 3932 ], [ 9516, 9521 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::collectLoopUniforms", "VPReplicateRecipe::execute" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
112460
https://github.com/llvm/llvm-project/issues/112460
miscompilation
65cf7afb6d9d8c6137b90d909ee4fcf251439f48
2024-10-16T01:34:25
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e56e9dd8adca2e86f22783bf5e745ee1ba7ead5f", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 14953, 14958 ], [ 17095, 17100 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::collectValuesToDemote", "BoUpSLP::vectorizeTree" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit e56e9dd8adca2e86f22783bf5e745ee1ba7ead5f Author: Alexey Bataev <[email protected]> Date: Fri Oct 18 13:32:41 2024 -0700 [SLP]Fix minbitwidth emission and analysis for freeze instruction Need to add minbw emission and analysis for freeze instruction to fix incorrect signedness propagation. Fixes #112460 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 53632efe913e..e7b52fbdcc3b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14953,6 +14953,12 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { return E->VectorizedValue; } + if (Op->getType() != VecTy) { + assert((It != MinBWs.end() || getOperandEntry(E, 0)->isGather() || + MinBWs.contains(getOperandEntry(E, 0))) && + "Expected item in MinBWs."); + Op = Builder.CreateIntCast(Op, VecTy, GetOperandSignedness(0)); + } Value *V = Builder.CreateFreeze(Op); V = FinalShuffle(V, E); @@ -17095,6 +17101,8 @@ bool BoUpSLP::collectValuesToDemote( return TryProcessInstruction( BitWidth, {getOperandEntry(&E, 0), getOperandEntry(&E, 1)}); } + case Instruction::Freeze: + return TryProcessInstruction(BitWidth, getOperandEntry(&E, 0)); case Instruction::Shl: { // If we are truncating the result of this SHL, and if it's a shift of an // inrange amount, we can always perform a SHL in a smaller type.
[ { "file": "llvm/test/Transforms/SLPVectorizer/freeze-signedness-missed.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(i1 %.b, i8 %conv18, i32 %k.promoted61) {\n %not..b79 = xor i1 %.b, true\n %1 = zext i1 %not..b79 to i8\n %cmp.i51 = icmp eq i8 %1, 0\n %cond.i55 = freeze i8 %1\n %.cmp = icmp ugt i8 %cond.i55, %conv18\n %.urem = select i1 %.cmp, i8 0, i8 %cond.i55\n %2 = sub nuw i8 %conv18, %.urem\n %cond.in.i = select i1 %cmp.i51, i8 %conv18, i8 %2\n %not..b80 = xor i1 %.b, true\n %3 = zext i1 %not..b80 to i8\n %cmp.i51.1 = icmp eq i8 %3, 0\n %cond.i55.1 = freeze i8 %3\n %.cmp.1 = icmp ugt i8 %cond.i55.1, %conv18\n %.urem.1 = select i1 %.cmp.1, i8 0, i8 %cond.i55.1\n %4 = sub nuw i8 %conv18, %.urem.1\n %cond.in.i.1 = select i1 %cmp.i51.1, i8 %conv18, i8 %4\n %not..b81 = xor i1 %.b, true\n %5 = zext i1 %not..b81 to i8\n %cmp.i51.2 = icmp eq i8 %5, 0\n %cond.i55.2 = freeze i8 %5\n %.cmp.2 = icmp ugt i8 %cond.i55.2, %conv18\n %.urem.2 = select i1 %.cmp.2, i8 0, i8 %cond.i55.2\n %6 = sub nuw i8 %conv18, %.urem.2\n %cond.in.i.2 = select i1 %cmp.i51.2, i8 %conv18, i8 %6\n %not..b = xor i1 %.b, true\n %7 = zext i1 %not..b to i8\n %cmp.i51.3 = icmp eq i8 %7, 0\n %cond.i55.3 = freeze i8 %7\n %.cmp.3 = icmp ugt i8 %cond.i55.3, %conv18\n %.urem.3 = select i1 %.cmp.3, i8 0, i8 %cond.i55.3\n %8 = sub nuw i8 %conv18, %.urem.3\n %cond.in.i.3 = select i1 %cmp.i51.3, i8 %conv18, i8 %8\n %conv26 = zext nneg i8 %cond.in.i to i32\n %or = or i32 %k.promoted61, %conv26\n %conv26.1 = zext nneg i8 %cond.in.i.1 to i32\n %or.1 = or i32 %or, %conv26.1\n %conv26.2 = zext nneg i8 %cond.in.i.2 to i32\n %or.2 = or i32 %or.1, %conv26.2\n %conv26.3 = zext nneg i8 %cond.in.i.3 to i32\n %or.3 = or i32 %or.2, %conv26.3\n ret i32 %or.3\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Miscompilation at -O2", "body": "Reproducer: https://alive2.llvm.org/ce/z/Tw0oUm\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ndefine i32 @src(i1 %.b, i8 %conv18, i32 %k.promoted61) {\r\n %not..b79 = xor i1 %.b, true\r\n %3 = zext i1 %not..b79 to i8\r\n %cmp.i51 = icmp eq i8 %3, 0\r\n %cond.i55.frozen = freeze i8 %3\r\n %.cmp = icmp ugt i8 %cond.i55.frozen, %conv18\r\n %.urem = select i1 %.cmp, i8 0, i8 %cond.i55.frozen\r\n %4 = sub nuw i8 %conv18, %.urem\r\n %cond.in.i = select i1 %cmp.i51, i8 %conv18, i8 %4\r\n %not..b80 = xor i1 %.b, true\r\n %5 = zext i1 %not..b80 to i8\r\n %cmp.i51.1 = icmp eq i8 %5, 0\r\n %cond.i55.frozen.1 = freeze i8 %5\r\n %.cmp.1 = icmp ugt i8 %cond.i55.frozen.1, %conv18\r\n %.urem.1 = select i1 %.cmp.1, i8 0, i8 %cond.i55.frozen.1\r\n %6 = sub nuw i8 %conv18, %.urem.1\r\n %cond.in.i.1 = select i1 %cmp.i51.1, i8 %conv18, i8 %6\r\n %not..b81 = xor i1 %.b, true\r\n %7 = zext i1 %not..b81 to i8\r\n %cmp.i51.2 = icmp eq i8 %7, 0\r\n %cond.i55.frozen.2 = freeze i8 %7\r\n %.cmp.2 = icmp ugt i8 %cond.i55.frozen.2, %conv18\r\n %.urem.2 = select i1 %.cmp.2, i8 0, i8 %cond.i55.frozen.2\r\n %8 = sub nuw i8 %conv18, %.urem.2\r\n %cond.in.i.2 = select i1 %cmp.i51.2, i8 %conv18, i8 %8\r\n %not..b = xor i1 %.b, true\r\n %9 = zext i1 %not..b to i8\r\n %cmp.i51.3 = icmp eq i8 %9, 0\r\n %cond.i55.frozen.3 = freeze i8 %9\r\n %.cmp.3 = icmp ugt i8 %cond.i55.frozen.3, %conv18\r\n %.urem.3 = select i1 %.cmp.3, i8 0, i8 %cond.i55.frozen.3\r\n %10 = sub nuw i8 %conv18, %.urem.3\r\n %cond.in.i.3 = select i1 %cmp.i51.3, i8 %conv18, i8 %10\r\n %conv26 = zext nneg i8 %cond.in.i to i32\r\n %or = or i32 %k.promoted61, %conv26\r\n %conv26.1 = zext nneg i8 %cond.in.i.1 to i32\r\n %or.1 = or i32 %or, %conv26.1\r\n %conv26.2 = zext nneg i8 %cond.in.i.2 to i32\r\n %or.2 = or i32 %or.1, %conv26.2\r\n %conv26.3 = zext nneg i8 %cond.in.i.3 to i32\r\n %or.3 = or i32 %or.2, %conv26.3\r\n ret i32 %or.3\r\n}\r\n```\r\n```\r\ndefine i32 @src(i1 %.b, i8 %conv18, i32 %k.promoted61) {\r\n %1 = insertelement <4 x i1> poison, i1 %.b, i32 0\r\n %2 = shufflevector <4 x i1> %1, <4 x i1> poison, <4 x i32> zeroinitializer\r\n %3 = xor <4 x i1> %2, <i1 true, i1 true, i1 true, i1 true>\r\n %4 = zext <4 x i1> %3 to <4 x i8>\r\n %5 = icmp eq <4 x i8> %4, zeroinitializer\r\n %6 = freeze <4 x i1> %3\r\n %7 = sext <4 x i1> %6 to <4 x i8>\r\n %8 = insertelement <4 x i8> poison, i8 %conv18, i32 0\r\n %9 = shufflevector <4 x i8> %8, <4 x i8> poison, <4 x i32> zeroinitializer\r\n %10 = icmp ugt <4 x i8> %7, %9\r\n %11 = select <4 x i1> %10, <4 x i8> zeroinitializer, <4 x i8> %7\r\n %12 = sub nuw <4 x i8> %9, %11\r\n %13 = select <4 x i1> %5, <4 x i8> %9, <4 x i8> %12\r\n %14 = zext <4 x i8> %13 to <4 x i32>\r\n %15 = call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %14)\r\n %op.rdx = or i32 %15, %k.promoted61\r\n ret i32 %op.rdx\r\n}\r\n```\r\n```\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\ni1 %.b = #x0 (0)\r\ni8 %conv18 = #x01 (1)\r\ni32 %k.promoted61 = #x00000000 (0)\r\n\r\nSource:\r\ni1 %not..b79 = #x1 (1)\r\ni8 %#1 = #x01 (1)\r\ni1 %cmp.i51 = #x0 (0)\r\ni8 %cond.i55.frozen = #x01 (1)\r\ni1 %.cmp = #x0 (0)\r\ni8 %.urem = #x01 (1)\r\ni8 %#2 = #x00 (0)\r\ni8 %cond.in.i = #x00 (0)\r\ni1 %not..b80 = #x1 (1)\r\ni8 %#3 = #x01 (1)\r\ni1 %cmp.i51.1 = #x0 (0)\r\ni8 %cond.i55.frozen.1 = #x01 (1)\r\ni1 %.cmp.1 = #x0 (0)\r\ni8 %.urem.1 = #x01 (1)\r\ni8 %#4 = #x00 (0)\r\ni8 %cond.in.i.1 = #x00 (0)\r\ni1 %not..b81 = #x1 (1)\r\ni8 %#5 = #x01 (1)\r\ni1 %cmp.i51.2 = #x0 (0)\r\ni8 %cond.i55.frozen.2 = #x01 (1)\r\ni1 %.cmp.2 = #x0 (0)\r\ni8 %.urem.2 = #x01 (1)\r\ni8 %#6 = #x00 (0)\r\ni8 %cond.in.i.2 = #x00 (0)\r\ni1 %not..b = #x1 (1)\r\ni8 %#7 = #x01 (1)\r\ni1 %cmp.i51.3 = #x0 (0)\r\ni8 %cond.i55.frozen.3 = #x01 (1)\r\ni1 %.cmp.3 = #x0 (0)\r\ni8 %.urem.3 = #x01 (1)\r\ni8 %#8 = #x00 (0)\r\ni8 %cond.in.i.3 = #x00 (0)\r\ni32 %conv26 = #x00000000 (0)\r\ni32 %or = #x00000000 (0)\r\ni32 %conv26.1 = #x00000000 (0)\r\ni32 %or.1 = #x00000000 (0)\r\ni32 %conv26.2 = #x00000000 (0)\r\ni32 %or.2 = #x00000000 (0)\r\ni32 %conv26.3 = #x00000000 (0)\r\ni32 %or.3 = #x00000000 (0)\r\n\r\nTarget:\r\n<4 x i1> %#1 = < #x0 (0), poison, poison, poison >\r\n<4 x i1> %#2 = < #x0 (0), #x0 (0), #x0 (0), #x0 (0) >\r\n<4 x i1> %#3 = < #x1 (1), #x1 (1), #x1 (1), #x1 (1) >\r\n<4 x i8> %#4 = < #x01 (1), #x01 (1), #x01 (1), #x01 (1) >\r\n<4 x i1> %#5 = < #x0 (0), #x0 (0), #x0 (0), #x0 (0) >\r\n<4 x i1> %#6 = < #x1 (1), #x1 (1), #x1 (1), #x1 (1) >\r\n<4 x i8> %#7 = < #xff (255, -1), #xff (255, -1), #xff (255, -1), #xff (255, -1) >\r\n<4 x i8> %#8 = < #x01 (1), poison, poison, poison >\r\n<4 x i8> %#9 = < #x01 (1), #x01 (1), #x01 (1), #x01 (1) >\r\n<4 x i1> %#10 = < #x1 (1), #x1 (1), #x1 (1), #x1 (1) >\r\n<4 x i8> %#11 = < #x00 (0), #x00 (0), #x00 (0), #x00 (0) >\r\n<4 x i8> %#12 = < #x01 (1), #x01 (1), #x01 (1), #x01 (1) >\r\n<4 x i8> %#13 = < #x01 (1), #x01 (1), #x01 (1), #x01 (1) >\r\n<4 x i32> %#14 = < #x00000001 (1), #x00000001 (1), #x00000001 (1), #x00000001 (1) >\r\ni32 %#15 = #x00000001 (1)\r\ni32 %op.rdx = #x00000001 (1)\r\nSource value: #x00000000 (0)\r\nTarget value: #x00000001 (1)\r\n```\r\n\r\nllvm version: 69f7758ddba662b63667507f2c472c008909dd7e\r\ncc @alexey-bataev ", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [] }
true
null
113810
https://github.com/llvm/llvm-project/issues/113810
crash
ce0368eb8417f2d369499bb98b1f0ccbe2219598
2024-10-27T14:16:44
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "7152bf3bc805b8d9b1873058ab0a084d7b6079d6", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7947, 7954 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 7152bf3bc805b8d9b1873058ab0a084d7b6079d6 Author: Alexey Bataev <[email protected]> Date: Mon Oct 28 06:37:24 2024 -0700 [SLP]Do not create new vector node if scalars fully overlap with the existing one If the list of scalars vectorized as the part of the same vector node, no need to generate vector node again, it will be handled as part of overlapping matching. Fixes #113810 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 2afd02dae3a8..268546fe99e1 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7947,8 +7947,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, Nodes.insert(E); SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end()); if (any_of(Nodes, [&](const TreeEntry *E) { - return all_of(E->Scalars, - [&](Value *V) { return Values.contains(V); }); + if (all_of(E->Scalars, + [&](Value *V) { return Values.contains(V); })) + return true; + SmallPtrSet<Value *, 8> EValues(E->Scalars.begin(), + E->Scalars.end()); + return ( + all_of(VL, [&](Value *V) { return EValues.contains(V); })); })) { LLVM_DEBUG(dbgs() << "SLP: Gathering due to full overlap.\n"); if (TryToFindDuplicates(S))
[ { "file": "llvm/test/Transforms/SLPVectorizer/full-overlap-non-schedulable.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %p1, ptr %0, i32 %1, i1 %c1, ptr %p2) {\ntop:\n %2 = getelementptr i8, ptr %0, i64 8\n %3 = getelementptr i8, ptr %0, i64 12\n %4 = getelementptr i8, ptr %0, i64 16\n %5 = getelementptr i8, ptr %0, i64 20\n br i1 %c1, label %L42, label %L41\n\nL41: ; preds = %top\n %.not276 = icmp eq ptr %2, null\n %6 = load i32, ptr %2, align 4\n %7 = select i1 %.not276, i32 0, i32 %6\n %.not277 = icmp eq ptr %3, null\n %8 = load i32, ptr %3, align 4\n %9 = select i1 %.not277, i32 0, i32 %8\n %.not278 = icmp eq ptr %4, null\n %10 = load i32, ptr %4, align 4\n %11 = select i1 %.not278, i32 0, i32 %10\n %.not279 = icmp eq ptr %5, null\n %12 = load i32, ptr %5, align 4\n %13 = select i1 %.not279, i32 0, i32 %12\n br label %L112\n\nL42: ; preds = %top\n %14 = load i32, ptr %2, align 4\n %.not280 = icmp eq i32 %14, 0\n br i1 %.not280, label %L112, label %L47\n\nL47: ; preds = %L42\n %15 = load i32, ptr %3, align 4\n %.not282 = icmp eq ptr %4, null\n %16 = load i32, ptr %4, align 4\n %17 = select i1 %.not282, i32 0, i32 %16\n %.not283 = icmp eq ptr %5, null\n %18 = load i32, ptr %5, align 4\n %19 = select i1 %.not283, i32 0, i32 %18\n br label %L112\n\nL112: ; preds = %L47, %L42, %L41\n %value_phi13336 = phi i32 [ %19, %L47 ], [ %13, %L41 ], [ 0, %L42 ]\n %value_phi12335 = phi i32 [ %17, %L47 ], [ %11, %L41 ], [ %1, %L42 ]\n %value_phi11334 = phi i32 [ %15, %L47 ], [ %9, %L41 ], [ 0, %L42 ]\n %value_phi10333 = phi i32 [ 0, %L47 ], [ %7, %L41 ], [ 0, %L42 ]\n store i32 %value_phi10333, ptr %p2, align 4\n store i32 %value_phi11334, ptr %p1, align 4\n store i32 %value_phi12335, ptr %p2, align 4\n store i32 %value_phi13336, ptr %p1, align 4\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "SLPVectorizer miscompilation", "body": "This IR\r\n```llvm\r\n; Function Attrs: alignstack(16)\r\ndefine swiftcc { ptr addrspace(10), i8 } @julia__zip_iterate_all_17381(ptr noalias nocapture noundef nonnull align 4 dereferenceable(96) %union_bytes_return, ptr nonnull swiftself %pgcstack_arg, ptr addrspace(11) nocapture noundef nonnull readonly align 4 dereferenceable(48) %0, ptr addrspace(11) nocapture noundef nonnull readonly align 4 dereferenceable(48) %1) #0 {\r\ntop:\r\n %pgcstack = call ptr @julia.get_pgcstack()\r\n %ptls_field = getelementptr inbounds i8, ptr %pgcstack, i32 8\r\n %ptls_load = load ptr, ptr %ptls_field, align 4\r\n %2 = getelementptr inbounds i8, ptr %ptls_load, i32 16\r\n %safepoint = load ptr, ptr %2, align 4\r\n fence syncscope(\"singlethread\") seq_cst\r\n call void @julia.safepoint(ptr %safepoint)\r\n fence syncscope(\"singlethread\") seq_cst\r\n %3 = load i32, ptr addrspace(11) %1, align 4\r\n %4 = load i32, ptr addrspace(11) %0, align 4\r\n %.not = icmp eq i32 %3, %4\r\n br i1 %.not, label %L26, label %L20\r\n\r\nL20: ; preds = %top\r\n %5 = add i32 %3, 1\r\n %6 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 4\r\n %7 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 8\r\n %8 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 12\r\n %9 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 16\r\n %10 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 20\r\n %.not265 = icmp eq ptr addrspace(11) %6, null\r\n %11 = load i32, ptr addrspace(11) %6, align 4\r\n %12 = select i1 %.not265, i32 undef, i32 %11\r\n %.not266 = icmp eq ptr addrspace(11) %7, null\r\n %13 = load i32, ptr addrspace(11) %7, align 4\r\n %14 = select i1 %.not266, i32 undef, i32 %13\r\n %.not267 = icmp eq ptr addrspace(11) %8, null\r\n %15 = load i32, ptr addrspace(11) %8, align 4\r\n %16 = select i1 %.not267, i32 undef, i32 %15\r\n %.not268 = icmp eq ptr addrspace(11) %9, null\r\n %17 = load i32, ptr addrspace(11) %9, align 4\r\n %18 = select i1 %.not268, i32 undef, i32 %17\r\n %.not269 = icmp eq ptr addrspace(11) %10, null\r\n %19 = load i32, ptr addrspace(11) %10, align 4\r\n %20 = select i1 %.not269, i32 undef, i32 %19\r\n br label %L112\r\n\r\nL26: ; preds = %top\r\n %21 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 4\r\n %22 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 8\r\n %23 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 12\r\n %24 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 16\r\n %25 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 20\r\n %26 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 4\r\n %27 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 12\r\n %28 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 16\r\n %29 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 20\r\n %30 = load i32, ptr addrspace(11) %21, align 4\r\n %31 = load i32, ptr addrspace(11) %26, align 4\r\n %.not275 = icmp eq i32 %30, %31\r\n br i1 %.not275, label %L42, label %L41\r\n\r\nL41: ; preds = %L26\r\n %32 = add i32 %30, 1\r\n %.not276 = icmp eq ptr addrspace(11) %22, null\r\n %33 = load i32, ptr addrspace(11) %22, align 4\r\n %34 = select i1 %.not276, i32 undef, i32 %33\r\n %.not277 = icmp eq ptr addrspace(11) %23, null\r\n %35 = load i32, ptr addrspace(11) %23, align 4\r\n %36 = select i1 %.not277, i32 undef, i32 %35\r\n %.not278 = icmp eq ptr addrspace(11) %24, null\r\n %37 = load i32, ptr addrspace(11) %24, align 4\r\n %38 = select i1 %.not278, i32 undef, i32 %37\r\n %.not279 = icmp eq ptr addrspace(11) %25, null\r\n %39 = load i32, ptr addrspace(11) %25, align 4\r\n %40 = select i1 %.not279, i32 undef, i32 %39\r\n br label %L112\r\n\r\nL42: ; preds = %L26\r\n %41 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 8\r\n %42 = load i32, ptr addrspace(11) %22, align 4\r\n %43 = load i32, ptr addrspace(11) %41, align 4\r\n %.not280 = icmp eq i32 %42, %43\r\n br i1 %.not280, label %L48, label %L47\r\n\r\nL47: ; preds = %L42\r\n %44 = add i32 %42, 1\r\n %.not281 = icmp eq ptr addrspace(11) %23, null\r\n %45 = load i32, ptr addrspace(11) %23, align 4\r\n %46 = select i1 %.not281, i32 undef, i32 %45\r\n %.not282 = icmp eq ptr addrspace(11) %24, null\r\n %47 = load i32, ptr addrspace(11) %24, align 4\r\n %48 = select i1 %.not282, i32 undef, i32 %47\r\n %.not283 = icmp eq ptr addrspace(11) %25, null\r\n %49 = load i32, ptr addrspace(11) %25, align 4\r\n %50 = select i1 %.not283, i32 undef, i32 %49\r\n br label %L112\r\n\r\nL48: ; preds = %L42\r\n %51 = load i32, ptr addrspace(11) %23, align 4\r\n %52 = load i32, ptr addrspace(11) %27, align 4\r\n %.not284 = icmp eq i32 %51, %52\r\n br i1 %.not284, label %L54, label %L53\r\n\r\nL53: ; preds = %L48\r\n %53 = add i32 %51, 1\r\n %.not285 = icmp eq ptr addrspace(11) %24, null\r\n %54 = load i32, ptr addrspace(11) %24, align 4\r\n %55 = select i1 %.not285, i32 undef, i32 %54\r\n %.not286 = icmp eq ptr addrspace(11) %25, null\r\n %56 = load i32, ptr addrspace(11) %25, align 4\r\n %57 = select i1 %.not286, i32 undef, i32 %56\r\n br label %L112\r\n\r\nL54: ; preds = %L48\r\n %58 = load i32, ptr addrspace(11) %24, align 4\r\n %59 = load i32, ptr addrspace(11) %28, align 4\r\n %.not287 = icmp eq i32 %58, %59\r\n br i1 %.not287, label %L87, label %L59\r\n\r\nL59: ; preds = %L54\r\n %60 = add i32 %58, 1\r\n %.not288 = icmp eq ptr addrspace(11) %25, null\r\n %61 = load i32, ptr addrspace(11) %25, align 4\r\n %62 = select i1 %.not288, i32 undef, i32 %61\r\n br label %L112\r\n\r\nL87: ; preds = %L54\r\n %63 = load i32, ptr addrspace(11) %25, align 4\r\n %64 = add i32 %63, 1\r\n %65 = load i32, ptr addrspace(11) %29, align 4\r\n %66 = icmp eq i32 %63, %65\r\n br i1 %66, label %common.ret, label %L112\r\n\r\nL112: ; preds = %L87, %L20, %L41, %L47, %L53, %L59\r\n %value_phi13336 = phi i32 [ %64, %L87 ], [ %62, %L59 ], [ %57, %L53 ], [ %50, %L47 ], [ %40, %L41 ], [ %20, %L20 ]\r\n %value_phi12335 = phi i32 [ 1, %L87 ], [ %60, %L59 ], [ %55, %L53 ], [ %48, %L47 ], [ %38, %L41 ], [ %18, %L20 ]\r\n %value_phi11334 = phi i32 [ 1, %L87 ], [ 1, %L59 ], [ %53, %L53 ], [ %46, %L47 ], [ %36, %L41 ], [ %16, %L20 ]\r\n %value_phi10333 = phi i32 [ 1, %L87 ], [ 1, %L59 ], [ 1, %L53 ], [ %44, %L47 ], [ %34, %L41 ], [ %14, %L20 ]\r\n %value_phi9332 = phi i32 [ 1, %L87 ], [ 1, %L59 ], [ 1, %L53 ], [ 1, %L47 ], [ %32, %L41 ], [ %12, %L20 ]\r\n %value_phi2326 = phi i32 [ 1, %L87 ], [ 1, %L59 ], [ 1, %L53 ], [ 1, %L47 ], [ 1, %L41 ], [ %5, %L20 ]\r\n %67 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 24\r\n %68 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 24\r\n %69 = load i32, ptr addrspace(11) %68, align 4\r\n %70 = load i32, ptr addrspace(11) %67, align 4\r\n %.not289 = icmp eq i32 %69, %70\r\n br i1 %.not289, label %L134, label %L128\r\n\r\nL128: ; preds = %L112\r\n %71 = add i32 %69, 1\r\n %72 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 28\r\n %73 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 32\r\n %74 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 36\r\n %75 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 40\r\n %76 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 44\r\n %.not290 = icmp eq ptr addrspace(11) %72, null\r\n %77 = load i32, ptr addrspace(11) %72, align 4\r\n %78 = select i1 %.not290, i32 undef, i32 %77\r\n %.not291 = icmp eq ptr addrspace(11) %73, null\r\n %79 = load i32, ptr addrspace(11) %73, align 4\r\n %80 = select i1 %.not291, i32 undef, i32 %79\r\n %.not292 = icmp eq ptr addrspace(11) %74, null\r\n %81 = load i32, ptr addrspace(11) %74, align 4\r\n %82 = select i1 %.not292, i32 undef, i32 %81\r\n %.not293 = icmp eq ptr addrspace(11) %75, null\r\n %83 = load i32, ptr addrspace(11) %75, align 4\r\n %84 = select i1 %.not293, i32 undef, i32 %83\r\n %.not294 = icmp eq ptr addrspace(11) %76, null\r\n %85 = load i32, ptr addrspace(11) %76, align 4\r\n %86 = select i1 %.not294, i32 undef, i32 %85\r\n br label %L230\r\n\r\nL134: ; preds = %L112\r\n %87 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 28\r\n %88 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 32\r\n %89 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 36\r\n %90 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 40\r\n %91 = getelementptr inbounds i8, ptr addrspace(11) %1, i32 44\r\n %92 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 28\r\n %93 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 36\r\n %94 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 40\r\n %95 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 44\r\n %96 = load i32, ptr addrspace(11) %87, align 4\r\n %97 = load i32, ptr addrspace(11) %92, align 4\r\n %.not300 = icmp eq i32 %96, %97\r\n br i1 %.not300, label %L150, label %L149\r\n\r\nL149: ; preds = %L134\r\n %98 = add i32 %96, 1\r\n %.not301 = icmp eq ptr addrspace(11) %88, null\r\n %99 = load i32, ptr addrspace(11) %88, align 4\r\n %100 = select i1 %.not301, i32 undef, i32 %99\r\n %.not302 = icmp eq ptr addrspace(11) %89, null\r\n %101 = load i32, ptr addrspace(11) %89, align 4\r\n %102 = select i1 %.not302, i32 undef, i32 %101\r\n %.not303 = icmp eq ptr addrspace(11) %90, null\r\n %103 = load i32, ptr addrspace(11) %90, align 4\r\n %104 = select i1 %.not303, i32 undef, i32 %103\r\n %.not304 = icmp eq ptr addrspace(11) %91, null\r\n %105 = load i32, ptr addrspace(11) %91, align 4\r\n %106 = select i1 %.not304, i32 undef, i32 %105\r\n br label %L230\r\n\r\nL150: ; preds = %L134\r\n %107 = getelementptr inbounds i8, ptr addrspace(11) %0, i32 32\r\n %108 = load i32, ptr addrspace(11) %88, align 4\r\n %109 = load i32, ptr addrspace(11) %107, align 4\r\n %.not305 = icmp eq i32 %108, %109\r\n br i1 %.not305, label %L156, label %L155\r\n\r\nL155: ; preds = %L150\r\n %110 = add i32 %108, 1\r\n %.not306 = icmp eq ptr addrspace(11) %89, null\r\n %111 = load i32, ptr addrspace(11) %89, align 4\r\n %112 = select i1 %.not306, i32 undef, i32 %111\r\n %.not307 = icmp eq ptr addrspace(11) %90, null\r\n %113 = load i32, ptr addrspace(11) %90, align 4\r\n %114 = select i1 %.not307, i32 undef, i32 %113\r\n %.not308 = icmp eq ptr addrspace(11) %91, null\r\n %115 = load i32, ptr addrspace(11) %91, align 4\r\n %116 = select i1 %.not308, i32 undef, i32 %115\r\n br label %L230\r\n\r\nL156: ; preds = %L150\r\n %117 = load i32, ptr addrspace(11) %89, align 4\r\n %118 = load i32, ptr addrspace(11) %93, align 4\r\n %.not309 = icmp eq i32 %117, %118\r\n br i1 %.not309, label %L162, label %L161\r\n\r\nL161: ; preds = %L156\r\n %119 = add i32 %117, 1\r\n %.not310 = icmp eq ptr addrspace(11) %90, null\r\n %120 = load i32, ptr addrspace(11) %90, align 4\r\n %121 = select i1 %.not310, i32 undef, i32 %120\r\n %.not311 = icmp eq ptr addrspace(11) %91, null\r\n %122 = load i32, ptr addrspace(11) %91, align 4\r\n %123 = select i1 %.not311, i32 undef, i32 %122\r\n br label %L230\r\n\r\nL162: ; preds = %L156\r\n %124 = load i32, ptr addrspace(11) %90, align 4\r\n %125 = load i32, ptr addrspace(11) %94, align 4\r\n %.not312 = icmp eq i32 %124, %125\r\n br i1 %.not312, label %L195, label %L167\r\n\r\nL167: ; preds = %L162\r\n %126 = add i32 %124, 1\r\n %.not313 = icmp eq ptr addrspace(11) %91, null\r\n %127 = load i32, ptr addrspace(11) %91, align 4\r\n %128 = select i1 %.not313, i32 undef, i32 %127\r\n br label %L230\r\n\r\nL195: ; preds = %L162\r\n %129 = load i32, ptr addrspace(11) %91, align 4\r\n %130 = add i32 %129, 1\r\n %131 = load i32, ptr addrspace(11) %95, align 4\r\n %132 = icmp eq i32 %129, %131\r\n br i1 %132, label %common.ret, label %L230\r\n\r\ncommon.ret: ; preds = %L87, %L195, %L230\r\n %common.ret.op = phi { ptr addrspace(10), i8 } [ { ptr addrspace(10) null, i8 2 }, %L230 ], [ { ptr addrspace(10) null, i8 1 }, %L195 ], [ { ptr addrspace(10) null, i8 1 }, %L87 ]\r\n ret { ptr addrspace(10), i8 } %common.ret.op\r\n\r\nL230: ; preds = %L195, %L128, %L149, %L155, %L161, %L167\r\n %value_phi29359 = phi i32 [ %130, %L195 ], [ %128, %L167 ], [ %123, %L161 ], [ %116, %L155 ], [ %106, %L149 ], [ %86, %L128 ]\r\n %value_phi28358 = phi i32 [ 1, %L195 ], [ %126, %L167 ], [ %121, %L161 ], [ %114, %L155 ], [ %104, %L149 ], [ %84, %L128 ]\r\n %value_phi27357 = phi i32 [ 1, %L195 ], [ 1, %L167 ], [ %119, %L161 ], [ %112, %L155 ], [ %102, %L149 ], [ %82, %L128 ]\r\n %value_phi26356 = phi i32 [ 1, %L195 ], [ 1, %L167 ], [ 1, %L161 ], [ %110, %L155 ], [ %100, %L149 ], [ %80, %L128 ]\r\n %value_phi25355 = phi i32 [ 1, %L195 ], [ 1, %L167 ], [ 1, %L161 ], [ 1, %L155 ], [ %98, %L149 ], [ %78, %L128 ]\r\n %value_phi18349 = phi i32 [ 1, %L195 ], [ 1, %L167 ], [ 1, %L161 ], [ 1, %L155 ], [ 1, %L149 ], [ %71, %L128 ]\r\n store i32 %value_phi2326, ptr %union_bytes_return, align 4\r\n %.sroa.0429.sroa.0.sroa.2.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 4\r\n store i32 %value_phi9332, ptr %.sroa.0429.sroa.0.sroa.2.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.0.sroa.3.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 8\r\n store i32 %value_phi10333, ptr %.sroa.0429.sroa.0.sroa.3.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.0.sroa.4.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 12\r\n store i32 %value_phi11334, ptr %.sroa.0429.sroa.0.sroa.4.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.0.sroa.5.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 16\r\n store i32 %value_phi12335, ptr %.sroa.0429.sroa.0.sroa.5.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.0.sroa.6.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 20\r\n store i32 %value_phi13336, ptr %.sroa.0429.sroa.0.sroa.6.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.2.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 24\r\n store i32 %value_phi18349, ptr %.sroa.0429.sroa.2.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.3.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 28\r\n store i32 %value_phi25355, ptr %.sroa.0429.sroa.3.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.4.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 32\r\n store i32 %value_phi26356, ptr %.sroa.0429.sroa.4.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.5.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 36\r\n store i32 %value_phi27357, ptr %.sroa.0429.sroa.5.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.6.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 40\r\n store i32 %value_phi28358, ptr %.sroa.0429.sroa.6.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.7.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 44\r\n store i32 %value_phi29359, ptr %.sroa.0429.sroa.7.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.8.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 48\r\n store i32 %value_phi2326, ptr %.sroa.0429.sroa.8.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.0429.sroa.8.sroa.2.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 52\r\n store i32 %value_phi9332, ptr %.sroa.0429.sroa.8.sroa.2.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx, align 4\r\n %.sroa.0429.sroa.8.sroa.3.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 56\r\n store i32 %value_phi10333, ptr %.sroa.0429.sroa.8.sroa.3.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx, align 4\r\n %.sroa.0429.sroa.8.sroa.4.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 60\r\n store i32 %value_phi11334, ptr %.sroa.0429.sroa.8.sroa.4.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx, align 4\r\n %.sroa.0429.sroa.8.sroa.5.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 64\r\n store i32 %value_phi12335, ptr %.sroa.0429.sroa.8.sroa.5.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx, align 4\r\n %.sroa.0429.sroa.8.sroa.6.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 68\r\n store i32 %value_phi13336, ptr %.sroa.0429.sroa.8.sroa.6.0..sroa.0429.sroa.8.0.union_bytes_return.sroa_idx.sroa_idx, align 4\r\n %.sroa.4430.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 72\r\n store i32 %value_phi18349, ptr %.sroa.4430.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.5431.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 76\r\n store i32 %value_phi25355, ptr %.sroa.5431.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.6432.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 80\r\n store i32 %value_phi26356, ptr %.sroa.6432.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.7433.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 84\r\n store i32 %value_phi27357, ptr %.sroa.7433.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.8434.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 88\r\n store i32 %value_phi28358, ptr %.sroa.8434.0.union_bytes_return.sroa_idx, align 4\r\n %.sroa.9435.0.union_bytes_return.sroa_idx = getelementptr inbounds i8, ptr %union_bytes_return, i32 92\r\n store i32 %value_phi29359, ptr %.sroa.9435.0.union_bytes_return.sroa_idx, align 4\r\n br label %common.ret\r\n}\r\n\r\ndeclare ptr @julia.get_pgcstack()\r\n\r\n; Function Attrs: memory(argmem: readwrite, inaccessiblemem: readwrite)\r\ndeclare void @julia.safepoint(ptr) #2\r\n\r\n; Function Attrs: willreturn memory(argmem: read, inaccessiblemem: readwrite)\r\ndeclare nonnull align 16 dereferenceable(16) ptr addrspace(10) @jl_alloc_genericmemory(ptr addrspace(10), i32) #3\r\n\r\n; Function Attrs: nounwind willreturn allockind(\"alloc\") allocsize(1) memory(argmem: read, inaccessiblemem: readwrite)\r\ndeclare noalias nonnull ptr addrspace(10) @julia.gc_alloc_obj(ptr, i32, ptr addrspace(10)) #4\r\n\r\n; Function Attrs: norecurse nosync nounwind speculatable willreturn memory(none)\r\ndeclare noundef nonnull ptr addrspace(13) @julia.gc_loaded(ptr addrspace(10) nocapture noundef nonnull readnone, ptr noundef nonnull readnone) #5\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #6\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #6\r\n```\r\ngives error \r\n```\r\nInstruction does not dominate all uses!\r\n %20 = shufflevector <4 x ptr addrspace(11)> %19, <4 x ptr addrspace(11)> poison, <4 x i32> zeroinitializer\r\n %17 = shufflevector <4 x ptr addrspace(11)> %20, <4 x ptr addrspace(11)> poison, <2 x i32> zeroinitializer\r\nInstruction does not dominate all uses!\r\n %90 = shufflevector <4 x ptr addrspace(11)> %89, <4 x ptr addrspace(11)> poison, <4 x i32> zeroinitializer\r\n %87 = shufflevector <4 x ptr addrspace(11)> %90, <4 x ptr addrspace(11)> poison, <2 x i32> zeroinitializer\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 <source>\r\n1.\tRunning pass \"verify\" on module \"<source>\"\r\n #0 0x00000000050e6958 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50e6958)\r\n #1 0x00000000050e434c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007508e6a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007508e6a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007508e6a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007508e6a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007d7105 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x00000000050254d8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50254d8)\r\n #8 0x0000000004f23440 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f23440)\r\n #9 0x00000000009000ae 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+0x9000ae)\r\n#10 0x0000000004ee6850 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ee6850)\r\n#11 0x000000000090adda 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+0x90adda)\r\n#12 0x00000000008fdd2a optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fdd2a)\r\n#13 0x00007508e6a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007508e6a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008f57ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f57ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nhttps://godbolt.org/z/sah34KE77", "author": "Zentrik", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [ { "author": "Zentrik", "body": "Reduced IR:\r\n```llvm\r\ndefine swiftcc { ptr addrspace(10), i8 } @julia__zip_iterate_all_17381(ptr addrspace(11) %0, i32 %1) {\r\ntop:\r\n %2 = getelementptr i8, ptr addrspace(11) %0, i32 8\r\n %3 = getelementptr i8, ptr addrspace(11) %0, i32 12\r\n %4 = getelementptr i8, ptr addrspace(11) %0, i32 16\r\n %5 = getelementptr i8, ptr addrspace(11) %0, i32 20\r\n br i1 false, label %L42, label %L41\r\n\r\nL41: ; preds = %top\r\n %.not276 = icmp eq ptr addrspace(11) %2, null\r\n %6 = select i1 %.not276, i32 0, i32 0\r\n %.not277 = icmp eq ptr addrspace(11) %3, null\r\n %7 = select i1 %.not277, i32 0, i32 0\r\n %.not278 = icmp eq ptr addrspace(11) %4, null\r\n %8 = select i1 %.not278, i32 0, i32 0\r\n %.not279 = icmp eq ptr addrspace(11) %5, null\r\n %9 = select i1 %.not279, i32 0, i32 0\r\n br label %common.ret\r\n\r\nL42: ; preds = %top\r\n %.not282 = icmp eq ptr addrspace(11) %4, null\r\n %10 = select i1 %.not282, i32 0, i32 0\r\n %.not283 = icmp eq ptr addrspace(11) %5, null\r\n %11 = select i1 %.not283, i32 0, i32 0\r\n br label %common.ret\r\n\r\nL59: ; No predecessors!\r\n %12 = select i1 false, i32 0, i32 0\r\n br label %common.ret\r\n\r\ncommon.ret: ; preds = %L59, %L42, %L41\r\n %value_phi13336 = phi i32 [ %12, %L59 ], [ %11, %L42 ], [ %9, %L41 ]\r\n %value_phi12335 = phi i32 [ 0, %L59 ], [ %10, %L42 ], [ %8, %L41 ]\r\n %value_phi11334 = phi i32 [ 0, %L59 ], [ %1, %L42 ], [ %7, %L41 ]\r\n %value_phi10333 = phi i32 [ 0, %L59 ], [ 0, %L42 ], [ %6, %L41 ]\r\n ret { ptr addrspace(10), i8 } zeroinitializer\r\n}\r\n```\r\nhttps://godbolt.org/z/a8xzqGYo9" }, { "author": "Zentrik", "body": "Bisected to 69332bb8995aef60d830406de12cb79a5039026 and f3d2609af3031ddb54030548e86335f295cf49ca, @alexey-bataev " } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.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/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::collectValuesToDemote", "BoUpSLP::computeMinimumValueSizes" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
84709
https://github.com/llvm/llvm-project/issues/84709
crash
4d0f79e346ceb0ddb25a94053c612a5b34a72100
2024-03-11T03:25:11
[ "llvm/test/Transforms/LoopStrengthReduce" ]
{ "fix_commit": "beba307c5bc206168bdea3b893e02ea31579fe62", "components": [ "LoopStrengthReduce" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": [ [ 6971, 6976 ], [ 6989, 6994 ] ], "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": [ "ReduceLoopStrength" ], "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit beba307c5bc206168bdea3b893e02ea31579fe62 Author: Nikita Popov <[email protected]> Date: Tue Mar 12 16:23:25 2024 +0100 [LSR] Clear SCEVExpander before deleting phi nodes Fixes https://github.com/llvm/llvm-project/issues/84709. diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 8b078ddc4e74..c4e1a0db8b32 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -6971,6 +6971,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE, Rewriter.setDebugType(DEBUG_TYPE); #endif unsigned numFolded = Rewriter.replaceCongruentIVs(L, &DT, DeadInsts, &TTI); + Rewriter.clear(); if (numFolded) { Changed = true; RecursivelyDeleteTriviallyDeadInstructionsPermissive(DeadInsts, &TLI, @@ -6989,6 +6990,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU, ScalarEvolution &SE, SCEVExpander Rewriter(SE, DL, "lsr", true); int Rewrites = rewriteLoopExitValues(L, &LI, &TLI, &SE, &TTI, Rewriter, &DT, UnusedIndVarInLoop, DeadInsts); + Rewriter.clear(); if (Rewrites) { Changed = true; RecursivelyDeleteTriviallyDeadInstructionsPermissive(DeadInsts, &TLI,
[ { "file": "llvm/test/Transforms/LoopStrengthReduce/pr84709.ll", "commands": [ "opt -S -passes=loop-reduce < %s" ], "tests": [ { "test_name": "test", "test_body": "define i64 @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb5, %bb\n %phi = phi i8 [ %zext6, %bb5 ], [ 0, %bb ]\n br label %bb2\n\nbb2: ; preds = %bb2, %bb1\n %phi3 = phi i8 [ %add, %bb2 ], [ %phi, %bb1 ]\n %phi4 = phi i32 [ 0, %bb2 ], [ 1, %bb1 ]\n %add = add i8 %phi3, 1\n br i1 true, label %bb5, label %bb2\n\nbb5: ; preds = %bb2\n %zext = zext i8 %add to i32\n %icmp = icmp sge i32 %phi4, 0\n %zext6 = zext i1 %icmp to i8\n br label %bb1\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[LSR] crashed on \"asserting value handle still pointed to this value!\"", "body": "https://godbolt.org/z/MWWcGdxT5\r\nLSR crashed when deleting dead PHIs ", "author": "coderchenlin", "labels": [ "llvm:crash", "llvm:transforms" ], "comments": [ { "author": "coderchenlin", "body": "I will give a resolution to fix it later." }, { "author": "coderchenlin", "body": " #84777 For this case, I think we should not set the value with nullptr when the value's uses are not empty. " }, { "author": "nikic", "body": "Reduced:\r\n```llvm\r\ndefine i64 @test() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1:\r\n %phi = phi i8 [ %zext6, %bb5 ], [ 0, %bb ]\r\n br label %bb2\r\n\r\nbb2:\r\n %phi3 = phi i8 [ %add, %bb2 ], [ %phi, %bb1 ]\r\n %phi4 = phi i32 [ 0, %bb2 ], [ 1, %bb1 ]\r\n %add = add i8 %phi3, 1\r\n br i1 true, label %bb5, label %bb2\r\n\r\nbb5:\r\n %zext = zext i8 %add to i32\r\n %icmp = icmp sge i32 %phi4, 0\r\n %zext6 = zext i1 %icmp to i8\r\n br label %bb1\r\n}\r\n```" } ] }
true
null
113526
https://github.com/llvm/llvm-project/issues/113526
crash
8c4bc1e75de27adfbaead34b895b0efbaf17bd02
2024-10-24T06:14:03
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "e724226da753f10fd36fbb0ea392f04ab0fdbdab", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 1524, 1529 ] ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPWidenCastRecipe::computeCost" ], "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit e724226da753f10fd36fbb0ea392f04ab0fdbdab Author: Florian Hahn <[email protected]> Date: Fri Oct 25 12:35:33 2024 +0100 [VPlan] Return cost of 0 for VPWidenCastRecipe without underlying value. In some cases, VPWidenCastRecipes are created but not considered in the legacy cost model, including truncates/extends when evaluating a reduction in a smaller type. Return 0 for such casts for now, to avoid divergences between VPlan and legacy cost models. Fixes https://github.com/llvm/llvm-project/issues/113526. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 0eb4f7c7c88c..2080b77157b6 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -1524,6 +1524,11 @@ void VPWidenCastRecipe::execute(VPTransformState &State) { InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF, VPCostContext &Ctx) const { + // TODO: In some cases, VPWidenCastRecipes are created but not considered in + // the legacy cost model, including truncates/extends when evaluating a + // reduction in a smaller type. + if (!getUnderlyingValue()) + return 0; // Computes the CastContextHint from a recipes that may access memory. auto ComputeCCH = [&](const VPRecipeBase *R) -> TTI::CastContextHint { if (VF.isScalar())
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": [ "opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S" ], "tests": [ { "test_name": "narrowed_reduction", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {\nentry:\n %conv = zext i1 %cmp to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]\n %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]\n %and = and i32 %or13, 1\n %or = or i32 %and, %conv\n %inc = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %or\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cost_assume", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @cost_assume(ptr %end, i64 %N) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = phi i64 [ 0, %entry ], [ %1, %loop ]\n %1 = add i64 %0, 1\n %iv.next = add nsw i64 %iv, 1\n %c = icmp ne i64 %N, 0\n tail call void @llvm.assume(i1 %c)\n %gep = getelementptr nusw [9 x i8], ptr null, i64 %iv.next\n %ec = icmp eq ptr %gep, %end\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i64 %1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null }, { "test_name": "cost_loop_invariant_recipes", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @cost_loop_invariant_recipes(i1 %x, i64 %y) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.i.i.i, %loop ]\n %red = phi i64 [ 1, %entry ], [ %red.mul, %loop ]\n %not.x = xor i1 %x, true\n %ext = zext i1 %not.x to i64\n %shl = shl i64 %y, %ext\n %red.mul = mul i64 %shl, %red\n %iv.next.i.i.i = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i64 %red.mul\n}\n", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "clang crashes at -O{s,2,3} on x86_64-linux-gnu: Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed ", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\r\n\r\nCompiler Explorer: https://godbolt.org/z/jPaW9fnKj\r\n\r\n```\r\n[531] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git a9050525954cbe11d45b415e2248d9e25e004bfe)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\nFound CUDA installation: /usr/local/cuda, version 11.8\r\n[532] %\r\n[532] % clangtk -O3 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7519: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20241024-clangtk-m64-Os-build-062114/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241024-clangtk-m64-Os-build-062114/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-22743c.o -x c small.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000056385e381f80 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x43e3f80)\r\n #1 0x000056385e37f38f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x43e138f)\r\n #2 0x000056385e37f4e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fe699585520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007fe6995d9a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\r\n #5 0x00007fe699585476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #6 0x00007fe69956b7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #7 0x00007fe69956b71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #8 0x00007fe69957ce96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #9 0x000056385fd39986 llvm::LoopVectorizationPlanner::computeBestVF() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5d9b986)\r\n#10 0x000056385fd50d8c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5db2d8c)\r\n#11 0x000056385fd53ea1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5db5ea1)\r\n#12 0x000056385fd54517 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5db6517)\r\n#13 0x000056385f8a7d86 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5909d86)\r\n#14 0x000056385dd0d52f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3d6f52f)\r\n#15 0x000056385b779146 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x17db146)\r\n#16 0x000056385dd0b8bb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3d6d8bb)\r\n#17 0x000056385b777be6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x17d9be6)\r\n#18 0x000056385dd0c41d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3d6e41d)\r\n#19 0x000056385e6253b6 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#20 0x000056385e628d53 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x468ad53)\r\n#21 0x000056385eceb3f5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4d4d3f5)\r\n#22 0x0000563860a56ffc clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6ab8ffc)\r\n#23 0x000056385efcbdd9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x502ddd9)\r\n#24 0x000056385ef45205 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4fa7205)\r\n#25 0x000056385f0aa403 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x510c403)\r\n#26 0x000056385b330b57 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1392b57)\r\n#27 0x000056385b3275ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x000056385b32b96f clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x138d96f)\r\n#29 0x000056385b21ef2b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1280f2b)\r\n#30 0x00007fe69956cd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#31 0x00007fe69956ce40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#32 0x000056385b326d15 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1388d15)\r\nclangtk: error: unable to execute command: Aborted\r\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git a9050525954cbe11d45b415e2248d9e25e004bfe)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nclangtk: note: diagnostic msg:\r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclangtk: note: diagnostic msg: /tmp/small-ed84bf.c\r\nclangtk: note: diagnostic msg: /tmp/small-ed84bf.sh\r\nclangtk: note: diagnostic msg:\r\n\r\n********************\r\n[533] %\r\n[533] % cat small.c\r\nint a, b, c;\r\nint main() {\r\n for (; a; a++) {\r\n c &= 1;\r\n c |= b == 1;\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "zhendongsu", "body": "@fhahn " } ] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 16118, 16124 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::vectorizeTree" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
102351
https://github.com/llvm/llvm-project/issues/102351
miscompilation
203a2ca8cd6af505e11a38aebceeaf864271042c
2024-08-07T18:49:59
[ "llvm/test/Transforms/SimplifyCFG" ]
{ "fix_commit": "3c9022c965b85951f30af140da591f819acef8a0", "components": [ "Local" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": [ [ 1028, 1034 ], [ 1133, 1139 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": [ "CanRedirectPredsOfEmptyBBToSucc", "llvm::TryToSimplifyUncondBranchFromEmptyBlock" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 3c9022c965b85951f30af140da591f819acef8a0 Author: AdityaK <[email protected]> Date: Tue Sep 10 22:39:02 2024 -0700 Bail out jump threading on indirect branches (#103688) The bug was introduced by https://github.com/llvm/llvm-project/pull/68473 Fixes: #102351 diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index d0669e44f821..c85c819263e2 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1028,7 +1028,14 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ, if (!BB->hasNPredecessorsOrMore(2)) return false; - // Get single common predecessors of both BB and Succ + if (any_of(BBPreds, [](const BasicBlock *Pred) { + return isa<PHINode>(Pred->begin()) && + isa<IndirectBrInst>(Pred->getTerminator()); + })) + return false; + + // Get the single common predecessor of both BB and Succ. Return false + // when there are more than one common predecessors. for (BasicBlock *SuccPred : SuccPreds) { if (BBPreds.count(SuccPred)) { if (CommonPred) @@ -1133,7 +1140,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, bool BBKillable = CanPropagatePredecessorsForPHIs(BB, Succ, BBPreds); - // Even if we can not fold bB into Succ, we may be able to redirect the + // Even if we can not fold BB into Succ, we may be able to redirect the // predecessors of BB to Succ. bool BBPhisMergeable = BBKillable ||
[ { "file": "llvm/test/Transforms/SimplifyCFG/switch-branch-fold-indirectbr-102351.ll", "commands": [ "opt < %s -passes=simplifycfg -S" ], "tests": [ { "test_name": "main", "test_body": "@.str = private unnamed_addr constant [23 x i8] c\"OP_1:(instruction=%d)\\0A\\00\", align 1\[email protected] = private unnamed_addr constant [28 x i8] c\"TERMINATE:(instruction=%d)\\0A\\00\", align 1\n\n; Function Attrs: mustprogress norecurse uwtable\ndefine dso_local noundef i32 @main() #0 {\nentry:\n %bytecode = alloca [2 x ptr], align 16\n store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5\n %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1\n store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5\n br label %while.body\n\nwhile.body: ; preds = %entry, %sw.epilog\n %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ]\n %index.0 = phi i32 [ 0, %entry ], [ %index.2, %sw.epilog ]\n switch i32 %state.0, label %sw.epilog [\n i32 0, label %sw.bb\n i32 1, label %VM__OP_1\n i32 2, label %sw.bb4\n ]\n\nsw.bb: ; preds = %while.body\n br label %indirectgoto\n\nVM__OP_1: ; preds = %while.body, %indirectgoto\n %index.1 = phi i32 [ %index.3, %indirectgoto ], [ %index.0, %while.body ]\n br label %sw.epilog\n\nsw.bb4: ; preds = %while.body\n %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0)\n %inc = add nsw i32 %index.0, 1\n br label %indirectgoto\n\nsw.epilog: ; preds = %while.body, %VM__OP_1\n %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ]\n %index.2 = phi i32 [ %index.0, %while.body ], [ %index.1, %VM__OP_1 ]\n br label %while.body, !llvm.loop !9\n\nVM__TERMINATE: ; preds = %indirectgoto\n %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3)\n ret i32 0\n\nindirectgoto: ; preds = %sw.bb4, %sw.bb\n %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %sw.bb ]\n %idxprom.pn = sext i32 %index.3 to i64\n %indirect.goto.dest.in = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 %idxprom.pn\n %indirect.goto.dest = load ptr, ptr %indirect.goto.dest.in, align 8, !tbaa !5\n indirectbr ptr %indirect.goto.dest, [label %VM__OP_1, label %VM__TERMINATE]\n}\ndeclare i32 @printf(ptr noundef, ...) #1\n\nattributes #0 = { mustprogress norecurse 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 = { \"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 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)\"}\n!5 = !{!6, !6, i64 0}\n!6 = !{!\"any pointer\", !7, i64 0}\n!7 = !{!\"omnipotent char\", !8, i64 0}\n!8 = !{!\"Simple C++ TBAA\"}\n!9 = !{!10, !10, i64 0}\n!10 = !{!\"int\", !7, i64 0}\n!11 = distinct !{!11, !12, !13}\n!12 = !{!\"llvm.loop.mustprogress\"}\n!13 = !{!\"llvm.loop.unroll.disable\"}", "lli_expected_out": "OP_1:(instruction=0)\nTERMINATE:(instruction=1)\n", "additional_args": null } ] } ]
{ "title": "Miscompile in code with indirect gotos", "body": "The simplifycfg pass (incorrectly?) optimizes one of the case statements.\r\n\r\n```llvm\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\[email protected] = private unnamed_addr constant [23 x i8] c\"OP_1:(instruction=%d)\\0A\\00\", align 1\r\[email protected] = private unnamed_addr constant [28 x i8] c\"TERMINATE:(instruction=%d)\\0A\\00\", align 1\r\n\r\n; Function Attrs: mustprogress norecurse uwtable\r\ndefine dso_local noundef i32 @main() #0 {\r\nentry:\r\n %bytecode = alloca [2 x ptr], align 16\r\n store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5\r\n %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1\r\n store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5\r\n br label %while.body\r\n\r\nwhile.body: ; preds = %entry, %sw.epilog\r\n %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ]\r\n %index.0 = phi i32 [ 0, %entry ], [ %index.2, %sw.epilog ]\r\n switch i32 %state.0, label %sw.epilog [\r\n i32 0, label %sw.bb\r\n i32 1, label %VM__OP_1\r\n i32 2, label %sw.bb4\r\n ]\r\n\r\nsw.bb: ; preds = %while.body\r\n br label %indirectgoto\r\n\r\nVM__OP_1: ; preds = %while.body, %indirectgoto\r\n %index.1 = phi i32 [ %index.3, %indirectgoto ], [ %index.0, %while.body ]\r\n br label %sw.epilog\r\n\r\nsw.bb4: ; preds = %while.body\r\n %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0)\r\n %inc = add nsw i32 %index.0, 1\r\n br label %indirectgoto\r\n\r\nsw.epilog: ; preds = %while.body, %VM__OP_1\r\n %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ]\r\n %index.2 = phi i32 [ %index.0, %while.body ], [ %index.1, %VM__OP_1 ]\r\n br label %while.body, !llvm.loop !9\r\n\r\nVM__TERMINATE: ; preds = %indirectgoto\r\n %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3)\r\n ret i32 0\r\n\r\nindirectgoto: ; preds = %sw.bb4, %sw.bb\r\n %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %sw.bb ]\r\n %idxprom.pn = sext i32 %index.3 to i64\r\n %indirect.goto.dest.in = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 %idxprom.pn\r\n %indirect.goto.dest = load ptr, ptr %indirect.goto.dest.in, align 8, !tbaa !5\r\n indirectbr ptr %indirect.goto.dest, [label %VM__OP_1, label %VM__TERMINATE]\r\n}\r\ndeclare i32 @printf(ptr noundef, ...) #1\r\n\r\nattributes #0 = { mustprogress norecurse 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 = { \"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\n\r\n!llvm.module.flags = !{!0, !1, !2, !3}\r\n!llvm.ident = !{!4}\r\n\r\n!0 = !{i32 1, !\"wchar_size\", i32 4}\r\n!1 = !{i32 8, !\"PIC Level\", i32 2}\r\n!2 = !{i32 7, !\"PIE Level\", i32 2}\r\n!3 = !{i32 7, !\"uwtable\", i32 2}\r\n!4 = !{!\"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)\"}\r\n!5 = !{!6, !6, i64 0}\r\n!6 = !{!\"any pointer\", !7, i64 0}\r\n!7 = !{!\"omnipotent char\", !8, i64 0}\r\n!8 = !{!\"Simple C++ TBAA\"}\r\n!9 = !{!10, !10, i64 0}\r\n!10 = !{!\"int\", !7, i64 0}\r\n!11 = distinct !{!11, !12, !13}\r\n!12 = !{!\"llvm.loop.mustprogress\"}\r\n!13 = !{!\"llvm.loop.unroll.disable\"}\r\n```\r\n\r\n$ opt -passes=simplifycfg orig.ll -S -o out.ll\r\n```llvm\r\n; ModuleID = 'orig.ll'\r\nsource_filename = \"orig.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\[email protected] = private unnamed_addr constant [23 x i8] c\"OP_1:(instruction=%d)\\0A\\00\", align 1\r\[email protected] = private unnamed_addr constant [28 x i8] c\"TERMINATE:(instruction=%d)\\0A\\00\", align 1\r\n\r\n; Function Attrs: mustprogress norecurse uwtable\r\ndefine dso_local noundef i32 @main() #0 {\r\nentry:\r\n %bytecode = alloca [2 x ptr], align 16\r\n store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5\r\n %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1\r\n store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5\r\n br label %while.body\r\n\r\nwhile.body: ; preds = %sw.epilog, %entry\r\n %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ]\r\n %index.0 = phi i32 [ 0, %entry ], [ %index.0, %sw.epilog ]\r\n switch i32 %state.0, label %sw.epilog [\r\n i32 0, label %VM__TERMINATE\r\n i32 1, label %VM__OP_1\r\n i32 2, label %sw.bb4\r\n ]\r\n\r\nVM__OP_1: ; preds = %while.body\r\n br label %sw.epilog\r\n\r\nsw.bb4: ; preds = %while.body\r\n %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0)\r\n %inc = add nsw i32 %index.0, 1\r\n br label %VM__TERMINATE\r\n\r\nsw.epilog: ; preds = %VM__OP_1, %while.body\r\n %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ]\r\n br label %while.body, !llvm.loop !9\r\n\r\nVM__TERMINATE: ; preds = %sw.bb4, %while.body\r\n %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %while.body ]\r\n %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3)\r\n ret i32 0\r\n}\r\n\r\ndeclare i32 @printf(ptr noundef, ...) #1\r\n\r\nattributes #0 = { mustprogress norecurse 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 = { \"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\n\r\n!llvm.module.flags = !{!0, !1, !2, !3}\r\n!llvm.ident = !{!4}\r\n\r\n!0 = !{i32 1, !\"wchar_size\", i32 4}\r\n!1 = !{i32 8, !\"PIC Level\", i32 2}\r\n!2 = !{i32 7, !\"PIE Level\", i32 2}\r\n!3 = !{i32 7, !\"uwtable\", i32 2}\r\n!4 = !{!\"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)\"}\r\n!5 = !{!6, !6, i64 0}\r\n!6 = !{!\"any pointer\", !7, i64 0}\r\n!7 = !{!\"omnipotent char\", !8, i64 0}\r\n!8 = !{!\"Simple C++ TBAA\"}\r\n!9 = !{!10, !10, i64 0}\r\n!10 = !{!\"int\", !7, i64 0}\r\n```", "author": "hiraditya", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "hiraditya", "body": "Original C code\r\n\r\n```c\r\nextern int printf(const char *fmt, ...);\r\n\r\nint main() {\r\n void* bytecode[2];\r\n bytecode[0] = &&VM__OP_1;\r\n bytecode[1] = &&VM__TERMINATE;\r\n\r\n int state = 0;\r\n int index = 0;\r\n\r\n while (1) {\r\n switch (state) {\r\n case 0:\r\n goto *bytecode[index];\r\n case 1:\r\n // NOTE: THIS IS ONLY REACHABLE VIA INDIRECT GOTOS\r\n VM__OP_1:\r\n state = 2;\r\n break;\r\n case 2:\r\n printf(\"OP_1:(instruction=%d)\\n\", index);\r\n index++;\r\n goto *bytecode[index];\r\n }\r\n }\r\n\r\nVM__TERMINATE:\r\n printf(\"TERMINATE:(instruction=%d)\\n\", index);\r\n return 0;\r\n}\r\n```\r\n\r\nhttps://github.com/llvm/llvm-project/pull/76295 makes the miscompile go away(https://godbolt.org/z/d9bGnhhv6) but I think simplifycfg still has the bug.\r\n" }, { "author": "efriedma-quic", "body": "Looks like TryToSimplifyUncondBranchFromEmptyBlock is not handling indirectbr predecessors correctly: the indirectbr's successor list is rewritten so it has a successor that isn't address-taken. That edge is then proven impossible, so the indirectbr is completely eliminated." } ] }
true
null
89500
https://github.com/llvm/llvm-project/issues/89500
miscompilation
a1b1c4a6d1d52916c5d885170a5f54632d579cdc
2024-04-20T12:43:21
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "7339f7ba3053db7595ece1ca5f49bd2e4c3c8305", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 1722, 1732 ] ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": [ [ 350, 357 ], [ 374, 380 ], [ 389, 400 ], [ 484, 489 ], [ 2596, 2601 ] ], "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "foldSelectICmpEq" ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": [ "isValue", "m_AllOnes", "m_Not", "m_c_SMin", "match" ], "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 7339f7ba3053db7595ece1ca5f49bd2e4c3c8305 Author: Nikita Popov <[email protected]> Date: Wed Apr 24 10:57:17 2024 +0900 [InstCombine] Fix poison propagation in select of bitwise fold (#89701) We're replacing the select with the false value here, but it may be more poisonous if m_Not contains poison elements. Fix this by introducing a m_NotForbidPoison matcher and using it here. Fixes https://github.com/llvm/llvm-project/issues/89500. diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 1fee1901fabb..0b13b4aad9c3 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -350,8 +350,9 @@ template <int64_t Val> inline constantint_match<Val> m_ConstantInt() { /// This helper class is used to match constant scalars, vector splats, /// and fixed width vectors that satisfy a specified predicate. -/// For fixed width vector constants, poison elements are ignored. -template <typename Predicate, typename ConstantVal> +/// For fixed width vector constants, poison elements are ignored if AllowPoison +/// is true. +template <typename Predicate, typename ConstantVal, bool AllowPoison> struct cstval_pred_ty : public Predicate { template <typename ITy> bool match(ITy *V) { if (const auto *CV = dyn_cast<ConstantVal>(V)) @@ -374,7 +375,7 @@ struct cstval_pred_ty : public Predicate { Constant *Elt = C->getAggregateElement(i); if (!Elt) return false; - if (isa<PoisonValue>(Elt)) + if (AllowPoison && isa<PoisonValue>(Elt)) continue; auto *CV = dyn_cast<ConstantVal>(Elt); if (!CV || !this->isValue(CV->getValue())) @@ -389,12 +390,13 @@ struct cstval_pred_ty : public Predicate { }; /// specialization of cstval_pred_ty for ConstantInt -template <typename Predicate> -using cst_pred_ty = cstval_pred_ty<Predicate, ConstantInt>; +template <typename Predicate, bool AllowPoison = true> +using cst_pred_ty = cstval_pred_ty<Predicate, ConstantInt, AllowPoison>; /// specialization of cstval_pred_ty for ConstantFP template <typename Predicate> -using cstfp_pred_ty = cstval_pred_ty<Predicate, ConstantFP>; +using cstfp_pred_ty = cstval_pred_ty<Predicate, ConstantFP, + /*AllowPoison=*/true>; /// This helper class is used to match scalar and vector constants that /// satisfy a specified predicate, and bind them to an APInt. @@ -484,6 +486,10 @@ inline cst_pred_ty<is_all_ones> m_AllOnes() { return cst_pred_ty<is_all_ones>(); } +inline cst_pred_ty<is_all_ones, false> m_AllOnesForbidPoison() { + return cst_pred_ty<is_all_ones, false>(); +} + struct is_maxsignedvalue { bool isValue(const APInt &C) { return C.isMaxSignedValue(); } }; @@ -2596,6 +2602,13 @@ m_Not(const ValTy &V) { return m_c_Xor(m_AllOnes(), V); } +template <typename ValTy> +inline BinaryOp_match<cst_pred_ty<is_all_ones, false>, ValTy, Instruction::Xor, + true> +m_NotForbidPoison(const ValTy &V) { + return m_c_Xor(m_AllOnesForbidPoison(), V); +} + /// Matches an SMin with LHS and RHS in either order. template <typename LHS, typename RHS> inline MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true> diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 73600206a55c..117eb7a1dcc9 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1722,11 +1722,11 @@ static Instruction *foldSelectICmpEq(SelectInst &SI, ICmpInst *ICI, return match(CmpRHS, m_Zero()) && match(FalseVal, matchInner); if (NotMask == NotInner) { - return match(FalseVal, - m_c_BinOp(OuterOpc, m_Not(matchInner), m_Specific(CmpRHS))); + return match(FalseVal, m_c_BinOp(OuterOpc, m_NotForbidPoison(matchInner), + m_Specific(CmpRHS))); } else if (NotMask == NotRHS) { - return match(FalseVal, - m_c_BinOp(OuterOpc, matchInner, m_Not(m_Specific(CmpRHS)))); + return match(FalseVal, m_c_BinOp(OuterOpc, matchInner, + m_NotForbidPoison(m_Specific(CmpRHS)))); } else { return match(FalseVal, m_c_BinOp(OuterOpc, matchInner, m_Specific(CmpRHS)));
[ { "file": "llvm/test/Transforms/InstCombine/select.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "src_and_eq_C_xor_OrAndNotC_vec_poison", "test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC_vec_poison(<2 x i32> %0, <2 x i32> %1, <2 x i32> %2) {\nentry:\n %and = and <2 x i32> %1, %0\n %cmp = icmp eq <2 x i32> %and, %2\n %xor = xor <2 x i32> %1, %0\n %or = or <2 x i32> %1, %0\n %not = xor <2 x i32> %2, <i32 -1, i32 poison>\n %and1 = and <2 x i32> %or, %not\n %cond = select <2 x i1> %cmp, <2 x i32> %xor, <2 x i32> %and1\n ret <2 x i32> %cond\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Miscompilation with poison vectors in `src_and_eq_C_xor_OrAndNotC` ", "body": "Alive2: https://alive2.llvm.org/ce/z/yB3oAx\r\n```ll\r\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC(<2 x i32> %0, <2 x i32> %1, <2 x i32> %2) {\r\nentry:\r\n %and = and <2 x i32> %1, %0\r\n %cmp = icmp eq <2 x i32> %and, %2\r\n %xor = xor <2 x i32> %1, %0\r\n %or = or <2 x i32> %1, %0\r\n %not = xor <2 x i32> %2, <i32 -1, i32 poison>\r\n %and1 = and <2 x i32> %or, %not\r\n %cond = select <2 x i1> %cmp, <2 x i32> %xor, <2 x i32> %and1\r\n ret <2 x i32> %cond\r\n}\r\n```\r\n```ll\r\n\r\n----------------------------------------\r\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC(<2 x i32> %#0, <2 x i32> %#1, <2 x i32> %#2) {\r\nentry:\r\n %and = and <2 x i32> %#1, %#0\r\n %cmp = icmp eq <2 x i32> %and, %#2\r\n %xor = xor <2 x i32> %#1, %#0\r\n %or = or <2 x i32> %#1, %#0\r\n %not = xor <2 x i32> %#2, { 4294967295, poison }\r\n %and1 = and <2 x i32> %or, %not\r\n %cond = select <2 x i1> %cmp, <2 x i32> %xor, <2 x i32> %and1\r\n ret <2 x i32> %cond\r\n}\r\n=>\r\ndefine <2 x i32> @src_and_eq_C_xor_OrAndNotC(<2 x i32> %#0, <2 x i32> %#1, <2 x i32> %#2) nofree willreturn memory(none) {\r\nentry:\r\n %or = or <2 x i32> %#1, %#0\r\n %not = xor <2 x i32> %#2, { 4294967295, poison }\r\n %and1 = and <2 x i32> %or, %not\r\n ret <2 x i32> %and1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<2 x i32> %#0 = < poison, #x00000000 (0) >\r\n<2 x i32> %#1 = < poison, #x00000000 (0) >\r\n<2 x i32> %#2 = < poison, #x00000000 (0) >\r\n\r\nSource:\r\n<2 x i32> %and = < poison, #x00000000 (0) >\r\n<2 x i1> %cmp = < poison, #x1 (1) >\r\n<2 x i32> %xor = < poison, #x00000000 (0) >\r\n<2 x i32> %or = < poison, #x00000000 (0) >\r\n<2 x i32> %not = < poison, poison >\r\n<2 x i32> %and1 = < poison, poison >\r\n<2 x i32> %cond = < poison, #x00000000 (0) >\r\n\r\nTarget:\r\n<2 x i32> %or = < poison, #x00000000 (0) >\r\n<2 x i32> %not = < poison, poison >\r\n<2 x i32> %and1 = < poison, poison >\r\nSource value: < poison, #x00000000 (0) >\r\nTarget value: < poison, poison >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```\r\n\r\nFound with https://github.com/dtcxzyw/llvm-tools.\r\ncc @nikic", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "nikic", "body": "Looks like a recent issue introduced with https://github.com/llvm/llvm-project/pull/73362." }, { "author": "ParkHanbum", "body": "I'll not forget to create a testcase with poison.\r\n" } ] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [ [ 2901, 2907 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [ "InstCombinerImpl::visitShuffleVectorInst" ], "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
102994
https://github.com/llvm/llvm-project/issues/102994
hang
15e915a44f0d0bf092214586d3ec86e2bb7636d7
2024-08-13T02:57:21
[ "llvm/test/Transforms/MemCpyOpt" ]
{ "fix_commit": "378daa6c6fd10d3704be449f2fe9c55df522a6e9", "components": [ "MemCpyOptimizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": [ [ 1193, 1198 ] ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": [ "MemCpyOptPass::processMemCpyMemCpyDependence" ], "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 378daa6c6fd10d3704be449f2fe9c55df522a6e9 Author: Yingwei Zheng <[email protected]> Date: Thu Aug 22 17:20:47 2024 +0800 [MemCpyOpt] Avoid infinite loops in `MemCpyOptPass::processMemCpyMemCpyDependence` (#103218) Closes https://github.com/llvm/llvm-project/issues/102994. diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 1d779128e454..3f15fa2163d2 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1193,6 +1193,10 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M, CopySourceAlign = commonAlignment(*CopySourceAlign, MForwardOffset); } + // Avoid infinite loops + if (BAA.isMustAlias(M->getSource(), CopySource)) + return false; + // Verify that the copied-from memory doesn't change in between the two // transfers. For example, in: // memcpy(a <- b)
[ { "file": "llvm/test/Transforms/MemCpyOpt/pr102994.ll", "commands": [ "opt -S -passes=memcpyopt < %s" ], "tests": [ { "test_name": "func2", "test_body": "@g3 = external global i8, align 1\n\ndefine void @func2(ptr %p) {\nentry:\n %gep1 = getelementptr i8, ptr %p, i64 32\n %gep2 = getelementptr i8, ptr %p, i64 34\n %gep3 = getelementptr i8, ptr %p, i64 32\n call void @llvm.memcpy.p0.p0.i64(ptr %gep1, ptr %gep3, i64 32, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr @g3, ptr %gep2, i64 1, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "func", "test_body": "@g1 = external global i8\n@g2 = external global [64 x i8]\n\ndefine void @func() {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g2, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g2, i64 16), i64 20, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr @g1, ptr getelementptr inbounds (i8, ptr @g2, i64 24), i64 1, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[MemcpyOpt] Infinite loops when forwarding memcpy on globals", "body": "Reproducer: https://godbolt.org/z/GKzGEKE18\r\n```\r\n; bin/opt -passes=memcpyopt reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n%struct.S1 = type { i64, i16, i32, %struct.S0, i8, i32, i8, i32, i8 }\r\n%struct.S0 = type { i32, i32, i32, i32, i16 }\r\n\r\n@g = external global i8\r\n@g_265 = external global %struct.S1\r\n\r\ndefine void @func() {\r\nentry:\r\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr @g_265, i64 24), i64 1, i1 false)\r\n ret void\r\n}\r\n```\r\n```\r\nFound roots: %entry \r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 0 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nMemCpyOptPass: Forwarding memcpy->memcpy src:\r\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr @g_265, i64 24), i64 1, i1 false)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 0 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nClobber starting at access 1 = MemoryDef(liveOnEntry)\r\n for instruction call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n is 1 = MemoryDef(liveOnEntry)\r\nMemCpyOptPass: Forwarding memcpy->memcpy src:\r\n call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)\r\n call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 8), i64 1, i1 false)\r\n...\r\n```", "author": "dtcxzyw", "labels": [ "llvm:hang", "llvm:transforms" ], "comments": [] }
true
null
105904
https://github.com/llvm/llvm-project/issues/105904
crash
499e13514aaf2efdcd85520ade791ed635502adb
2024-08-23T22:57:57
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "b9d3da8c8d277a7fc2223c659122bb377a0e54e0", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 3011, 3017 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "isOperandGatherNode" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit b9d3da8c8d277a7fc2223c659122bb377a0e54e0 Author: Alexey Bataev <[email protected]> Date: Mon Aug 26 04:31:44 2024 -0700 [SLP]Fix PR105904: the root node might be a gather node without user for reductions. Before checking the user components of the gather/buildvector nodes, need to check if the node has users at all. Root nodes might not have users, if it is a node for the reduction. Fixes https://github.com/llvm/llvm-project/issues/105904 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 949579772b94..def73e8d0c0d 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3011,7 +3011,8 @@ private: } bool isOperandGatherNode(const EdgeInfo &UserEI) const { - return isGather() && UserTreeIndices.front().EdgeIdx == UserEI.EdgeIdx && + return isGather() && (Idx > 0 || !UserTreeIndices.empty()) && + UserTreeIndices.front().EdgeIdx == UserEI.EdgeIdx && UserTreeIndices.front().UserTE == UserEI.UserTE; }
[ { "file": "llvm/test/Transforms/SLPVectorizer/RISCV/gather-node-with-no-users.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=riscv64-unknown-linux-gnu -mattr=+v,+zvl512b < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %c) {\nentry:\n %arrayidx8.5.3 = getelementptr i8, ptr %c, i64 222\n %0 = load i8, ptr %arrayidx8.5.3, align 1\n %arrayidx8.7.3 = getelementptr i8, ptr %c, i64 228\n %1 = load i8, ptr %arrayidx8.7.3, align 1\n %arrayidx8.434 = getelementptr i8, ptr %c, i64 276\n %2 = load i8, ptr %arrayidx8.434, align 1\n %arrayidx8.1.4 = getelementptr i8, ptr %c, i64 279\n %3 = load i8, ptr %arrayidx8.1.4, align 1\n %arrayidx8.2.4 = getelementptr i8, ptr %c, i64 282\n %4 = load i8, ptr %arrayidx8.2.4, align 1\n %arrayidx8.3.4 = getelementptr i8, ptr %c, i64 285\n %5 = load i8, ptr %arrayidx8.3.4, align 1\n %arrayidx8.4.4 = getelementptr i8, ptr %c, i64 288\n %6 = load i8, ptr %arrayidx8.4.4, align 1\n %7 = load i8, ptr %c, align 1\n %8 = load i8, ptr %c, align 1\n %arrayidx8.536 = getelementptr i8, ptr %c, i64 345\n %9 = load i8, ptr %arrayidx8.536, align 1\n %arrayidx8.1.5 = getelementptr i8, ptr %c, i64 348\n %10 = load i8, ptr %arrayidx8.1.5, align 1\n %arrayidx8.2.5 = getelementptr i8, ptr %c, i64 351\n %11 = load i8, ptr %arrayidx8.2.5, align 1\n %arrayidx8.3.5 = getelementptr i8, ptr %c, i64 354\n %12 = load i8, ptr %arrayidx8.3.5, align 1\n %arrayidx8.4.5 = getelementptr i8, ptr %c, i64 357\n %13 = load i8, ptr %arrayidx8.4.5, align 1\n %arrayidx8.5.5 = getelementptr i8, ptr %c, i64 360\n %14 = load i8, ptr %arrayidx8.5.5, align 1\n %arrayidx8.6.5 = getelementptr i8, ptr %c, i64 363\n %15 = load i8, ptr %arrayidx8.6.5, align 1\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %entry\n %a.promoted2226 = phi i8 [ 0, %entry ], [ %or18.6.5, %for.cond ]\n %or18.7.3 = or i8 %0, %1\n %or18.435 = or i8 %or18.7.3, %2\n %or18.1.4 = or i8 %or18.435, %3\n %or18.2.4 = or i8 %or18.1.4, %4\n %or18.3.4 = or i8 %or18.2.4, %5\n %or18.4.4 = or i8 %or18.3.4, %6\n %or18.5.4 = or i8 %or18.4.4, %7\n %or18.6.4 = or i8 %or18.5.4, %8\n %or18.537 = or i8 %or18.6.4, %9\n %or18.1.5 = or i8 %or18.537, %10\n %or18.2.5 = or i8 %or18.1.5, %11\n %or18.3.5 = or i8 %or18.2.5, %12\n %or18.4.5 = or i8 %or18.3.5, %13\n %or18.5.5 = or i8 %or18.4.5, %14\n %or18.6.5 = or i8 %or18.5.5, %15\n br label %for.cond\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLP Vectorizer] Assertion `!empty()' failed.", "body": "Testcase:\r\n```llvm ir\r\n ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @b(ptr %c) #0 {\r\nentry:\r\n %arrayidx8.5.3 = getelementptr i8, ptr %c, i64 222\r\n %0 = load i8, ptr %arrayidx8.5.3, align 1\r\n %arrayidx8.7.3 = getelementptr i8, ptr %c, i64 228\r\n %1 = load i8, ptr %arrayidx8.7.3, align 1\r\n %arrayidx8.434 = getelementptr i8, ptr %c, i64 276\r\n %2 = load i8, ptr %arrayidx8.434, align 1\r\n %arrayidx8.1.4 = getelementptr i8, ptr %c, i64 279\r\n %3 = load i8, ptr %arrayidx8.1.4, align 1\r\n %arrayidx8.2.4 = getelementptr i8, ptr %c, i64 282\r\n %4 = load i8, ptr %arrayidx8.2.4, align 1\r\n %arrayidx8.3.4 = getelementptr i8, ptr %c, i64 285\r\n %5 = load i8, ptr %arrayidx8.3.4, align 1\r\n %arrayidx8.4.4 = getelementptr i8, ptr %c, i64 288\r\n %6 = load i8, ptr %arrayidx8.4.4, align 1\r\n %7 = load i8, ptr %c, align 1\r\n %8 = load i8, ptr %c, align 1\r\n %arrayidx8.536 = getelementptr i8, ptr %c, i64 345\r\n %9 = load i8, ptr %arrayidx8.536, align 1\r\n %arrayidx8.1.5 = getelementptr i8, ptr %c, i64 348\r\n %10 = load i8, ptr %arrayidx8.1.5, align 1\r\n %arrayidx8.2.5 = getelementptr i8, ptr %c, i64 351\r\n %11 = load i8, ptr %arrayidx8.2.5, align 1\r\n %arrayidx8.3.5 = getelementptr i8, ptr %c, i64 354\r\n %12 = load i8, ptr %arrayidx8.3.5, align 1\r\n %arrayidx8.4.5 = getelementptr i8, ptr %c, i64 357\r\n %13 = load i8, ptr %arrayidx8.4.5, align 1\r\n %arrayidx8.5.5 = getelementptr i8, ptr %c, i64 360\r\n %14 = load i8, ptr %arrayidx8.5.5, align 1\r\n %arrayidx8.6.5 = getelementptr i8, ptr %c, i64 363\r\n %15 = load i8, ptr %arrayidx8.6.5, align 1\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond, %entry\r\n %a.promoted2226 = phi i8 [ 0, %entry ], [ %or18.6.5, %for.cond ]\r\n %or18.7.3 = or i8 %0, %1\r\n %or18.435 = or i8 %or18.7.3, %2\r\n %or18.1.4 = or i8 %or18.435, %3\r\n %or18.2.4 = or i8 %or18.1.4, %4\r\n %or18.3.4 = or i8 %or18.2.4, %5\r\n %or18.4.4 = or i8 %or18.3.4, %6\r\n %or18.5.4 = or i8 %or18.4.4, %7\r\n %or18.6.4 = or i8 %or18.5.4, %8\r\n %or18.537 = or i8 %or18.6.4, %9\r\n %or18.1.5 = or i8 %or18.537, %10\r\n %or18.2.5 = or i8 %or18.1.5, %11\r\n %or18.3.5 = or i8 %or18.2.5, %12\r\n %or18.4.5 = or i8 %or18.3.5, %13\r\n %or18.5.5 = or i8 %or18.4.5, %14\r\n %or18.6.5 = or i8 %or18.5.5, %15\r\n br label %for.cond\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+relax,+xsifivecflushdlone,+zicsr,+zve32x,+zve64x,+zvl1024b,+zvl128b,+zvl256b,+zvl32b,+zvl512b,+zvl64b,-a,-b,-c,-d,-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,-f,-h,-m,-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,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-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,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zve32f,-zve64d,-zve64f,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl65536b,-zvl8192b\" }\r\n```\r\nGodbolt: https://godbolt.org/z/Thhajqn9q\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 -S reduced.ll\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/include/llvm/ADT/SmallVector.h:317: const T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::front() const [with T = llvm::slpvectorizer::BoUpSLP::EdgeInfo; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = const llvm::slpvectorizer::BoUpSLP::EdgeInfo&]: Assertion `!empty()' 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=slp-vectorizer -S reduced.ll\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"b\"\r\n #0 0x00005da37ad02b80 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300eb80)\r\n #1 0x00005da37acfff9f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300bf9f)\r\n #2 0x00005da37ad000f5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000733cc0242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000733cc02969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000733cc02969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x0000733cc02969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000733cc0242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x0000733cc02287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x0000733cc022871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000733cc0239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005da379da2beb llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20aebeb)\r\n#12 0x00005da379d9e086 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20aa086)\r\n#13 0x00005da379da2372 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20ae372)\r\n#14 0x00005da379d9db47 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20a9b47)\r\n#15 0x00005da379d9c510 llvm::slpvectorizer::BoUpSLP::createBuildVector(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20a8510)\r\n#16 0x00005da379d9cf7b llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20a8f7b)\r\n#17 0x00005da379da62cf 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*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20b22cf)\r\n#18 0x00005da379db2bd5 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#19 0x00005da379db5599 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+0x20c1599)\r\n#20 0x00005da379db9a68 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20c5a68)\r\n#21 0x00005da379dbd75c llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20c975c)\r\n#22 0x00005da379dc41b0 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#23 0x00005da379dc4da2 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20d0da2)\r\n#24 0x00005da378b51cf6 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+0xe5dcf6)\r\n#25 0x00005da37ab0e94f 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+0x2e1a94f)\r\n#26 0x00005da378b544f6 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+0xe604f6)\r\n#27 0x00005da37ab0d6cb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e196cb)\r\n#28 0x00005da378b50796 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+0xe5c796)\r\n#29 0x00005da37ab0b70d 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+0x2e1770d)\r\n#30 0x00005da37837ae56 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+0x686e56)\r\n#31 0x00005da37836cbe1 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x678be1)\r\n#32 0x0000733cc0229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#33 0x0000733cc0229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#34 0x0000733cc0229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#35 0x00005da378362f95 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66ef95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nFound via fuzzer", "author": "patrick-rivos", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": [ [ 35, 40 ], [ 44, 49 ] ], "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": [ "VPTypeAnalysis::inferScalarTypeForRecipe" ], "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
80836
https://github.com/llvm/llvm-project/issues/80836
crash
ea2d9383a23ca17b9240ad64c2adc5f2b5a73dc0
2024-02-06T14:26:26
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "1c10821022f1799452065fb57474e894e2562b7f", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 2010, 2025 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "getCost" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 1c10821022f1799452065fb57474e894e2562b7f Author: David Sherwood <[email protected]> Date: Wed Feb 14 16:07:51 2024 +0000 [LoopVectorize] Fix divide-by-zero bug (#80836) (#81721) When attempting to use the estimated trip count to refine the costs of the runtime memory checks we should also check for sane trip counts to prevent divide-by-zero faults on some platforms. Fixes #80836 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b39bf21cacdb..98b177cf5d2d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2010,16 +2010,18 @@ public: BestTripCount = *EstimatedTC; } + BestTripCount = std::max(BestTripCount, 1U); InstructionCost NewMemCheckCost = MemCheckCost / BestTripCount; // Let's ensure the cost is always at least 1. NewMemCheckCost = std::max(*NewMemCheckCost.getValue(), (InstructionCost::CostType)1); - LLVM_DEBUG(dbgs() - << "We expect runtime memory checks to be hoisted " - << "out of the outer loop. Cost reduced from " - << MemCheckCost << " to " << NewMemCheckCost << '\n'); + if (BestTripCount > 1) + LLVM_DEBUG(dbgs() + << "We expect runtime memory checks to be hoisted " + << "out of the outer loop. Cost reduced from " + << MemCheckCost << " to " << NewMemCheckCost << '\n'); MemCheckCost = NewMemCheckCost; }
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/low_trip_memcheck_cost.ll", "commands": [ "opt -p loop-vectorize -debug-only=loop-vectorize -S -disable-output < %s 2>&1" ], "tests": [ { "test_name": "outer_known_tc3_full_range_checks", "test_body": "target triple = \"aarch64-unknown-linux-gnu\"\n\ndefine void @outer_known_tc3_full_range_checks(ptr nocapture noundef %dst, ptr nocapture noundef readonly %src, i64 noundef %n) {\nentry:\n br label %outer.loop\n\nouter.loop: ; preds = %inner.exit, %entry\n %outer.iv = phi i64 [ 0, %entry ], [ %outer.iv.next, %inner.exit ]\n %0 = mul nsw i64 %outer.iv, %n\n br label %inner.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %iv.inner = phi i64 [ 0, %outer.loop ], [ %iv.inner.next, %inner.loop ]\n %1 = add nuw nsw i64 %iv.inner, %0\n %arrayidx.us = getelementptr inbounds i32, ptr %src, i64 %1\n %2 = load i32, ptr %arrayidx.us, align 4\n %arrayidx8.us = getelementptr inbounds i32, ptr %dst, i64 %1\n %3 = load i32, ptr %arrayidx8.us, align 4\n %add9.us = add nsw i32 %3, %2\n store i32 %add9.us, ptr %arrayidx8.us, align 4\n %iv.inner.next = add nuw nsw i64 %iv.inner, 1\n %inner.exit.cond = icmp eq i64 %iv.inner.next, %n\n br i1 %inner.exit.cond, label %inner.exit, label %inner.loop\n\ninner.exit: ; preds = %inner.loop\n %outer.iv.next = add nuw nsw i64 %outer.iv, 1\n %outer.exit.cond = icmp eq i64 %outer.iv.next, 3\n br i1 %outer.exit.cond, label %outer.exit, label %outer.loop\n\nouter.exit: ; preds = %inner.exit\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "outer_pgo_minus1", "test_body": "target triple = \"aarch64-unknown-linux-gnu\"\n\ndefine void @outer_pgo_minus1(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %m, i64 noundef %n) {\nentry:\n br label %outer.loop\n\nouter.loop: ; preds = %inner.exit, %entry\n %outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]\n %mul.us = mul nsw i64 %outer.iv, %n\n br label %inner.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]\n %add.us = add nuw nsw i64 %inner.iv, %mul.us\n %arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us\n %0 = load i8, ptr %arrayidx.us, align 1\n %arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us\n %1 = load i8, ptr %arrayidx7.us, align 1\n %add9.us = add i8 %1, %0\n store i8 %add9.us, ptr %arrayidx7.us, align 1\n %inner.iv.next = add nuw nsw i64 %inner.iv, 1\n %exitcond.not = icmp eq i64 %inner.iv.next, %n\n br i1 %exitcond.not, label %inner.exit, label %inner.loop\n\ninner.exit: ; preds = %inner.loop\n %outer.iv.next = add nuw nsw i64 %outer.iv, 1\n %exitcond26.not = icmp eq i64 %outer.iv.next, %m\n br i1 %exitcond26.not, label %outer.exit, label %outer.loop, !prof !0\n\nouter.exit: ; preds = %inner.exit\n ret void\n}\n\n!0 = !{!\"branch_weights\", i32 1, i32 -1}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Unhandled Floating point exception with loop-vectorize ", "body": "Run opt with -passes=loop-vectorize \r\n\r\nhttps://godbolt.org/z/s3PWY3vhE\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine ptr addrspace(1) @wombat(i64 %arg, ptr addrspace(1) %arg1) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb4, %bb\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb3, %bb2\r\n %phi = phi i64 [ 0, %bb2 ], [ %add, %bb3 ]\r\n %add = add i64 %phi, 1\r\n %load = load i8, ptr addrspace(1) %arg1, align 1\r\n %shl = shl i64 0, 0\r\n store i16 0, ptr addrspace(1) null, align 2\r\n %icmp = icmp ult i64 %phi, %arg\r\n br i1 %icmp, label %bb3, label %bb4\r\n\r\nbb4: ; preds = %bb3\r\n br i1 false, label %bb5, label %bb2, !prof !0\r\n\r\nbb5: ; preds = %bb4\r\n ret ptr addrspace(1) null\r\n}\r\n\r\n!0 = !{!\"branch_weights\", i32 1, i32 -1}\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "DaniilSuchkov", "body": "It started failing after 962fbafecf4730ba84a3b9fd7a662a5c30bb2c7c\r\n```\r\nAuthor: David Sherwood <[email protected]>\r\nDate: Fri Jan 26 14:43:48 2024 +0000\r\n\r\n [LoopVectorize] Refine runtime memory check costs when there is an outer loop (#76034)\r\n\r\n When we generate runtime memory checks for an inner loop it's\r\n possible that these checks are invariant in the outer loop and\r\n so will get hoisted out. In such cases, the effective cost of\r\n the checks should reduce to reflect the outer loop trip count.\r\n\r\n This fixes a 25% performance regression introduced by commit\r\n\r\n 49b0e6dcc296792b577ae8f0f674e61a0929b99d\r\n\r\n when building the SPEC2017 x264 benchmark with PGO, where we\r\n decided the inner loop trip count wasn't high enough to warrant\r\n the (incorrect) high cost of the runtime checks. Also, when\r\n runtime memory checks consist entirely of diff checks these are\r\n likely to be outer loop invariant.\r\n```\r\nWe have a division by 0 here https://github.com/llvm/llvm-project/commit/962fbafecf4730ba84a3b9fd7a662a5c30bb2c7c#diff-da321d454a7246f8ae276bf1db2782bf26b5210b8133cb59e4d7fd45d0905decR2114 because `getLoopEstimatedTripCount(OuterLoop)` just above that line returns 0." }, { "author": "david-arm", "body": "OK thanks for raising this issue - I'll take a look this morning!" }, { "author": "david-arm", "body": "I have a fix in review - https://github.com/llvm/llvm-project/pull/81721" } ] }
true
null
76713
https://github.com/llvm/llvm-project/issues/76713
miscompilation
71bcef0b0bf55a96f85b2f323b0beb13ad8e2caa
2024-01-02T12:49:15
[ "llvm/test/Transforms/ConstraintElimination" ]
{ "fix_commit": "3c127e83c07c3791e86413c22a414a030d4302e3", "components": [ "ConstraintElimination" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ [ 366, 371 ], [ 569, 578 ] ], "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ "add", "decompose", "mul" ], "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 3c127e83c07c3791e86413c22a414a030d4302e3 Author: Florian Hahn <[email protected]> Date: Tue Jan 2 22:05:57 2024 +0000 [ConstraintElim] Replace NUWSub decomp with recursive decomp of ops. The current patterns for NUWSub decompositions do not handle negative constants correctly at the moment (causing #76713). Replace the incorrect pattern by more general code that recursively decomposes the operands and then combines the results. This is already done in most other places that handle operators like add/mul. This means we fall back to the general constant handling code (fixes the mis-compile) while also being able to support reasoning about decomposable expressions in the SUB operands. Fixes https://github.com/llvm/llvm-project/issues/76713. diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 49ac1e96e255..06c87bd6dc37 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -366,6 +366,13 @@ struct Decomposition { append_range(Vars, Other.Vars); } + void sub(const Decomposition &Other) { + Decomposition Tmp = Other; + Tmp.mul(-1); + add(Tmp.Offset); + append_range(Vars, Tmp.Vars); + } + void mul(int64_t Factor) { Offset = multiplyWithOverflow(Offset, Factor); for (auto &Var : Vars) @@ -569,10 +576,12 @@ static Decomposition decompose(Value *V, return Result; } - if (match(V, m_NUWSub(m_Value(Op0), m_ConstantInt(CI))) && canUseSExt(CI)) - return {-1 * CI->getSExtValue(), {{1, Op0}}}; - if (match(V, m_NUWSub(m_Value(Op0), m_Value(Op1)))) - return {0, {{1, Op0}, {-1, Op1}}}; + if (match(V, m_NUWSub(m_Value(Op0), m_Value(Op1)))) { + auto ResA = decompose(Op0, Preconditions, IsSigned, DL); + auto ResB = decompose(Op1, Preconditions, IsSigned, DL); + ResA.sub(ResB); + return ResA; + } return {V, IsKnownNonNegative}; }
[ { "file": "llvm/test/Transforms/ConstraintElimination/sub-nuw.ll", "commands": [ "opt -passes=constraint-elimination -S %s" ], "tests": [ { "test_name": "pr76713", "test_body": "define i1 @pr76713(i16 %i1, i16 %i3) {\nentry:\n %c1 = icmp ult i16 %i1, -1\n %c2 = icmp uge i16 %i1, -3\n %c3 = icmp ult i16 %i3, 2\n %and = and i1 %c1, %c2\n %and.2 = and i1 %and, %c3\n br i1 %and, label %then, label %else\n\nthen: ; preds = %entry\n %sub = sub nuw nsw i16 %i1, -3\n %arrayidx.idx = mul nuw nsw i16 %i3, 4\n %i6 = add nuw nsw i16 %arrayidx.idx, %sub\n %c4 = icmp ult i16 12, %i6\n ret i1 %c4\n\nelse: ; preds = %entry\n ret i1 false\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sub_nuw_chained_negative_constants", "test_body": "declare void @use(i1)\n\ndefine void @sub_nuw_chained_negative_constants(i8 %a) {\nentry:\n %sub1 = sub nuw i8 %a, 10\n %sub2 = sub nuw i8 %sub1, -126\n %c.1 = icmp ugt i8 %sub2, 20\n br i1 %c.1, label %exit.1, label %exit.2\n\nexit.1: ; preds = %entry\n %c.2 = icmp ugt i8 %a, -96\n call void @use(i1 %c.2)\n %c.3 = icmp ugt i8 %a, -95\n call void @use(i1 %c.3)\n ret void\n\nexit.2: ; preds = %entry\n %c.4 = icmp ugt i8 %a, -96\n call void @use(i1 %c.4)\n %c.5 = icmp ugt i8 %a, -95\n call void @use(i1 %c.5)\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sub_nuw_neg_i16", "test_body": "define i1 @sub_nuw_neg_i16(i16 %a) {\nentry:\n %neg2 = sub nuw i16 %a, -305\n %c.1 = icmp ugt i16 0, %neg2\n br i1 %c.1, label %exit.1, label %exit.2\n\nexit.1: ; preds = %entry\n %c.2 = icmp ugt i16 %a, 0\n ret i1 %c.2\n\nexit.2: ; preds = %entry\n %c.3 = icmp ugt i16 %a, 0\n ret i1 %c.3\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sub_nuw_chained_positive_constants", "test_body": "declare void @use(i1)\n\ndefine void @sub_nuw_chained_positive_constants(i16 %a) {\nentry:\n %sub1 = sub nuw i16 %a, 10\n %sub2 = sub nuw i16 %sub1, 20\n %c.1 = icmp ugt i16 %sub2, 90\n br i1 %c.1, label %exit.1, label %exit.2\n\nexit.1: ; preds = %entry\n %c.2 = icmp ugt i16 %a, 120\n call void @use(i1 %c.2)\n %c.3 = icmp ugt i16 %a, 121\n call void @use(i1 %c.3)\n ret void\n\nexit.2: ; preds = %entry\n %c.4 = icmp ugt i16 %a, 120\n call void @use(i1 %c.4)\n %c.5 = icmp ugt i16 %a, 121\n call void @use(i1 %c.5)\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Miscompile with opt -passes=\"constraint-elimination\"", "body": "llvm commit: 5842dfe34d89\r\nReproduce with: ```opt -passes=\"constraint-elimination\" bbi-90501.ll -S -o -```\r\n[bbi-90501.ll.gz](https://github.com/llvm/llvm-project/files/13810077/bbi-90501.ll.gz)\r\n\r\nThere are two nested loops in the input that should finish and then we should end up at\r\n```\r\nbb.2: ; preds = %bb.1\r\n ret i16 0\r\n```\r\nbut with constraint-elimination the condition in bb.5 is changed to\r\n```\r\n %i10 = or i1 true, %i9\r\n br i1 %i10, label %bb.7, label %bb.6\r\n```\r\nso we will go to\r\n```\r\nbb.7: ; preds = %bb.5\r\n ret i16 1\r\n```\r\ninstead.", "author": "mikaelholmen", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "mikaelholmen", "body": "This starts happening with e6a1657fa30c747f4412fc47f567660ebe861a9e\r\n```\r\n[ConstraintElim] Add A < B if A is an increasing phi for A != B.\r\n```\r\n@fhahn : any idea what's up?" }, { "author": "fhahn", "body": "Looks like an issue with `sub` decomposition with negative constants, preparing a fix." }, { "author": "mikaelholmen", "body": "Thanks for the quick fix! I've verified it solves the problem I saw." }, { "author": "fhahn", "body": "@mikaelholmen thanks for the reproducer!" }, { "author": "fhahn", "body": "(appreciated as always, thanks for your extensive testing)" } ] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 6886, 6892 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ "llvm::getUnderlyingObjectAggressive" ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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}", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": 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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.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/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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;.", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": 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/Utils/Local.cpp": [ [ 3508, 3513 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.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/Utils/Local.cpp": [ "llvm::patchReplacementInstruction" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
112476
https://github.com/llvm/llvm-project/issues/112476
miscompilation
3ef630ac339f31686290f9460a40eb2a9c9f5bd0
2024-10-16T04:35:15
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "09361953116770b646decf5820a9455ada2ba4fc", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 1738, 1744 ], [ 1844, 1850 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 1448, 1453 ] ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ "InstCombinerImpl::foldICmpAndConstConst", "InstCombinerImpl::foldICmpAndShift" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "InstCombinerImpl::foldSelectEqualityTest" ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 09361953116770b646decf5820a9455ada2ba4fc Author: Yingwei Zheng <[email protected]> Date: Wed Oct 16 19:13:52 2024 +0800 [InstCombine] Drop `samesign` in InstCombine (#112480) Closes https://github.com/llvm/llvm-project/issues/112476. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 7129499e0f8f..18a6fdcec172 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1738,7 +1738,7 @@ Instruction *InstCombinerImpl::foldICmpAndShift(ICmpInst &Cmp, // Compute X & (C2 << Y). Value *NewAnd = Builder.CreateAnd(Shift->getOperand(0), NewShift); - return replaceOperand(Cmp, 0, NewAnd); + return new ICmpInst(Cmp.getPredicate(), NewAnd, Cmp.getOperand(1)); } return nullptr; @@ -1844,7 +1844,7 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp, /*HasNUW=*/true), One, Or->getName()); Value *NewAnd = Builder.CreateAnd(A, NewOr, And->getName()); - return replaceOperand(Cmp, 0, NewAnd); + return new ICmpInst(Cmp.getPredicate(), NewAnd, Cmp.getOperand(1)); } } } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 8be2eeed84ad..623694663aa1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1448,6 +1448,7 @@ Instruction *InstCombinerImpl::foldSelectEqualityTest(SelectInst &Sel) { m_c_SpecificICmp(ICmpInst::ICMP_EQ, m_Specific(X), m_Specific(Y)))) return nullptr; + cast<ICmpInst>(XeqY)->setSameSign(false); return replaceInstUsesWith(Sel, XeqY); }
[ { "file": "llvm/test/Transforms/InstCombine/icmp-and-shift.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_shr_and_1_ne_0", "test_body": "define i1 @test_shr_and_1_ne_0(i32 %a, i32 %b) {\n %shr = lshr i32 %a, %b\n %and = and i32 %shr, 1\n %cmp = icmp ne i32 %and, 0\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/icmp-equality-test.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "icmp_equality_test_swift_optional_pointers", "test_body": "define i1 @icmp_equality_test_swift_optional_pointers(i64 %X, i64 %Y) {\nentry:\n %XeqC = icmp eq i64 %X, 0\n %YeqC = icmp eq i64 %Y, 0\n %either = select i1 %XeqC, i1 true, i1 %YeqC\n %both = select i1 %XeqC, i1 %YeqC, i1 false\n %XeqY = icmp eq i64 %X, %Y\n %equal = select i1 %either, i1 %both, i1 %XeqY\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_wrong_equal", "test_body": "define i1 @icmp_equality_test_wrong_equal(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, %Y\n %not.YeqZ = xor i1 %YeqZ, true\n %and = select i1 %not.YeqZ, i1 %XeqY, i1 false\n %equal = select i1 %XeqZ, i1 %and, i1 %YeqZ\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_commute_icmp1", "test_body": "define i1 @icmp_equality_test_commute_icmp1(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %Z, %X\n %YeqZ = icmp eq i64 %Z, %Y\n %XeqY = icmp eq i64 %Y, %X\n %not.YeqZ = xor i1 %YeqZ, true\n %and = select i1 %not.YeqZ, i1 %XeqY, i1 false\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_wrong_cmp", "test_body": "define i1 @icmp_equality_test_wrong_cmp(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, 999\n %not.YeqZ = xor i1 %YeqZ, true\n %and = select i1 %not.YeqZ, i1 %XeqY, i1 false\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_wrong_constant", "test_body": "define i1 @icmp_equality_test_wrong_constant(i64 %X, i64 %Y) {\nentry:\n %XeqC = icmp eq i64 %X, 0\n %YeqC = icmp eq i64 %Y, 999\n %XeqY = icmp eq i64 %X, %Y\n %not.YeqC = xor i1 %YeqC, true\n %and = select i1 %not.YeqC, i1 %XeqY, i1 false\n %equal = select i1 %XeqC, i1 %YeqC, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_vector", "test_body": "define <2 x i1> @icmp_equality_test_vector(<2 x i64> %X, <2 x i64> %Y) {\nentry:\n %XeqC = icmp eq <2 x i64> %X, <i64 123, i64 456>\n %YeqC = icmp eq <2 x i64> %Y, <i64 123, i64 456>\n %XeqY = icmp eq <2 x i64> %X, %Y\n %not.YeqC = xor <2 x i1> %YeqC, splat (i1 true)\n %and = select <2 x i1> %not.YeqC, <2 x i1> %XeqY, <2 x i1> zeroinitializer\n %equal = select <2 x i1> %XeqC, <2 x i1> %YeqC, <2 x i1> %and\n ret <2 x i1> %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_commute_select2", "test_body": "define i1 @icmp_equality_test_commute_select2(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, %Y\n %not.XeqZ = xor i1 %XeqZ, true\n %and = select i1 %YeqZ, i1 false, i1 %XeqY\n %equal = select i1 %not.XeqZ, i1 %and, i1 %YeqZ\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_constant", "test_body": "define i1 @icmp_equality_test_constant(i42 %X, i42 %Y) {\nentry:\n %XeqC = icmp eq i42 %X, -42\n %YeqC = icmp eq i42 %Y, -42\n %XeqY = icmp eq i42 %X, %Y\n %not.YeqC = xor i1 %YeqC, true\n %and = select i1 %not.YeqC, i1 %XeqY, i1 false\n %equal = select i1 %XeqC, i1 %YeqC, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_wrong_and", "test_body": "define i1 @icmp_equality_test_wrong_and(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, %Y\n %not.YeqZ = xor i1 %YeqZ, true\n %and = select i1 %not.YeqZ, i1 false, i1 %XeqY\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test", "test_body": "define i1 @icmp_equality_test(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, %Y\n %not.YeqZ = xor i1 %YeqZ, true\n %and = select i1 %not.YeqZ, i1 %XeqY, i1 false\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_missing_not", "test_body": "define i1 @icmp_equality_test_missing_not(i64 %X, i64 %Y, i64 %Z) {\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, %Y\n %and = select i1 %YeqZ, i1 %XeqY, i1 false\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_constant_samesign", "test_body": "define i1 @icmp_equality_test_constant_samesign(i42 %X, i42 %Y) {\nentry:\n %XeqC = icmp eq i42 %X, -42\n %YeqC = icmp eq i42 %Y, -42\n %XeqY = icmp samesign eq i42 %X, %Y\n %not.YeqC = xor i1 %YeqC, true\n %and = select i1 %not.YeqC, i1 %XeqY, i1 false\n %equal = select i1 %XeqC, i1 %YeqC, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_commute_icmp2", "test_body": "define i1 @icmp_equality_test_commute_icmp2(i64 %X, i64 %Y, i64 %Z) {\n %XeqZ = icmp eq i64 %Z, %X\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %Y, %X\n %not.YeqZ = xor i1 %YeqZ, true\n %and = select i1 %not.YeqZ, i1 %XeqY, i1 false\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_equality_test_commute_select1", "test_body": "define i1 @icmp_equality_test_commute_select1(i64 %X, i64 %Y, i64 %Z) {\nentry:\n %XeqZ = icmp eq i64 %X, %Z\n %YeqZ = icmp eq i64 %Y, %Z\n %XeqY = icmp eq i64 %X, %Y\n %and = select i1 %YeqZ, i1 false, i1 %XeqY\n %equal = select i1 %XeqZ, i1 %YeqZ, i1 %and\n ret i1 %equal\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "icmp_and_or_lshr", "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_and_or_lshr(i32 %x, i32 %y) {\n %shf = lshr i32 %x, %y\n %or = or i32 %shf, %x\n %and = and i32 %or, 1\n %ret = icmp ne i32 %and, 0\n ret i1 %ret\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped in `InstCombinerImpl::foldICmpAndConstConst`", "body": "Reproducer:\r\n```\r\ndefine i1 @src(i32 %x, i32 %y) {\r\n %shf = lshr i32 %x, %y\r\n %or = or i32 %shf, %x\r\n %and = and i32 %or, 1\r\n %ret = icmp samesign ne i32 %and, 0\r\n ret i1 %ret\r\n}\r\n\r\ndefine i1 @tgt(i32 %x, i32 %y) {\r\n %shf1 = shl nuw i32 1, %y\r\n %or2 = or i32 %shf1, 1\r\n %and3 = and i32 %x, %or2\r\n %ret = icmp samesign ne i32 %and3, 0\r\n ret i1 %ret\r\n}\r\n```\r\n```\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #x80000000 (2147483648, -2147483648)\r\ni32 %y = #x0000001f (31)\r\n\r\nSource:\r\ni32 %shf = #x00000001 (1)\r\ni32 %or = #x80000001 (2147483649, -2147483647)\r\ni32 %and = #x00000001 (1)\r\ni1 %ret = #x1 (1)\r\n\r\nTarget:\r\ni32 %shf1 = #x80000000 (2147483648, -2147483648)\r\ni32 %or2 = #x80000001 (2147483649, -2147483647)\r\ni32 %and3 = #x80000000 (2147483648, -2147483648)\r\ni1 %ret = poison\r\nSource value: #x1 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
84025
https://github.com/llvm/llvm-project/issues/84025
miscompilation
f51ade25b9205efee09a4915031848cebe772805
2024-03-05T15:07:55
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "e96c0c1d5e0a9916098b1a31acb006ea6c1108fb", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": [ [ 2167, 2180 ] ], "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": [ "collectInsertionElements" ], "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit e96c0c1d5e0a9916098b1a31acb006ea6c1108fb Author: Quentin Dian <[email protected]> Date: Wed Mar 6 06:16:28 2024 +0800 [InstCombine] Fix shift calculation in InstCombineCasts (#84027) Fixes #84025. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 33ed1d557537..45afa6363ae0 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2167,14 +2167,14 @@ static bool collectInsertionElements(Value *V, unsigned Shift, Type *ElementIntTy = IntegerType::get(C->getContext(), ElementSize); for (unsigned i = 0; i != NumElts; ++i) { - unsigned ShiftI = Shift + i * ElementSize; + unsigned ShiftI = i * ElementSize; Constant *Piece = ConstantFoldBinaryInstruction( Instruction::LShr, C, ConstantInt::get(C->getType(), ShiftI)); if (!Piece) return false; Piece = ConstantExpr::getTrunc(Piece, ElementIntTy); - if (!collectInsertionElements(Piece, ShiftI, Elements, VecEltTy, + if (!collectInsertionElements(Piece, ShiftI + Shift, Elements, VecEltTy, isBigEndian)) return false; }
[ { "file": "llvm/test/Transforms/InstCombine/bitcast.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "bitcast_from_single_element_pointer_vector_to_pointer", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\ntarget triple = \"x86_64-apple-darwin10.0.0\"\n\ndefine ptr @bitcast_from_single_element_pointer_vector_to_pointer(<1 x ptr> %ptrvec) {\n %ptr = bitcast <1 x ptr> %ptrvec to ptr\n ret ptr %ptr\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "bitcast_shl", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\ntarget triple = \"x86_64-apple-darwin10.0.0\"\n\ndefine <4 x i32> @bitcast_shl(i32 %arg) {\n %i = zext i32 %arg to i64\n %i1 = shl i64 %i, 32\n %i2 = or i64 %i1, 65\n %i3 = zext i64 %i2 to i128\n %i4 = shl i128 %i3, 64\n %i5 = bitcast i128 %i4 to <4 x i32>\n ret <4 x i32> %i5\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "select_bitcast_unsized_pointer", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\ntarget triple = \"x86_64-apple-darwin10.0.0\"\n\ndeclare void @f1()\n\ndeclare void @f2()\n\ndefine ptr @select_bitcast_unsized_pointer(i1 %c) {\n %s = select i1 %c, ptr @f1, ptr @f2\n ret ptr %s\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "InstCombine calculated a wrong `insertelement` instruction", "body": "I tried this IR:\r\n\r\n```llvm\r\ndefine <4 x i32> @src(i32 %arg) {\r\n %i = zext i32 %arg to i64\r\n %i1 = shl i64 %i, 32\r\n %i2 = or i64 %i1, 65\r\n %i3 = zext i64 %i2 to i128\r\n %i4 = shl i128 %i3, 64\r\n %i5 = bitcast i128 %i4 to <4 x i32>\r\n ret <4 x i32> %i5\r\n}\r\n\r\ndefine <4 x i32> @tgt(i32 %arg) {\r\n %i5 = insertelement <4 x i32> <i32 0, i32 0, i32 0, i32 poison>, i32 %arg, i64 3\r\n ret <4 x i32> %i5\r\n}\r\n```\r\n\r\nI expect `src` to be:\r\n\r\n```llvm\r\ndefine <4 x i32> @src(i32 %arg) {\r\n %i5 = insertelement <4 x i32> <i32 0, i32 0, i32 65, i32 poison>, i32 %arg, i64 3\r\n ret <4 x i32> %i5\r\n}\r\n```\r\n\r\nBut I'm getting the same instructions as `tgt`.\r\n\r\nGodbolt: https://llvm.godbolt.org/z/KnMEY4rTq\r\nAlive2: https://alive2.llvm.org/ce/z/7FIJNi\r\nFrom: https://github.com/rust-lang/rust/issues/121996", "author": "DianQK", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "cbeuw", "body": "Looks like this bug is almost 11 years old: https://github.com/llvm/llvm-project/commit/feb34713d531d1f48c37116e8cab84814202d057! Thanks for fixing" }, { "author": "DianQK", "body": "> Looks like this bug is almost 11 years old: [feb3471](https://github.com/llvm/llvm-project/commit/feb34713d531d1f48c37116e8cab84814202d057)! Thanks for fixing\r\n\r\nBased on my experience, we likely have many more latent bugs. :)" } ] }
true
null
129373
https://github.com/llvm/llvm-project/issues/129373
hang
88460137d97c0b8d3742203e0173ab9ed6c5c8a7
2025-03-01T09:39:32
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "5ddf40fa78705384966c22da78e12134df7bd723", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ [ 1579, 1584 ] ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [ "VectorCombine::scalarizeLoadExtract" ], "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 5ddf40fa78705384966c22da78e12134df7bd723 Author: Simon Pilgrim <[email protected]> Date: Sat Mar 1 16:54:22 2025 +0000 [VectorCombine] scalarizeLoadExtract - don't create scalar loads if any extract is waiting to be erased (#129375) If any extract is waiting to be erased, then bail out as this will distort the cost calculation and possibly lead to infinite loops. Fixes #129373 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index bb4e1c0f67e7..2e8458e2cd03 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -1579,6 +1579,11 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) { if (!UI || UI->getParent() != LI->getParent()) return false; + // If any extract is waiting to be erased, then bail out as this will + // distort the cost calculation and possibly lead to infinite loops. + if (UI->use_empty()) + return false; + // Check if any instruction between the load and the extract may modify // memory. if (LastCheckedInst->comesBefore(UI)) {
[ { "file": "llvm/test/Transforms/VectorCombine/X86/load-extractelement-scalarization.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=sse2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mattr=avx2" ], "tests": [ { "test_name": "multiple_extract", "test_body": "define void @multiple_extract(ptr %p) {\n %vp = load ptr, ptr %p, align 8\n %v = load <2 x i32>, ptr %vp, align 16\n %e0 = extractelement <2 x i32> %v, i64 0\n %e1 = extractelement <2 x i32> %v, i64 1\n store i32 %e0, ptr %p, align 4\n %p1 = getelementptr inbounds nuw i8, ptr %p, i64 4\n store i32 %e1, ptr %p1, align 4\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "unused_extract", "test_body": "define void @unused_extract(ptr %p) {\n %load = load <4 x float>, ptr %p, align 8\n %shuffle0 = shufflevector <4 x float> zeroinitializer, <4 x float> %load, <4 x i32> <i32 0, i32 4, i32 1, i32 5>\n %shuffle1 = shufflevector <4 x float> %shuffle0, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 poison, i32 poison>\n %extract = extractelement <4 x float> %load, i64 1\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VectorCombine] scalarizeLoadExtract - infinite loop if we scalarize a dead extract waiting to be erased", "body": "Reduced test case:\n\n```ll\ndefine void @infinite_loop(ptr %p0) {\n %load = load <4 x float>, ptr %p0, align 8\n %shuffle0 = shufflevector <4 x float> zeroinitializer, <4 x float> %load, <4 x i32> <i32 0, i32 4, i32 1, i32 5>\n %shuffle1 = shufflevector <4 x float> %shuffle0, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 poison, i32 poison>\n %extract = extractelement <4 x float> %load, i64 1\n ret void\n}\n```\n\nscalarizeLoadExtract iterates across all users of a load, and doesn't account for possible orders in the worklist that prevent unused instructions that use the load from being erased afterward.\n\nFix incoming", "author": "RKSimon", "labels": [ "release:backport", "vectorizers", "hang" ], "comments": [] }
true
null
122913
https://github.com/llvm/llvm-project/issues/122913
crash
195a1fc5b05d7a42b2e3fa383edb9a7e8b34a9c5
2025-01-14T15:11:18
[ "llvm/test/Analysis/ScalarEvolution" ]
{ "fix_commit": "137d706739653304294adef84ed758e3e498d975", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ [ 15328, 15333 ] ], "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::LoopGuards::collect" ], "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 137d706739653304294adef84ed758e3e498d975 Author: Julian Nagele <[email protected]> Date: Wed Jan 22 18:36:37 2025 +0000 [SCEV] Do not attempt to collect loop guards for loops without predecessor. (#123662) Attempting to collect loop guards for loops without a predecessor can lead to non-terminating recursion trying to construct a SCEV. Fixes https://github.com/llvm/llvm-project/issues/122913. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7673c3548175..210c7cab965e 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -15328,6 +15328,8 @@ ScalarEvolution::LoopGuards::collect(const Loop *L, ScalarEvolution &SE) { BasicBlock *Header = L->getHeader(); BasicBlock *Pred = L->getLoopPredecessor(); LoopGuards Guards(SE); + if (!Pred) + return Guards; SmallPtrSet<const BasicBlock *, 8> VisitedBlocks; collectFromBlock(SE, Guards, Header, Pred, VisitedBlocks); return Guards;
[ { "file": "llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll", "commands": [ "opt < %s -disable-output -passes=nary-reassociate --scalar-evolution-use-expensive-range-sharpening 2>&1" ], "tests": [ { "test_name": "pr122913", "test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine ptr @f(i32 %0) {\n switch i32 0, label %bb4 [\n i32 1, label %bb4\n i32 2, label %bb4\n i32 3, label %bb4\n i32 4, label %bb1\n i32 5, label %bb4\n i32 6, label %bb4\n ]\n\nbb: ; No predecessors!\n switch i32 0, label %bb4 [\n i32 0, label %bb4\n i32 1, label %bb1\n ]\n\nbb1: ; preds = %bb2, %bb, %1\n %2 = phi i32 [ %3, %bb2 ], [ 0, %bb ], [ 0, %1 ]\n switch i32 %0, label %bb3 [\n i32 0, label %bb2\n i32 1, label %bb2\n i32 2, label %bb2\n ]\n\nbb2: ; preds = %bb1, %bb1, %bb1\n %3 = add i32 %2, 1\n %4 = icmp ult i32 %0, 0\n br i1 %4, label %bb1, label %bb4\n\nbb3: ; preds = %bb1\n unreachable\n\nbb4: ; preds = %bb2, %bb, %bb, %1, %1, %1, %1, %1, %1\n ret ptr null\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SCEV] Another SEGV/stack overflow in LoopGuards", "body": "Similar to https://github.com/llvm/llvm-project/issues/120615. Looks like the fix wasn't a complete one. Here is an example:\n\n```llvm\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine ptr @f(i32 %0) {\n switch i32 0, label %bb4 [\n i32 1, label %bb4\n i32 2, label %bb4\n i32 3, label %bb4\n i32 4, label %bb1\n i32 5, label %bb4\n i32 6, label %bb4\n ]\n\nbb: ; No predecessors!\n switch i32 0, label %bb4 [\n i32 0, label %bb4\n i32 1, label %bb1\n ]\n\nbb1: ; preds = %bb2, %bb, %1\n %2 = phi i32 [ %3, %bb2 ], [ 0, %bb ], [ 0, %1 ]\n switch i32 %0, label %bb3 [\n i32 0, label %bb2\n i32 1, label %bb2\n i32 2, label %bb2\n ]\n\nbb2: ; preds = %bb1, %bb1, %bb1\n %3 = add i32 %2, 1\n %4 = icmp ult i32 %0, 0\n br i1 %4, label %bb1, label %bb4\n\nbb3: ; preds = %bb1\n unreachable\n\nbb4: ; preds = %bb2, %bb, %bb, %1, %1, %1, %1, %1, %1\n ret ptr null\n}\n```\nCrashes with the same command line `opt -passes=nary-reassociate --scalar-evolution-use-expensive-range-sharpening`\ngodbolt: https://godbolt.org/z/4d3jo8jTz", "author": "danilaml", "labels": [ "llvm:SCEV", "crash-on-valid" ], "comments": [ { "author": "juliannagele", "body": "Thanks, checking!" }, { "author": "danilaml", "body": "@juliannagele Thanks for looking into it! Do you need any additional info?" } ] }
true
null
123550
https://github.com/llvm/llvm-project/issues/123550
miscompilation
a3aa452a21f983237873fa85c866b9f0224789bd
2025-01-20T06:37:58
[ "llvm/test/Analysis/ScalarEvolution" ]
{ "fix_commit": "07efe2c18a63423943a4f9d9daeada23601f84c8", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ [ 5917, 5936 ] ], "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": [ "ScalarEvolution::createAddRecFromPHI" ], "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 07efe2c18a63423943a4f9d9daeada23601f84c8 Author: Nikita Popov <[email protected]> Date: Wed Jan 29 09:09:14 2025 +0100 [SCEV] Check correct value for UB (#124302) This is a followup to #117152. That patch introduced a check for UB/poison on BEValue. However, the SCEV we're actually going to use is Shifted. In some cases, it's possible for Shifted to contain UB, while BEValue doesn't. In the test case the values are: BEValue: (-1 * (zext i8 (-83 + ((-83 /u {1,+,1}<%loop>) * {-1,+,-1}<%loop>)) to i32))<nuw><nsw> Shifted: (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))<nuw><nsw>)<nuw><nsw> Fixes https://github.com/llvm/llvm-project/issues/123550. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 7d7d37b3d228..2ce40877b523 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5917,20 +5917,18 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) { // PHI(f(0), f({1,+,1})) --> f({0,+,1}) // Do not allow refinement in rewriting of BEValue. - if (isGuaranteedNotToCauseUB(BEValue)) { - const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this); - const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false); - if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() && - ::impliesPoison(BEValue, Start)) { - const SCEV *StartVal = getSCEV(StartValueV); - if (Start == StartVal) { - // Okay, for the entire analysis of this edge we assumed the PHI - // to be symbolic. We now need to go back and purge all of the - // entries for the scalars that use the symbolic expression. - forgetMemoizedResults(SymbolicName); - insertValueToMap(PN, Shifted); - return Shifted; - } + const SCEV *Shifted = SCEVShiftRewriter::rewrite(BEValue, L, *this); + const SCEV *Start = SCEVInitRewriter::rewrite(Shifted, L, *this, false); + if (Shifted != getCouldNotCompute() && Start != getCouldNotCompute() && + isGuaranteedNotToCauseUB(Shifted) && ::impliesPoison(Shifted, Start)) { + const SCEV *StartVal = getSCEV(StartValueV); + if (Start == StartVal) { + // Okay, for the entire analysis of this edge we assumed the PHI + // to be symbolic. We now need to go back and purge all of the + // entries for the scalars that use the symbolic expression. + forgetMemoizedResults(SymbolicName); + insertValueToMap(PN, Shifted); + return Shifted; } } }
[ { "file": "llvm/test/Analysis/ScalarEvolution/pr123550.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @src() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n %phi = phi i32 [ -173, %bb ], [ %sub, %bb4 ]\n %phi2 = phi i32 [ 1, %bb ], [ %add, %bb4 ]\n %srem = srem i32 729259140, %phi\n %trunc = trunc i32 %phi2 to i8\n %urem = urem i8 -83, %trunc\n %zext = zext i8 %urem to i32\n %sub = sub nsw i32 0, %zext\n br label %bb4\n\nbb4: ; preds = %bb1\n %add = add nuw nsw i32 %phi2, 1\n %icmp = icmp eq i32 %sub, 0\n br i1 %icmp, label %bb5, label %bb1\n\nbb5: ; preds = %bb4\n %phi6 = phi i32 [ %srem, %bb4 ]\n ret i32 %phi6\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[Indvars] Miscompile: SSA value incorrectly simplified", "body": "One can find the incorrect transformation here: https://godbolt.org/z/T9qMhT7rb\nAnd the proof of incorrect transformation here: https://alive2.llvm.org/ce/z/PXjb5J\n\nFor the record, I describe the problem here. Given the IR:\n```\ndefine i32 @widget() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n %phi = phi i32 [ -173, %bb ], [ %sub, %bb4 ]\n %phi2 = phi i32 [ 1, %bb ], [ %add, %bb4 ]\n %srem = srem i32 729259140, %phi\n %trunc = trunc i32 %phi2 to i8\n %urem = urem i8 -83, %trunc\n %zext = zext i8 %urem to i32\n %sub = sub nsw i32 0, %zext\n br label %bb4\n\nbb4: ; preds = %bb1\n %add = add nuw nsw i32 %phi2, 1\n %icmp = icmp eq i32 %sub, 0\n br i1 %icmp, label %bb5, label %bb1\n\nbb5: ; preds = %bb4\n %phi6 = phi i32 [ %srem, %bb4 ]\n ret i32 %phi6\n}\n```\nwhich returns `srem i32 729259140, -173` which is `130`. The above IR under the `indvars` pass transforms to:\n```\ndefine i32 @widget() {\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n br label %bb4\n\nbb4: ; preds = %bb1\n br i1 true, label %bb5, label %bb1\n\nbb5: ; preds = %bb4\n ret i32 729259140\n}\n```\nwhich returns `729259140` which is the wrong answer. ", "author": "Nirhar", "labels": [ "miscompilation", "release:backport", "llvm:SCEV" ], "comments": [ { "author": "nikic", "body": "Slightly cleaned up:\n```\ndefine i32 @test() {\nbb:\n br label %loop \n\nloop: \n %phi = phi i32 [ -173, %bb ], [ %sub, %loop ]\n %iv2 = phi i32 [ 1, %bb ], [ %iv2.inc, %loop ]\n %srem = srem i32 729259140, %phi\n %trunc = trunc i32 %iv2 to i8\n %urem = urem i8 -83, %trunc\n %zext = zext i8 %urem to i32\n %sub = sub i32 0, %zext \n %iv2.inc = add i32 %iv2, 1\n %icmp = icmp eq i32 %zext, 0\n br i1 %icmp, label %exit, label %loop\n\nexit:\n %srem.lcssa = phi i32 [ %srem, %loop ]\n ret i32 %srem.lcssa\n}\n```\n\nIncorrect exit value is computed by SCEV:\n```\n --> (729259140 + (-1 * (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))<nuw><nsw>)<nuw><nsw> * (729259140 /u (-173 + (-1 * (zext i8 ((-83 /u {0,+,1}<%loop>) * {0,+,-1}<%loop>) to i32))<nuw><nsw>)<nuw><nsw>)))<nuw><nsw> U: empty-set S: empty-set\t\tExits: 729259140\t\tLoopDispositions: { %loop: Computable }\n```" } ] }
true
null
113123
https://github.com/llvm/llvm-project/issues/113123
miscompilation
67ff5ba9af9754261abe11d762af11532a816126
2024-10-21T02:18:29
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a2ba438f3e5635e368333213914c7452a6a6a2da", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ [ 1531, 1538 ] ], "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ "InstCombinerImpl::foldLogicOfFCmps" ], "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit a2ba438f3e5635e368333213914c7452a6a6a2da Author: XChy <[email protected]> Date: Mon Oct 21 22:30:31 2024 +0800 [InstCombine] Preserve the flag from RHS only if the `and` is bitwise (#113164) Fixes #113123 Alive proof: https://alive2.llvm.org/ce/z/hnqeLC diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index d72013ba223d..835eae9f5725 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1531,8 +1531,10 @@ Value *InstCombinerImpl::foldLogicOfFCmps(FCmpInst *LHS, FCmpInst *RHS, } if (IsLessThanOrLessEqual(IsAnd ? PredL : PredR)) { BuilderTy::FastMathFlagGuard Guard(Builder); - Builder.setFastMathFlags(LHS->getFastMathFlags() | - RHS->getFastMathFlags()); + FastMathFlags NewFlag = LHS->getFastMathFlags(); + if (!IsLogicalSelect) + NewFlag |= RHS->getFastMathFlags(); + Builder.setFastMathFlags(NewFlag); Value *FAbs = Builder.CreateUnaryIntrinsic(Intrinsic::fabs, LHS0); return Builder.CreateFCmp(PredL, FAbs,
[ { "file": "llvm/test/Transforms/InstCombine/fcmp-range-check-idiom.ll", "commands": [ "opt -S -passes=instcombine %s" ], "tests": [ { "test_name": "test_and_olt_fmf_propagation_union_logical_rhs_poison", "test_body": "define i1 @test_and_olt_fmf_propagation_union_logical_rhs_poison(float %x) {\n %cmp1 = fcmp ninf olt float %x, 0x3C00000000000000\n %cmp2 = fcmp ogt float %x, 0xBC00000000000000\n %cond = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_and_olt_fmf_propagation_union_logical_both_poison", "test_body": "define i1 @test_and_olt_fmf_propagation_union_logical_both_poison(float %x) {\n %cmp1 = fcmp ninf olt float %x, 0x3C00000000000000\n %cmp2 = fcmp ninf ogt float %x, 0xBC00000000000000\n %cond = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_and_olt_fmf_propagation_union", "test_body": "define i1 @test_and_olt_fmf_propagation_union(float %x) {\n %cmp1 = fcmp nnan ninf olt float %x, 0x3C00000000000000\n %cmp2 = fcmp nnan nsz ogt float %x, 0xBC00000000000000\n %cond = and i1 %cmp1, %cmp2\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_and_olt_fmf_propagation_union_logical_lhs_poison", "test_body": "define i1 @test_and_olt_fmf_propagation_union_logical_lhs_poison(float %x) {\n %cmp1 = fcmp olt float %x, 0x3C00000000000000\n %cmp2 = fcmp ninf ogt float %x, 0xBC00000000000000\n %cond = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %cond\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Wrong canonicalization of a range check idiom", "body": "https://github.com/llvm/llvm-project/blob/11dad2fa5138a50d60a5a34a2c7e074b976820e2/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp#L1511-L1527\r\n\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/qBHAmS\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @test_and_olt_fmf_propagation_union.2(float %x) {\r\n#0:\r\n %cmp1 = fcmp nnan ninf olt float %x, 0.000000\r\n %cmp2 = fcmp nnan nsz ogt float %x, -0.000000\r\n %#1 = select i1 %cmp2, i1 %cmp1, i1 %cmp2\r\n %cond = and i1 %#1, %cmp2\r\n ret i1 %cond\r\n}\r\n=>\r\ndefine i1 @test_and_olt_fmf_propagation_union.2(float %x) {\r\n#0:\r\n %#1 = fabs nnan ninf nsz float %x\r\n %#2 = fcmp nnan ninf nsz olt float %#1, 0.000000\r\n ret i1 %#2\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\nfloat %x = #xff800000 (-oo)\r\n\r\nSource:\r\ni1 %cmp1 = poison\r\ni1 %cmp2 = #x0 (0)\r\ni1 %#1 = #x0 (0)\r\ni1 %cond = #x0 (0)\r\n\r\nTarget:\r\nfloat %#1 = poison\r\ni1 %#2 = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [ { "author": "XChy", "body": "Thanks for the report.\r\n\r\nWe preserve `ninf` flag from `cmp1` when folding logical and `select cmp2, cmp1, false` into `fcmp ninf (fabs(x))`. But if `cmp2` equals to `false`, the select won't be poison whatever `cmp1` is. Thus, such fold makes it more poisonous. See https://alive2.llvm.org/ce/z/hnqeLC" }, { "author": "XChy", "body": "And it looks like you are mutating the unit tests to fuzz LLVM. Looks interesting to me. If OK, could you provide some information about it?" }, { "author": "bongjunj", "body": "> And it looks like you are mutating the unit tests to fuzz LLVM. Looks interesting to me. If OK, could you provide some information about it?\r\n\r\n@XChy Yes we are designing a fuzzer on top of LLVM to test the compiler. We can't disclose the full detail at this time. Thank you." } ] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": [ [ 6870, 6875 ] ], "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": [ "SalvageDVI" ], "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
105785
https://github.com/llvm/llvm-project/issues/105785
miscompilation
1241c762c165972690c4edfb82ec7421c1e64658
2024-08-23T05:45:52
[ "llvm/test/Transforms/ConstraintElimination" ]
{ "fix_commit": "85b6aac7c25f9d2a976a76045ace1e7afebb5965", "components": [ "ConstraintElimination" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ [ 1464, 1470 ] ], "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [ "checkAndReplaceCmp" ], "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 3ff9d92aae0945daa85ec6f85f05a3aeaaa9f962 Author: Yingwei Zheng <[email protected]> Date: Fri Aug 23 16:06:00 2024 +0800 [ConstraintElim] Fix miscompilation caused by PR97974 (#105790) Fixes https://github.com/llvm/llvm-project/issues/105785. (cherry picked from commit 85b6aac7c25f9d2a976a76045ace1e7afebb5965) diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index c31173879af1..37022104d0a9 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1464,7 +1464,7 @@ static bool checkAndReplaceCmp(CmpIntrinsic *I, ConstraintInfo &Info, ToRemove.push_back(I); return true; } - if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info)) { + if (checkCondition(ICmpInst::ICMP_EQ, LHS, RHS, I, Info).value_or(false)) { I->replaceAllUsesWith(ConstantInt::get(I->getType(), 0)); ToRemove.push_back(I); return true;
[ { "file": "llvm/test/Transforms/ConstraintElimination/pr105785.ll", "commands": [ "opt -passes=constraint-elimination -S %s" ], "tests": [ { "test_name": "pr105785", "test_body": "define void @pr105785(ptr %p) {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %for.cond1, %entry\n %for.ind = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\n %cmp = icmp eq i32 %for.ind, 0\n br i1 %cmp, label %for.cond1, label %for.end6\n\nfor.cond1: ; preds = %for.body3, %for.cond\n %for.ind2 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\n %cmp2 = icmp ult i32 %for.ind2, 3\n br i1 %cmp2, label %for.body3, label %for.cond\n\nfor.body3: ; preds = %for.cond1\n %scmp = call i32 @llvm.scmp.i32.i32(i32 %for.ind, i32 1)\n store i32 %scmp, ptr %p, align 4\n %inc = add nuw nsw i32 %for.ind2, 1\n br label %for.cond1\n\nfor.end6: ; preds = %for.cond\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.scmp.i32.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[ConstraintElim] Miscompilation with cmp intrinsic", "body": "Reproducer: https://alive2.llvm.org/ce/z/Tvz2NA\r\n```\r\n; bin/opt -passes=constraint-elimination test.ll -S\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.cond, %for.body3\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n %sub.i = tail call range(i32 -1, 2) i32 @llvm.scmp.i32.i32(i32 1, i32 %storemerge)\r\n store i32 %sub.i, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6:\r\n ret void\r\n}\r\n```\r\n\r\n```\r\ndefine void @h(ptr %p) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1, %entry\r\n %storemerge = phi i32 [ 0, %entry ], [ 1, %for.cond1 ]\r\n %cmp = icmp eq i32 %storemerge, 0\r\n br i1 %cmp, label %for.cond1, label %for.end6\r\n\r\nfor.cond1: ; preds = %for.body3, %for.cond\r\n %i.0 = phi i32 [ %inc, %for.body3 ], [ 0, %for.cond ]\r\n %cmp2 = icmp ult i32 %i.0, 3\r\n br i1 %cmp2, label %for.body3, label %for.cond\r\n\r\nfor.body3: ; preds = %for.cond1\r\n store i32 0, ptr %p, align 4\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br label %for.cond1\r\n\r\nfor.end6: ; preds = %for.cond\r\n ret void\r\n}\r\n```\r\n\r\nThe result of scmp should be 1 instead of 0.\r\n\r\nReduced C reproducer:\r\n```\r\n#include <stdio.h>\r\n#include <stdint.h>\r\n\r\nint builtin_scmp(int d, int e) { return (d > e) - (d < e); }\r\nint32_t f = 0;\r\nint64_t g = 0;\r\nvoid h() {\r\n for (f = 0; f <= 0; f++) {\r\n int i;\r\n for (i = 0; i < 3; i++)\r\n g = builtin_scmp(1, f);\r\n }\r\n}\r\nint main() {\r\n h();\r\n printf(\"%d\\n\", (int)g);\r\n return 0;\r\n}\r\n```\r\n\r\nI will post a fix later.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [] }
true
null
117517
https://github.com/llvm/llvm-project/issues/117517
crash
7e3187e12a2cef8b2552e08ce9423aca9c09d813
2024-11-25T05:18:47
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "57bbdbd7ae3698a274edd4dd6ef1b53d9129e552", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 1143, 1151 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "addMask" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 57bbdbd7ae3698a274edd4dd6ef1b53d9129e552 Author: Alexey Bataev <[email protected]> Date: Mon Nov 25 07:56:45 2024 -0800 [SLP]Relax assertion in mask combine for non-power-of-2 number of elements The nodes may contain non-power-of-2 number of elements. Need to relax the assertion to avoid possible compiler crash Fixes #117517 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d033b7c2ef4a..73218f377a06 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1143,9 +1143,7 @@ static void addMask(SmallVectorImpl<int> &Mask, ArrayRef<int> SubMask, assert( (!ExtendingManyInputs || SubMask.size() > Mask.size() || // Check if input scalars were extended to match the size of other node. - (SubMask.size() == Mask.size() && - std::all_of(std::next(Mask.begin(), Mask.size() / 2), Mask.end(), - [](int Idx) { return Idx == PoisonMaskElem; }))) && + (SubMask.size() == Mask.size() && Mask.back() == PoisonMaskElem)) && "SubMask with many inputs support must be larger than the mask."); if (Mask.empty()) { Mask.append(SubMask.begin(), SubMask.end());
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-2-num-elems-reused.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-10 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i64 @test() {\n;\nentry:\n %xor148.2.i = xor i32 0, 0\n %conv193.i = zext i32 %xor148.2.i to i64\n %conv193.1.i = zext i32 %xor148.2.i to i64\n %or194.1.i = or i64 %conv193.i, %conv193.1.i\n %xor148.2.i.1 = xor i32 0, 0\n %conv193.i.1 = zext i32 %xor148.2.i.1 to i64\n %or194.i.1 = or i64 %or194.1.i, %conv193.i.1\n %conv193.1.i.1 = zext i32 %xor148.2.i.1 to i64\n %or194.1.i.1 = or i64 %or194.i.1, %conv193.1.i.1\n %xor148.2.i.2 = xor i32 0, 0\n %conv193.i.2 = zext i32 %xor148.2.i.2 to i64\n %or194.i.2 = or i64 %or194.1.i.1, %conv193.i.2\n %conv193.1.i.2 = zext i32 %xor148.2.i.2 to i64\n %or194.1.i.2 = or i64 %or194.i.2, %conv193.1.i.2\n %xor148.2.i.3 = xor i32 0, 0\n %conv193.i.3 = zext i32 %xor148.2.i.3 to i64\n %or194.i.3 = or i64 %or194.1.i.2, %conv193.i.3\n %conv193.1.i.3 = zext i32 %xor148.2.i.3 to i64\n %or194.1.i.3 = or i64 %or194.i.3, %conv193.1.i.3\n %xor148.2.i.4 = xor i32 0, 0\n %conv193.i.4 = zext i32 %xor148.2.i.4 to i64\n %or194.i.4 = or i64 %or194.1.i.3, %conv193.i.4\n %conv193.1.i.4 = zext i32 %xor148.2.i.4 to i64\n %or194.1.i.4 = or i64 %or194.i.4, %conv193.1.i.4\n %xor148.2.i.5 = xor i32 0, 0\n %conv193.i.5 = zext i32 %xor148.2.i.5 to i64\n %or194.i.5 = or i64 %or194.1.i.4, %conv193.i.5\n %conv193.1.i.5 = zext i32 %xor148.2.i.5 to i64\n %or194.1.i.5 = or i64 %or194.i.5, %conv193.1.i.5\n %xor148.2.i.6 = xor i32 0, 0\n %conv193.i.6 = zext i32 %xor148.2.i.6 to i64\n %or194.i.6 = or i64 %or194.1.i.5, %conv193.i.6\n %or54.i.i.6 = or i32 %xor148.2.i.6, 0\n %conv193.1.i.6 = zext i32 %or54.i.i.6 to i64\n %xor148.2.i.7 = xor i32 0, 0\n %conv193.i.7 = zext i32 %xor148.2.i.7 to i64\n %0 = or i64 %or194.i.6, %conv193.i.7\n %conv193.1.i.7 = zext i32 %xor148.2.i.7 to i64\n %1 = or i64 %0, %conv193.1.i.7\n %or194.1.i.7 = or i64 %1, %conv193.1.i.6\n ret i64 %or194.1.i.7\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion \"SubMask with many inputs support must be larger than the mask.\" failed.", "body": "Reproducer: https://godbolt.org/z/Mzbe1G875\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i64 @test() {\r\nentry:\r\n %xor148.2.i = xor i32 0, 0\r\n %conv193.i = zext i32 %xor148.2.i to i64\r\n %conv193.1.i = zext i32 %xor148.2.i to i64\r\n %or194.1.i = or i64 %conv193.i, %conv193.1.i\r\n %xor148.2.i.1 = xor i32 0, 0\r\n %conv193.i.1 = zext i32 %xor148.2.i.1 to i64\r\n %or194.i.1 = or i64 %or194.1.i, %conv193.i.1\r\n %conv193.1.i.1 = zext i32 %xor148.2.i.1 to i64\r\n %or194.1.i.1 = or i64 %or194.i.1, %conv193.1.i.1\r\n %xor148.2.i.2 = xor i32 0, 0\r\n %conv193.i.2 = zext i32 %xor148.2.i.2 to i64\r\n %or194.i.2 = or i64 %or194.1.i.1, %conv193.i.2\r\n %conv193.1.i.2 = zext i32 %xor148.2.i.2 to i64\r\n %or194.1.i.2 = or i64 %or194.i.2, %conv193.1.i.2\r\n %xor148.2.i.3 = xor i32 0, 0\r\n %conv193.i.3 = zext i32 %xor148.2.i.3 to i64\r\n %or194.i.3 = or i64 %or194.1.i.2, %conv193.i.3\r\n %conv193.1.i.3 = zext i32 %xor148.2.i.3 to i64\r\n %or194.1.i.3 = or i64 %or194.i.3, %conv193.1.i.3\r\n %xor148.2.i.4 = xor i32 0, 0\r\n %conv193.i.4 = zext i32 %xor148.2.i.4 to i64\r\n %or194.i.4 = or i64 %or194.1.i.3, %conv193.i.4\r\n %conv193.1.i.4 = zext i32 %xor148.2.i.4 to i64\r\n %or194.1.i.4 = or i64 %or194.i.4, %conv193.1.i.4\r\n %xor148.2.i.5 = xor i32 0, 0\r\n %conv193.i.5 = zext i32 %xor148.2.i.5 to i64\r\n %or194.i.5 = or i64 %or194.1.i.4, %conv193.i.5\r\n %conv193.1.i.5 = zext i32 %xor148.2.i.5 to i64\r\n %or194.1.i.5 = or i64 %or194.i.5, %conv193.1.i.5\r\n %xor148.2.i.6 = xor i32 0, 0\r\n %conv193.i.6 = zext i32 %xor148.2.i.6 to i64\r\n %or194.i.6 = or i64 %or194.1.i.5, %conv193.i.6\r\n %or54.i.i.6 = or i32 %xor148.2.i.6, 0\r\n %conv193.1.i.6 = zext i32 %or54.i.i.6 to i64\r\n %xor148.2.i.7 = xor i32 0, 0\r\n %conv193.i.7 = zext i32 %xor148.2.i.7 to i64\r\n %0 = or i64 %or194.i.6, %conv193.i.7\r\n %conv193.1.i.7 = zext i32 %xor148.2.i.7 to i64\r\n %1 = or i64 %0, %conv193.1.i.7\r\n %or194.1.i.7 = or i64 %1, %conv193.1.i.6\r\n ret i64 %or194.1.i.7\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:1143: void addMask(llvm::SmallVectorImpl<int>&, llvm::ArrayRef<int>, bool): Assertion `(!ExtendingManyInputs || SubMask.size() > Mask.size() || (SubMask.size() == Mask.size() && std::all_of(std::next(Mask.begin(), Mask.size() / 2), Mask.end(), [](int Idx) { return Idx == PoisonMaskElem; }))) && \"SubMask with many inputs support must be larger than the mask.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000751221842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007512218969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000751221842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007512218287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000075122182871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000751221839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e91f7 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+0x41e91f7)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x00000000042691b0 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000426c681 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426c681)\r\n#14 0x0000000004270deb llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#15 0x00000000042758a6 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42758a6)\r\n#16 0x000000000427bf86 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x0000751221829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x0000751221829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
106780
https://github.com/llvm/llvm-project/issues/106780
crash
5aa83eb677d2f8cba0c2ad3dcc14f3f4e80a0bba
2024-08-30T19:02:15
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "654bb4e9f287f9ccb5142d1c62a9ab17c16e29d7", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6817, 6822 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::collectValuesToIgnore" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 654bb4e9f287f9ccb5142d1c62a9ab17c16e29d7 Author: Florian Hahn <[email protected]> Date: Sun Sep 1 20:35:28 2024 +0100 [LV] Don't consider branches leaving loop in collectValuesToIgnore. Branches exiting the loop will remain regardless, so don't consider them in collectValuesToIgnore. This fixes another divergence between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/106780. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index fa05b8dd2242..a8722db654f5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6817,6 +6817,9 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { if (auto *Br = dyn_cast_or_null<BranchInst>(Op)) { BasicBlock *ThenBB = Br->getSuccessor(0); BasicBlock *ElseBB = Br->getSuccessor(1); + // Don't considers branches leaving the loop for simplification. + if (!TheLoop->contains(ThenBB) || !TheLoop->contains(ElseBB)) + continue; bool ThenEmpty = IsEmptyBlock(ThenBB); bool ElseEmpty = IsEmptyBlock(ElseBB); if ((ThenEmpty && ElseEmpty) ||
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll", "commands": [ "opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s" ], "tests": [ { "test_name": "dead_load", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cost_of_exit_branch_and_cond_insts", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.umax.i16(i16, i16) #0\n\ndefine i32 @cost_of_exit_branch_and_cond_insts(ptr %a, ptr %b, i1 %c, i16 %x) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.exiting\n\nthen: ; preds = %loop.header\n %gep = getelementptr inbounds i32, ptr %b, i32 %iv\n store i1 false, ptr %a, align 1\n store i32 0, ptr %gep, align 4\n br label %loop.exiting\n\nloop.exiting: ; preds = %then, %loop.header\n %iv.next = add i32 %iv, 1\n %umax = tail call i16 @llvm.umax.i16(i16 %x, i16 111)\n %umax.ext = zext i16 %umax to i32\n %sub = sub i32 770, %umax.ext\n %ec = icmp slt i32 %iv, %sub\n br i1 %ec, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop.exiting\n br label %loop.header\n\nexit: ; preds = %loop.exiting\n br label %return\n\nreturn: ; preds = %exit\n ret i32 0\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dead_live_out_due_to_scalar_epilogue_required", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i8 @dead_live_out_due_to_scalar_epilogue_required(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %idxprom = sext i32 %iv to i64\n %gep.src = getelementptr i8, ptr %src, i64 %idxprom\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %idxprom\n store i8 0, ptr %gep.dst, align 1\n %iv.next = add i32 %iv, 4\n %cmp = icmp ult i32 %iv, 1001\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n %r = phi i8 [ %l, %loop ]\n ret i8 %r\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using ef7b18a53c0d186dcda1e322be6035407fdedb55\r\n\r\nTestcase:\r\n```c\r\nunsigned short a;\r\nextern int b;\r\nvoid c(_Bool d, int e, long long f[], unsigned short g[][16],\r\n unsigned short h[][16], unsigned short i[][13], short j[][13],\r\n int k[][21], unsigned char l[][21][21], signed char m[][24]) {\r\n for (short n = 0; n < 5; n += -5532)\r\n for (char o = 0; o < 3; o += d)\r\n for (int p = 0; p < -({ g[d][1] > 0115 ? g[d][1] : 0115; }) + 770; p++)\r\n for (_Bool q = 0; q < (_Bool)e; q = 5)\r\n for (_Bool r = 2048749519 ? 8 ? f[d] : 0 : 0; r < 1; r = h)\r\n b = a = 0;\r\n}\r\nvoid hash();\r\nunsigned short a = 6;\r\nlong long f[6];\r\nunsigned short g[6][16];\r\nunsigned short h[1][16];\r\nunsigned short i[1][13];\r\nshort j[1][13];\r\nint k[1][21];\r\nunsigned char l[1][21][21];\r\nsigned char m[1][24];\r\nint main() {\r\n for (long s = 0; s < 6; ++s)\r\n f[s] = 6;\r\n for (long s = 0; s < 16; ++s)\r\n for (long n = 0; n < 16; ++n)\r\n g[s][n] = 7;\r\n c(1, 407418382874, f, g, h, i, j, k, l, m);\r\n hash(a);\r\n}\r\n```\r\nc command:\r\n```\r\n/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -fno-strict-aliasing -march=rv64gcv -flto -O3 -fuse-ld=lld red.c -o rv64gcv.out -w\r\n```\r\n\r\nLLVM IR testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i16 @llvm.umax.i16(i16, i16) #0\r\n\r\ndefine i32 @main(ptr %a) #1 {\r\nentry:\r\n br label %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n\r\nfor.cond22.preheader.us.us76.us.us.us.us.i.1: ; preds = %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1, %entry\r\n %p.072.us.us77.us.us.us.us.i.1 = phi i32 [ %inc.us.us80.us.us.us.us.i.1, %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1 ], [ 0, %entry ]\r\n br i1 false, label %for.body41.lr.ph.us.us.us.us.us.us.us.i.1, label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n\r\nfor.body41.lr.ph.us.us.us.us.us.us.us.i.1: ; preds = %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n store i1 false, ptr %a, align 1\r\n store i32 0, ptr null, align 4\r\n br label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n\r\nfor.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1: ; preds = %for.body41.lr.ph.us.us.us.us.us.us.us.i.1, %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n %inc.us.us80.us.us.us.us.i.1 = add i32 %p.072.us.us77.us.us.us.us.i.1, 1\r\n %narrow.us.us81.us.us.us.us.i.1 = tail call i16 @llvm.umax.i16(i16 0, i16 0)\r\n %spec.select.us.us82.us.us.us.us.i.1 = zext i16 %narrow.us.us81.us.us.us.us.i.1 to i32\r\n %add.us.us83.us.us.us.us.i.1 = sub i32 770, %spec.select.us.us82.us.us.us.us.i.1\r\n %cmp18.us.us84.us.us.us.us.i.1 = icmp slt i32 %p.072.us.us77.us.us.us.us.i.1, %add.us.us83.us.us.us.us.i.1\r\n br i1 %cmp18.us.us84.us.us.us.us.i.1, label %for.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1, label %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge\r\n\r\nfor.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n br label %for.cond.cleanup20.us.us.us.us.i.1\r\n\r\nfor.cond.cleanup20.us.us.us.us.i.1: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1.for.cond.cleanup20.us.us.us.us.i.1_crit_edge\r\n ret i32 0\r\n\r\nfor.cond22.preheader.us.us76.us.us.us.usthread-pre-split.i.1: ; preds = %for.cond22.for.cond.cleanup28_crit_edge.us.us.us.us.us.us.i.1\r\n br label %for.cond22.preheader.us.us76.us.us.us.us.i.1\r\n}\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #1 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7366: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x00005e8221f7d690 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301e690)\r\n #1 0x00005e8221f7aa9f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301ba9f)\r\n #2 0x00005e8221f7abf5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000772c88c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000772c88c969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000772c88c969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x0000772c88c969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000772c88c42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x0000772c88c287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x0000772c88c2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000772c88c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005e8220f4a3e0 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1feb3e0)\r\n#12 0x00005e8220f60ffb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2001ffb)\r\n#13 0x00005e8220f64011 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2005011)\r\n#14 0x00005e8220f64687 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2005687)\r\n#15 0x00005e821fdc0fb6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe61fb6)\r\n#16 0x00005e8221d8858f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2958f)\r\n#17 0x00005e821fdc4146 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe65146)\r\n#18 0x00005e8221d8730b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2830b)\r\n#19 0x00005e821fdc03e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe613e6)\r\n#20 0x00005e8221d8534d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2634d)\r\n#21 0x00005e821f5e6ee6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x687ee6)\r\n#22 0x00005e821f5d8c71 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679c71)\r\n#23 0x0000772c88c29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x0000772c88c29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x0000772c88c29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005e821f5cf025 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x670025)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/ej1Gax953\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/106641\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
119173
https://github.com/llvm/llvm-project/issues/119173
miscompilation
ab77db03ce28e86a61010e51ea13796ea09efc46
2024-12-09T07:19:06
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "30f3752e54fa7cd595a434a985efbe9a7abe9b65", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6637, 6644 ], [ 8588, 8593 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInstructionCost", "VPRecipeBuilder::tryToWiden" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 30f3752e54fa7cd595a434a985efbe9a7abe9b65 Author: Florian Hahn <[email protected]> Date: Mon Feb 3 17:01:02 2025 +0000 [VPlan] Only use SCEV for live-ins in tryToWiden. (#125436) Replacing a recipe with a live-in may not be correct in all cases, e.g. when replacing recipes involving header-phi recipes, like reductions. For now, only use SCEV to simplify live-ins. More powerful input simplification can be built in top of https://github.com/llvm/llvm-project/pull/124432 in the future. Fixes https://github.com/llvm/llvm-project/issues/119173. Fixes https://github.com/llvm/llvm-project/issues/125374. PR: https://github.com/llvm/llvm-project/pull/125436 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index cbb9960959f2..ce66350669d5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6637,8 +6637,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, // fold away. We can generalize this for all operations using the notion // of neutral elements. (TODO) if (I->getOpcode() == Instruction::Mul && - (PSE.getSCEV(I->getOperand(0))->isOne() || - PSE.getSCEV(I->getOperand(1))->isOne())) + ((TheLoop->isLoopInvariant(I->getOperand(0)) && + PSE.getSCEV(I->getOperand(0))->isOne()) || + (TheLoop->isLoopInvariant(I->getOperand(1)) && + PSE.getSCEV(I->getOperand(1))->isOne()))) return 0; // Detect reduction patterns @@ -8588,6 +8590,8 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, // to replace operands with constants. ScalarEvolution &SE = *PSE.getSE(); auto GetConstantViaSCEV = [this, &SE](VPValue *Op) { + if (!Op->isLiveIn()) + return Op; Value *V = Op->getUnderlyingValue(); if (isa<Constant>(V) || !SE.isSCEVable(V->getType())) return Op;
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/mul-simplification.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "mul_select_operand_known_1_via_scev", "test_body": "target triple = \"arm64-apple-macosx\"\n\ndefine i64 @mul_select_operand_known_1_via_scev() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %red = phi i64 [ 12, %entry ], [ %red.next, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = and i32 %iv, 1\n %cmp1.i = icmp eq i32 %0, 0\n %narrow.i = select i1 %cmp1.i, i32 1, i32 %iv\n %mul = zext nneg i32 %narrow.i to i64\n %red.next = mul nsw i64 %red, %mul\n %iv.next = add nuw nsw i32 %iv, 1\n %ec = icmp eq i32 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %res = phi i64 [ %red.next, %loop ]\n ret i64 %res\n}\n", "lli_expected_out": null, "additional_args": "-src-unroll=4 -tgt-unroll=4" }, { "test_name": "pr125374", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main() {\nentry:\n br label %for.body.i.i\n\nfor.body.i.i: ; preds = %for.body.i.i, %entry\n %indvars.iv.i.i = phi i64 [ 0, %entry ], [ %indvars.iv.next.i.i, %for.body.i.i ]\n %conv678.i.i = phi i8 [ 1, %entry ], [ %add.i.i.i, %for.body.i.i ]\n %add.i.i.i = add i8 0, %conv678.i.i\n %indvars.iv.next.i.i = add i64 %indvars.iv.i.i, 1\n %exitcond.not.i.i = icmp eq i64 %indvars.iv.i.i, 1\n br i1 %exitcond.not.i.i, label %o.exit, label %for.body.i.i\n\no.exit: ; preds = %for.body.i.i\n %conv6.i.i = zext i8 %add.i.i.i to i32\n ret i32 %conv6.i.i\n}\n", "lli_expected_out": null, "additional_args": "-src-unroll=2 -tgt-unroll=2" } ] } ]
{ "title": "[clang] Miscompilation at -O3", "body": "This code prints 15 at -O3, but prints 5 at -O0/1/2:\n```c\nint printf(const char *, ...);\nstatic int a[] = {4294967295, 5};\nint b, c;\nint main() {\n a[1] = b = 5;\n unsigned d = -13;\n for (; d >= 8; d = a[0] + d + 6) {\n int *e = &b;\n *e = a[0] - -1 + b;\n }\n a[c];\n printf(\"%d\\n\", b);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/4xdPqcjPb\n\nBisected to https://github.com/llvm/llvm-project/commit/6d6eea92e36c301e34a7ec11b2a40e3080f79f53, which was committed by @fhahn ", "author": "cardigan1008", "labels": [ "miscompilation", "vectorizers" ], "comments": [ { "author": "hstk30-hw", "body": "Don't ignore the warning.\n\n```\n<source>:2:19: warning: implicit conversion from 'long' to 'int' changes value from 4294967294 to -2 [-Wconstant-conversion]\n 2 | static int a[] = {4294967294, 5};\n | ~^~~~~~~~~~\n```" }, { "author": "antoniofrighetto", "body": "Please leave the issue opened, as it's implementation-defined behaviour, not undefined behaviour." }, { "author": "antoniofrighetto", "body": "Reduced to:\n```llvm\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine noundef i32 @src() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %entry, %for.body\n %d.06 = phi i32 [ -13, %entry ], [ %add2.reass, %for.body ]\n %add45 = phi i32 [ 5, %entry ], [ %add, %for.body ]\n %add = add i32 0, %add45\n %add2.reass = add i32 %d.06, 5\n %cmp = icmp ugt i32 %add2.reass, 7\n br i1 %cmp, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret i32 %add\n}\n```\n\n@fhahn I think the issue fundamentally here lies in the fact that we are incorrectly widening the constant 5 (retrieved from SCEV) to `<5, 5, 5, 5>`, when in fact it should be `<5, 0, 0, 0>` (VPlan value: `WIDEN-REDUCTION-PHI ir<%add45> = phi ir<5>`). The VPBasicBlock for the miscompiled basic block is the following one:\n```\nvector.body:\n EMIT vp<%4> = CANONICAL-INDUCTION ir<0>, vp<%7>\n WIDEN-INDUCTION %d.06 = phi -13, %add2.reass, ir<5>, vp<%0>\n WIDEN-REDUCTION-PHI ir<%add45> = phi ir<5>\n EMIT vp<%5> = WIDEN-CANONICAL-INDUCTION vp<%4>\n EMIT vp<%6> = icmp ule vp<%5>, vp<%3>\n```\nI'm not that familiar with VPlan, though I feel like that either we are not taking into account the active lane, or we should have not emitted a widen instruction in the first place.\n\n(Godbolt: https://llvm.godbolt.org/z/4Wz46ceh1)" }, { "author": "antoniofrighetto", "body": "@fhahn Would you be willing to have a look at it? Happy to help with any additional triage, if needed." }, { "author": "fhahn", "body": "Yep let me take a look!" } ] }
true
null
112068
https://github.com/llvm/llvm-project/issues/112068
miscompilation
b24acc06e1d465b3e3e4e28515dd437f6a7454f2
2024-10-12T02:41:57
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a59976bea8ad76f18119a11391dc8ba3e6ba07d5", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": [ [ 505, 512 ] ], "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": [ "foldCttzCtlz" ], "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit a59976bea8ad76f18119a11391dc8ba3e6ba07d5 Author: Yingwei Zheng <[email protected]> Date: Tue Nov 19 20:06:34 2024 +0800 [InstCombine] Drop noundef attributes in `foldCttzCtlz` (#116718) Closes https://github.com/llvm/llvm-project/issues/112068. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 6cff3c7af91e..42c0acd1e45e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -505,8 +505,10 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) { // If ctlz/cttz is only used as a shift amount, set is_zero_poison to true. if (II.hasOneUse() && match(Op1, m_Zero()) && - match(II.user_back(), m_Shift(m_Value(), m_Specific(&II)))) + match(II.user_back(), m_Shift(m_Value(), m_Specific(&II)))) { + II.dropUBImplyingAttrsAndMetadata(); return IC.replaceOperand(II, 1, IC.Builder.getTrue()); + } Constant *C;
[ { "file": "llvm/test/Transforms/InstCombine/shift-cttz-ctlz.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "shl_cttz_false_multiuse", "test_body": "define i32 @shl_cttz_false_multiuse(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n call void @use(i32 %cttz)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\ndeclare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "shl_cttz_false_noundef", "test_body": "define i32 @shl_cttz_false_noundef(i32 %x, i32 %y) {\nentry:\n %cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "ashr_cttz_false", "test_body": "define i32 @ashr_cttz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = ashr i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "shl_cttz_false", "test_body": "define i32 @shl_cttz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "shl_cttz_as_lhs", "test_body": "define i32 @shl_cttz_as_lhs(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = shl i32 %cttz, %x\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "shl_ctlz_false", "test_body": "define i32 @shl_ctlz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.ctlz.i32(i32 %y, i1 false)\n %res = shl i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "lshr_cttz_false", "test_body": "define i32 @lshr_cttz_false(i32 %x, i32 %y) {\nentry:\n %cttz = call i32 @llvm.cttz.i32(i32 %y, i1 false)\n %res = lshr i32 %x, %cttz\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `noundef` attribute should be dropped after setting `is_zero_poison` to true", "body": "Reproducer: https://alive2.llvm.org/ce/z/7-TgAf\r\n```\r\ndefine i32 @src(i32 %x, i32 %y) {\r\nentry:\r\n %cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 false)\r\n %res = lshr i32 %x, %cttz\r\n ret i32 %res\r\n}\r\n\r\ndefine i32 @tgt(i32 %x, i32 %y) {\r\nentry:\r\n %cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 true)\r\n %res = lshr i32 %x, %cttz\r\n ret i32 %res\r\n}\r\n\r\ndefine i32 @src2(i32 %x) {\r\n %ct = call noundef i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %cmp = icmp ne i32 %x, 0\r\n %res = select i1 %cmp, i32 %ct, i32 123\r\n ret i32 %res\r\n}\r\n\r\ndefine i32 @tgt2(i32 %x) {\r\n %ct = call noundef i32 @llvm.ctlz.i32(i32 %x, i1 true)\r\n %cmp = icmp ne i32 %x, 0\r\n %res = select i1 %cmp, i32 %ct, i32 123\r\n ret i32 %res\r\n}\r\n```\r\n`noundef` attribute should be dropped. Otherwise we will convert a poison value to immediate UB.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
111934
https://github.com/llvm/llvm-project/issues/111934
miscompilation
f74f568b29885c3fa63c44e33f91f3bb7281138e
2024-10-11T03:29:55
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "6a65e98fa7901dc1de91172d065fafb16ce89d77", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ [ 955, 963 ], [ 971, 977 ], [ 980, 986 ], [ 3375, 3381 ] ], "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ "InstCombinerImpl::foldAndOrOfICmps", "foldIsPowerOf2" ], "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 6a65e98fa7901dc1de91172d065fafb16ce89d77 Author: Yingwei Zheng <[email protected]> Date: Fri Oct 11 18:19:21 2024 +0800 [InstCombine] Drop range attributes in `foldIsPowerOf2` (#111946) Fixes https://github.com/llvm/llvm-project/issues/111934. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 688601a8ffa5..964616a4eb35 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -955,9 +955,11 @@ static Value *foldIsPowerOf2OrZero(ICmpInst *Cmp0, ICmpInst *Cmp1, bool IsAnd, } /// Reduce a pair of compares that check if a value has exactly 1 bit set. -/// 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 *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd, - InstCombiner::BuilderTy &Builder) { + InstCombiner::BuilderTy &Builder, + InstCombinerImpl &IC) { // Handle 'and' / 'or' commutation: make the equality check the first operand. if (JoinedByAnd && Cmp1->getPredicate() == ICmpInst::ICMP_NE) std::swap(Cmp0, Cmp1); @@ -971,7 +973,10 @@ static Value *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd, match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_ULT, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)), m_SpecificInt(2)))) { - Value *CtPop = Cmp1->getOperand(0); + auto *CtPop = cast<Instruction>(Cmp1->getOperand(0)); + // Drop range attributes and re-infer them in the next iteration. + CtPop->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(CtPop); return Builder.CreateICmpEQ(CtPop, ConstantInt::get(CtPop->getType(), 1)); } // (X == 0) || (ctpop(X) u> 1) --> ctpop(X) != 1 @@ -980,7 +985,10 @@ static Value *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd, match(Cmp1, m_SpecificICmp(ICmpInst::ICMP_UGT, m_Intrinsic<Intrinsic::ctpop>(m_Specific(X)), m_SpecificInt(1)))) { - Value *CtPop = Cmp1->getOperand(0); + auto *CtPop = cast<Instruction>(Cmp1->getOperand(0)); + // Drop range attributes and re-infer them in the next iteration. + CtPop->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(CtPop); return Builder.CreateICmpNE(CtPop, ConstantInt::get(CtPop->getType(), 1)); } return nullptr; @@ -3375,7 +3383,7 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, if (Value *V = foldSignedTruncationCheck(LHS, RHS, I, Builder)) return V; - if (Value *V = foldIsPowerOf2(LHS, RHS, IsAnd, Builder)) + if (Value *V = foldIsPowerOf2(LHS, RHS, IsAnd, Builder, *this)) return V; if (Value *V = foldPowerOf2AndShiftedMask(LHS, RHS, IsAnd, Builder))
[ { "file": "llvm/test/Transforms/InstCombine/ispow2.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] poison-generating attributes are not dropped when folding logical and/or of icmps", "body": "Reproducer: https://alive2.llvm.org/ce/z/rSUfvo\r\n```\r\ndefine i1 @src(i32 noundef %Value) {\r\nentry:\r\n %cmp.not = icmp eq i32 %Value, 0\r\n %0 = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %Value)\r\n %cmp1 = icmp ult i32 %0, 2\r\n %1 = select i1 %cmp.not, i1 false, i1 %cmp1\r\n ret i1 %1\r\n}\r\n\r\ndefine i1 @tgt(i32 noundef %Value) {\r\nentry:\r\n %0 = call range(i32 1, 33) i32 @llvm.ctpop.i32(i32 %Value)\r\n %1 = icmp eq i32 %0, 1\r\n ret i1 %1\r\n}\r\n```\r\nWhen `%Value == 0`, `@src` returns `false` but `@tgt` returns `poison`.\r\nThis miscompilation was triggered after https://github.com/llvm/llvm-project/pull/111284 was landed.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 8693, 8698 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "addUsersInExitBlock" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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;.", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
89516
https://github.com/llvm/llvm-project/issues/89516
miscompilation
18bb175428f520aaa4a5e388bd3b680a1a7c60c0
2024-04-20T22:58:16
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "6309440c218778db027306826993e484eab2be17", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 2720, 2726 ] ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "foldSelectWithSRem" ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 6309440c218778db027306826993e484eab2be17 Author: Yingwei Zheng <[email protected]> Date: Sun Apr 21 22:41:32 2024 +0800 [InstCombine] Fix unexpected overwriting in `foldSelectWithSRem` (#89539) Fixes #89516 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 0262af28068b..73600206a55c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2720,7 +2720,7 @@ static Instruction *foldSelectWithSRem(SelectInst &SI, InstCombinerImpl &IC, // %cnd = icmp slt i32 %rem, 0 // %add = add i32 %rem, %n // %sel = select i1 %cnd, i32 %add, i32 %rem - if (match(TrueVal, m_Add(m_Value(RemRes), m_Value(Remainder))) && + if (match(TrueVal, m_Add(m_Specific(RemRes), m_Value(Remainder))) && match(RemRes, m_SRem(m_Value(Op), m_Specific(Remainder))) && IC.isKnownToBeAPowerOfTwo(Remainder, /*OrZero*/ true) && FalseVal == RemRes)
[ { "file": "llvm/test/Transforms/InstCombine/select-divrem.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "rem_euclid_pow2_false_arm_folded", "test_body": "define i32 @rem_euclid_pow2_false_arm_folded(i32 %n) {\n %rem = srem i32 %n, 2\n %nonneg = icmp sge i32 %rem, 0\n %res = select i1 %nonneg, i32 %rem, i32 1\n ret i32 %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr89516", "test_body": "define i8 @pr89516(i8 %n, i8 %x) {\n %cond = icmp slt i8 %x, 0\n %pow2 = shl nuw i8 1, %n\n %srem = srem i8 1, %pow2\n %add = add nuw i8 %srem, %pow2\n %res = select i1 %cond, i8 %add, i8 %srem\n ret i8 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "miscompile of vanilla integer code by InstCombine", "body": "https://alive2.llvm.org/ce/z/jRfVLr\r\n\r\nthis function:\r\n```llvm\r\ndefine i8 @f(i8 %0, i8 %1) {\r\n %3 = icmp slt i8 %1, 0\r\n %4 = shl i8 1, %0\r\n %5 = srem i8 1, %4\r\n %6 = add i8 %5, %4\r\n %7 = select i1 %3, i8 %6, i8 %5\r\n ret i8 %7\r\n}\r\n```\r\nis getting mis-optimized to:\r\n```llvm\r\ndefine i8 @f(i8 %0, i8 %1) {\r\n %3 = icmp ne i8 %0, 0\r\n %4 = zext i1 %3 to i8\r\n ret i8 %4\r\n}\r\n```\r\nhere I'll just give Alive's work:\r\n```\r\nExample:\r\ni8 %#0 = #x00 (0)\r\ni8 %#1 = #xff (255, -1)\r\n\r\nSource:\r\ni1 %#3 = #x1 (1)\r\ni8 %#4 = #x01 (1)\r\ni8 %#5 = #x00 (0)\r\ni8 %#6 = #x01 (1)\r\ni8 %#7 = #x01 (1)\r\n\r\nTarget:\r\ni1 %#3 = #x0 (0)\r\ni8 %#4 = #x00 (0)\r\nSource value: #x01 (1)\r\nTarget value: #x00 (0)\r\n```\r\n\r\ncc @nunoplopes @hatsunespica", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
98139
https://github.com/llvm/llvm-project/issues/98139
miscompilation
6aefa918768c834ec21e0b599fa14d03b9ce3dc0
2024-07-09T09:49:19
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "722151664ecfd53295392ad875ff9bfdcd1deaaf", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ [ 411, 417 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [ "InstCombinerImpl::SimplifyDemandedUseBits" ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 722151664ecfd53295392ad875ff9bfdcd1deaaf Author: Yingwei Zheng <[email protected]> Date: Tue Jul 9 22:04:55 2024 +0800 [InstCombine] Fix typo in `adjustKnownBitsForSelectArm` (#98155) Fixes https://github.com/llvm/llvm-project/issues/98139. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 98f085a2c756..081e783c964f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -411,7 +411,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, // Only known if known in both the LHS and RHS. adjustKnownBitsForSelectArm(LHSKnown, I->getOperand(0), I->getOperand(1), /*Invert=*/false, Depth, Q); - adjustKnownBitsForSelectArm(LHSKnown, I->getOperand(0), I->getOperand(2), + adjustKnownBitsForSelectArm(RHSKnown, I->getOperand(0), I->getOperand(2), /*Invert=*/true, Depth, Q); Known = LHSKnown.intersectWith(RHSKnown); break;
[ { "file": "llvm/test/Transforms/InstCombine/pr98139.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr98139", "test_body": "define i8 @pr98139(i16 %a, i16 %b, i1 %cond) {\n %sel = select i1 %cond, i16 1, i16 254\n %cond1 = icmp ne i16 %b, 0\n %mask = and i16 %a, 255\n %cond2 = icmp ne i16 %mask, 255\n %cond3 = or i1 %cond1, %cond2\n %sel2 = select i1 %cond3, i16 %sel, i16 255\n %sub = sub i16 %sel2, %a\n %trunc = trunc i16 %sub to i8\n ret i8 %trunc\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "wrong code at -O{s,2,3} on x86_64-linux-gnu", "body": "It appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier.\r\n\r\nCompiler Explorer: https://godbolt.org/z/o595xsMdb\r\n\r\n```\r\n[512] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 765e2f9a8de27cc8fd8c75540844e9630d8229ad)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[513] % \r\n[513] % clangtk -O1 small.c; ./a.out\r\n1\r\n[514] % clangtk -O3 small.c; ./a.out\r\n-2\r\n1\r\n[515] % cat small.c\r\nint printf(const char *, ...);\r\nint a, b, c, e;\r\nchar d;\r\nint main() {\r\n int f = 1;\r\n unsigned g = 1;\r\n for (; c < 2; c++) {\r\n if (g)\r\n b = 1;\r\n char h = f;\r\n f = ~h;\r\n d = ~b - ~g * (a || f);\r\n g = ~g;\r\n if (g < 1)\r\n break;\r\n if (d)\r\n printf(\"%d\\n\", g);\r\n f = e;\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "miscompilation", "confirmed", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "There is a bug in `SimplifyDemandedInstructionBits` :)\r\nI am working to provide a minimal reproducer.\r\n" }, { "author": "dtcxzyw", "body": "@nikic https://github.com/llvm/llvm-project/blob/a9183b8899f2c02ba3710b27c0cbdde6831a627b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L411-L416\r\n\r\nI will post a fix later.\r\n" }, { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/GAUsBC\r\n```\r\ndefine i8 @src(i16 %a, i16 %b, i1 %cond) {\r\n %sel = select i1 %cond, i16 1, i16 254\r\n %cond1 = icmp ne i16 %b, 0\r\n %mask = and i16 %a, 255\r\n %cond2 = icmp ne i16 %mask, 255\r\n %cond3 = or i1 %cond1, %cond2\r\n %sel2 = select i1 %cond3, i16 %sel, i16 255\r\n %sub = sub i16 %sel2, %a\r\n %trunc = trunc i16 %sub to i8\r\n ret i8 %trunc\r\n}\r\n\r\ndefine i8 @tgt(i16 %a1, i16 %a2, i1 %cond) {\r\n %1 = trunc i16 %a1 to i8\r\n %conv6 = xor i8 %1, -1\r\n ret i8 %conv6\r\n}\r\n```" } ] }
true
null
128736
https://github.com/llvm/llvm-project/issues/128736
crash
02128342d2818e5a65846fec4179ed5344045102
2025-02-25T16:27:23
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "39bab1de33333ee3c62b586c4e8d26f8c443bc60", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 1389, 1397 ], [ 2849, 2859 ], [ 2915, 2926 ], [ 16466, 16474 ], [ 17075, 17081 ], [ 20449, 20456 ], [ 20678, 20684 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce", "removeInstructionsAndOperands", "BoUpSLP::vectorizeTree" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 39bab1de33333ee3c62b586c4e8d26f8c443bc60 Author: Alexey Bataev <[email protected]> Date: Wed Feb 26 14:12:05 2025 -0800 [SLP]Check if the operand for removal is the reduction operand, awaiting for the reduction If the operand of the instruction-to-be-removed is a reduction value, which is not reduced yet, and, thus, it has no users, it may be removed during operands analysis. Fixes #128736 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index b25b09306aca..e8c91ebd508c 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1389,9 +1389,10 @@ public: /// Vectorize the tree but with the list of externally used values \p /// ExternallyUsedValues. Values in this MapVector can be replaced but the /// generated extractvalue instructions. - Value * - vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, - Instruction *ReductionRoot = nullptr); + Value *vectorizeTree( + const ExtraValueToDebugLocsMap &ExternallyUsedValues, + Instruction *ReductionRoot = nullptr, + ArrayRef<std::tuple<Value *, unsigned, bool>> VectorValuesAndScales = {}); /// \returns the cost incurred by unwanted spills and fills, caused by /// holding live values over call sites. @@ -2849,11 +2850,13 @@ public: /// Remove instructions from the parent function and clear the operands of \p /// DeadVals instructions, marking for deletion trivially dead operands. template <typename T> - void removeInstructionsAndOperands(ArrayRef<T *> DeadVals) { + void removeInstructionsAndOperands( + ArrayRef<T *> DeadVals, + ArrayRef<std::tuple<Value *, unsigned, bool>> VectorValuesAndScales) { SmallVector<WeakTrackingVH> DeadInsts; for (T *V : DeadVals) { auto *I = cast<Instruction>(V); - DeletedInstructions.insert(I); + eraseInstruction(I); } DenseSet<Value *> Processed; for (T *V : DeadVals) { @@ -2915,12 +2918,17 @@ public: // loop iteration. if (auto *OpI = dyn_cast<Instruction>(OpV)) if (!DeletedInstructions.contains(OpI) && + (!OpI->getType()->isVectorTy() || + none_of(VectorValuesAndScales, + [&](const std::tuple<Value *, unsigned, bool> &V) { + return std::get<0>(V) == OpI; + })) && isInstructionTriviallyDead(OpI, TLI)) DeadInsts.push_back(OpI); } VI->removeFromParent(); - DeletedInstructions.insert(VI); + eraseInstruction(VI); SE->forgetValue(VI); } } @@ -16466,9 +16474,10 @@ Value *BoUpSLP::vectorizeTree() { return vectorizeTree(ExternallyUsedValues); } -Value * -BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, - Instruction *ReductionRoot) { +Value *BoUpSLP::vectorizeTree( + const ExtraValueToDebugLocsMap &ExternallyUsedValues, + Instruction *ReductionRoot, + ArrayRef<std::tuple<Value *, unsigned, bool>> VectorValuesAndScales) { // All blocks must be scheduled before any instructions are inserted. for (auto &BSIter : BlocksSchedules) { scheduleBlock(BSIter.second.get()); @@ -17075,7 +17084,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, // cache correctness. // NOTE: removeInstructionAndOperands only marks the instruction for deletion // - instructions are not deleted until later. - removeInstructionsAndOperands(ArrayRef(RemovedInsts)); + removeInstructionsAndOperands(ArrayRef(RemovedInsts), VectorValuesAndScales); Builder.ClearInsertionPoint(); InstrElementSize.clear(); @@ -20449,8 +20458,8 @@ public: InsertPt = GetCmpForMinMaxReduction(RdxRootInst); // Vectorize a tree. - Value *VectorizedRoot = - V.vectorizeTree(LocalExternallyUsedValues, InsertPt); + Value *VectorizedRoot = V.vectorizeTree( + LocalExternallyUsedValues, InsertPt, VectorValuesAndScales); // Update TrackedToOrig mapping, since the tracked values might be // updated. for (Value *RdxVal : Candidates) { @@ -20678,7 +20687,7 @@ public: Ignore->replaceAllUsesWith(P); } } - V.removeInstructionsAndOperands(RdxOps); + V.removeInstructionsAndOperands(RdxOps, VectorValuesAndScales); } } else if (!CheckForReusedReductionOps) { for (ReductionOpsType &RdxOps : ReductionOps)
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-with-removed-extracts.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=znver2 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(i32 %arg) {\n;\nbb:\n br label %bb1\n\nbb1:\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.", "body": "To reproduce run opt with the test below using -passes=slp-vectorizer.\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.ll\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @wombat(i32 %arg) #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n \nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul37, %bb1 ]\n %mul = mul i64 0, 0\n %trunc = trunc i64 %mul to i32\n %or = or i32 0, %trunc\n %or2 = or i32 0, %or\n %or3 = or i32 %or2, 0\n %mul4 = mul i32 0, %or3\n %mul5 = mul i32 %or3, 0\n %mul6 = mul i32 %mul5, %mul4\n %mul7 = mul i32 %mul6, %mul4\n %mul8 = mul i32 %mul7, %or3\n %mul9 = mul i64 0, 0\n %trunc10 = trunc i64 %mul9 to i32\n %or11 = or i32 0, %trunc10\n %or12 = or i32 %arg, %or11\n %or13 = or i32 %or12, 0\n %mul14 = mul i32 %or13, %mul8\n %mul15 = mul i32 %mul14, 0\n %mul16 = mul i32 %mul15, 0\n %mul17 = mul i32 %mul16, %or13\n %shl = shl i64 0, 0\n %mul18 = mul i64 %shl, 0\n %trunc19 = trunc i64 %mul18 to i32\n %or20 = or i32 0, %trunc19\n %or21 = or i32 0, %or20\n %or22 = or i32 %or21, 0\n %mul23 = mul i32 %or22, %mul17\n %mul24 = mul i32 %mul23, 0\n %mul25 = mul i32 %mul24, 0\n %mul26 = mul i32 %mul25, %or22\n %shl27 = shl i64 0, 0\n %mul28 = mul i64 %shl27, 0\n %trunc29 = trunc i64 %mul28 to i32\n %or30 = or i32 0, %trunc29\n %or31 = or i32 0, %or30\n %or32 = or i32 %or31, 0\n %mul33 = mul i32 0, %or32\n %mul34 = mul i32 %or32, %mul26\n %mul35 = mul i32 %mul34, %mul33\n %mul36 = mul i32 %mul35, %mul33\n %mul37 = mul i32 %mul36, %or32\n br label %bb1\n}\n\nattributes #0 = { \"target-cpu\"=\"znver2\" }\n```\n\nReproducer: https://godbolt.org/z/4PPzsMbP3\n\nStack dump:\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:4570: llvm::slpvectorizer::BoUpSLP::~BoUpSLP(): Assertion `I->use_empty() && \"trying to erase instruction with users.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\n #0 0x00000000054546a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54546a8)\n #1 0x0000000005452064 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007b5c5f242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007b5c5f2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007b5c5f242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007b5c5f2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007b5c5f22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007b5c5f239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000440d177 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x440d177)\n #9 0x00000000044d46ae llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#10 0x00000000044d50cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44d50cb)\n#11 0x000000000318a35e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x318a35e)\n#12 0x000000000524e9e0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524e9e0)\n#13 0x0000000000e6f88e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6f88e)\n#14 0x000000000524d2fb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524d2fb)\n#15 0x0000000000e6eb7e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6eb7e)\n#16 0x000000000524cd00 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524cd00)\n#17 0x0000000000935e7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935e7a)\n#18 0x00000000009294ec optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9294ec)\n#19 0x00007b5c5f229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#20 0x00007b5c5f229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#21 0x0000000000920dc5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920dc5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
109376
https://github.com/llvm/llvm-project/issues/109376
crash
1c47fa9b620d0abb280647b4f361ada43784d00e
2024-09-20T05:30:57
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "3db0f8c895d4e814a18b754f9afbb1e03bd839a5", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 18668, 18673 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 3db0f8c895d4e814a18b754f9afbb1e03bd839a5 Author: Alexey Bataev <[email protected]> Date: Mon Sep 23 10:49:54 2024 -0700 [SLP]Update TrackedToOrig mappings after reduction vectorization Need to update mappings in TrackedToOrig to correctly provide mapping between updated reduced value after vectorization and its original value, otherwise the compiler might miss this update and it may cause compiler crash later, when it tries to find the original instruction mapping for the updated value. Fixes https://github.com/llvm/llvm-project/issues/109376 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index a88702b81096..04b8fc09a724 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -18668,6 +18668,14 @@ public: // Vectorize a tree. Value *VectorizedRoot = V.vectorizeTree(LocalExternallyUsedValues, InsertPt); + // Update TrackedToOrig mapping, since the tracked values might be + // updated. + for (Value *RdxVal : Candidates) { + Value *OrigVal = TrackedToOrig.at(RdxVal); + Value *TransformedRdxVal = TrackedVals.at(OrigVal); + if (TransformedRdxVal != RdxVal) + TrackedToOrig.try_emplace(TransformedRdxVal, OrigVal); + } Builder.SetInsertPoint(InsertPt);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-value-vectorized-later.ll", "commands": [ "opt -S -passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i16 @test() {\nentry:\n %subi = add i16 0, 0\n %sub40.i = add i16 %subi, 0\n %sub41.i = add i16 %subi, 0\n %sub42.i = add i16 %subi, 0\n %sub43.i = add i16 %subi, 0\n %sub44.i = add i16 %subi, 0\n %sub45.i = add i16 %subi, 0\n %sub46.i = add i16 0, 0\n %sub47.i = add i16 0, 0\n %sub48.i = add i16 0, 0\n %sub49.i = add i16 0, 0\n %or40.i = or i16 %sub40.i, %sub41.i\n %or41.i = or i16 %or40.i, %sub42.i\n %or42.i = or i16 %or41.i, %sub43.i\n %or43.i = or i16 %or42.i, %sub44.i\n %or44.i = or i16 %or43.i, %sub45.i\n %or45.i = or i16 %or44.i, %sub46.i\n %or46.i = or i16 %or45.i, %sub47.i\n %or47.i = or i16 %or46.i, %sub48.i\n %or48.i = or i16 %or47.i, %sub49.i\n %or50.i = or i16 %or48.i, %subi\n %subii = add i16 0, 0\n %subi16.i = add i16 %subii, 0\n %subi17.i = add i16 %subii, 0\n %0 = or i16 %subi16.i, %subi17.i\n %1 = or i16 %0, %or50.i\n ret i16 %1\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `Iter != this->end() && \"DenseMap::at failed due to a missing key\"' failed.", "body": "Reproducer: https://godbolt.org/z/v5bqhPWqb\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i16 @test() {\r\nentry:\r\n %sub.i487.i.reass.i = add i16 0, 0\r\n %sub.i487.i.reass.40.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.41.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.42.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.43.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.44.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.45.i = add i16 %sub.i487.i.reass.i, 0\r\n %sub.i487.i.reass.46.i = add i16 0, 0\r\n %sub.i487.i.reass.47.i = add i16 0, 0\r\n %sub.i487.i.reass.48.i = add i16 0, 0\r\n %sub.i487.i.reass.49.i = add i16 0, 0\r\n %or374461.i.40.i = or i16 %sub.i487.i.reass.40.i, %sub.i487.i.reass.41.i\r\n %or374461.i.41.i = or i16 %or374461.i.40.i, %sub.i487.i.reass.42.i\r\n %or374461.i.42.i = or i16 %or374461.i.41.i, %sub.i487.i.reass.43.i\r\n %or374461.i.43.i = or i16 %or374461.i.42.i, %sub.i487.i.reass.44.i\r\n %or374461.i.44.i = or i16 %or374461.i.43.i, %sub.i487.i.reass.45.i\r\n %or374461.i.45.i = or i16 %or374461.i.44.i, %sub.i487.i.reass.46.i\r\n %or374461.i.46.i = or i16 %or374461.i.45.i, %sub.i487.i.reass.47.i\r\n %or374461.i.47.i = or i16 %or374461.i.46.i, %sub.i487.i.reass.48.i\r\n %or374461.i.48.i = or i16 %or374461.i.47.i, %sub.i487.i.reass.49.i\r\n %or374461.i.50.i = or i16 %or374461.i.48.i, %sub.i487.i.reass.i\r\n %sub.i487.i96.reass.i = add i16 0, 0\r\n %sub.i487.i96.reass.16.i = add i16 %sub.i487.i96.reass.i, 0\r\n %sub.i487.i96.reass.17.i = add i16 %sub.i487.i96.reass.i, 0\r\n %0 = or i16 %sub.i487.i96.reass.16.i, %sub.i487.i96.reass.17.i\r\n %1 = or i16 %0, %or374461.i.50.i\r\n ret i16 %1\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/ADT/DenseMap.h:204: const ValueT& llvm::DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT>::at(llvm::DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT>::const_arg_type_t<KeyT>) const [with DerivedT = llvm::DenseMap<llvm::Value*, llvm::Value*>; KeyT = llvm::Value*; ValueT = llvm::Value*; KeyInfoT = llvm::DenseMapInfo<llvm::Value*, void>; BucketT = llvm::detail::DenseMapPair<llvm::Value*, llvm::Value*>; llvm::DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT>::const_arg_type_t<KeyT> = const llvm::Value*]: Assertion `Iter != this->end() && \"DenseMap::at failed due to a missing key\"' 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 0x0000000005035d68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5035d68)\r\n #1 0x00000000050334ac SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000707bdcc42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x0000707bdcc969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000707bdcc42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x0000707bdcc287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x0000707bdcc2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x0000707bdcc39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000409326e llvm::DenseMapBase<llvm::DenseMap<llvm::Value*, llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, llvm::Value*>>, llvm::Value*, llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, llvm::Value*>>::at(llvm::Value const*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x409326e)\r\n #9 0x000000000413473f (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#10 0x00000000041370d1 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+0x41370d1)\r\n#11 0x000000000413b996 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#12 0x000000000413ff36 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x413ff36)\r\n#13 0x0000000004146401 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#14 0x000000000414708b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x414708b)\r\n#15 0x0000000002f1a1ae 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+0x2f1a1ae)\r\n#16 0x0000000004e38158 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e38158)\r\n#17 0x0000000000e0b02e 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+0xe0b02e)\r\n#18 0x0000000004e36b7e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e36b7e)\r\n#19 0x0000000000e0a83e 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+0xe0a83e)\r\n#20 0x0000000004e365b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e365b0)\r\n#21 0x00000000008feef2 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+0x8feef2)\r\n#22 0x00000000008f1d7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f1d7c)\r\n#23 0x0000707bdcc29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#24 0x0000707bdcc29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#25 0x00000000008e984e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e984e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: e8a739062490ce1bb30974f216ba187cd7b5a2a4", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": [ [ 361, 368 ], [ 376, 382 ] ], "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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;.", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6539, 6546 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInstructionCost" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": [ [ 45, 59 ], [ 79, 90 ] ], "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": [ "clearAssumptionsOfUsers" ], "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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", "lli_expected_out": null, "additional_args": 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
89669
https://github.com/llvm/llvm-project/issues/89669
miscompilation
d97cdd7d088b11b45038112a5f7fe5cbf60a6461
2024-04-22T21:27:36
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a1b1c4a6d1d52916c5d885170a5f54632d579cdc", "components": [ "InstCombine", "ValueTracking" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ [ 320, 326 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ [ 8042, 8058 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": [ [ 131, 137 ] ], "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": [ "Negator::visitImpl" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": [ "llvm::isKnownNegation", "matchMinMax" ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit a1b1c4a6d1d52916c5d885170a5f54632d579cdc Author: Nikita Popov <[email protected]> Date: Wed Apr 24 10:56:26 2024 +0900 [InstCombine] Fix miscompile in negation of select (#89698) Swapping the operands of a select is not valid if one hand is more poisonous that the other, because the negation zero contains poison elements. Fix this by adding an extra parameter to isKnownNegation() to forbid poison elements. I've implemented this using manual checks to avoid needing four variants for the NeedsNSW/AllowPoison combinations. Maybe there is a better way to do this... Fixes https://github.com/llvm/llvm-project/issues/89669. diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index a2fa8f6064e1..571e44cdac26 100644 --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -131,7 +131,8 @@ bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth = 0); /// Currently can recoginze Value pair: /// 1: <X, Y> if X = sub (0, Y) or Y = sub (0, X) /// 2: <X, Y> if X = sub (A, B) and Y = sub (B, A) -bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW = false); +bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW = false, + bool AllowPoison = true); /// Returns true if the give value is known to be non-negative. bool isKnownNonNegative(const Value *V, const SimplifyQuery &SQ, diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 21e3f8a4cc52..7501f78ca23b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8042,17 +8042,27 @@ static SelectPatternResult matchMinMax(CmpInst::Predicate Pred, return {SPF_UNKNOWN, SPNB_NA, false}; } -bool llvm::isKnownNegation(const Value *X, const Value *Y, bool NeedNSW) { +bool llvm::isKnownNegation(const Value *X, const Value *Y, bool NeedNSW, + bool AllowPoison) { assert(X && Y && "Invalid operand"); - // X = sub (0, Y) || X = sub nsw (0, Y) - if ((!NeedNSW && match(X, m_Sub(m_ZeroInt(), m_Specific(Y)))) || - (NeedNSW && match(X, m_NSWNeg(m_Specific(Y))))) + auto IsNegationOf = [&](const Value *X, const Value *Y) { + if (!match(X, m_Neg(m_Specific(Y)))) + return false; + + auto *BO = cast<BinaryOperator>(X); + if (NeedNSW && !BO->hasNoSignedWrap()) + return false; + + auto *Zero = cast<Constant>(BO->getOperand(0)); + if (!AllowPoison && !Zero->isNullValue()) + return false; + return true; + }; - // Y = sub (0, X) || Y = sub nsw (0, X) - if ((!NeedNSW && match(Y, m_Sub(m_ZeroInt(), m_Specific(X)))) || - (NeedNSW && match(Y, m_NSWNeg(m_Specific(X))))) + // X = -Y or Y = -X + if (IsNegationOf(X, Y) || IsNegationOf(Y, X)) return true; // X = sub (A, B), Y = sub (B, A) || X = sub nsw (A, B), Y = sub nsw (B, A) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index d697f361dec0..ed2a98ba4ae4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -320,7 +320,8 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { return NegatedPHI; } case Instruction::Select: { - if (isKnownNegation(I->getOperand(1), I->getOperand(2))) { + if (isKnownNegation(I->getOperand(1), I->getOperand(2), /*NeedNSW=*/false, + /*AllowPoison=*/false)) { // Of one hand of select is known to be negation of another hand, // just swap the hands around. auto *NewSelect = cast<SelectInst>(I->clone());
[ { "file": "llvm/test/Transforms/InstCombine/sub-of-negatible.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "negate_select_of_negation_poison", "test_body": "define <2 x i32> @negate_select_of_negation_poison(<2 x i1> %c, <2 x i32> %x) {\n %neg = sub <2 x i32> <i32 0, i32 poison>, %x\n %sel = select <2 x i1> %c, <2 x i32> %neg, <2 x i32> %x\n %neg2 = sub <2 x i32> zeroinitializer, %sel\n ret <2 x i32> %neg2\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dont_negate_ordinary_select", "test_body": "define i8 @dont_negate_ordinary_select(i8 %x, i8 %y, i8 %z, i1 %c) {\n %t0 = select i1 %c, i8 %x, i8 %y\n %t1 = sub i8 %z, %t0\n ret i8 %t1\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "miscompile of vector double-negation + select by InstCombine", "body": "https://alive2.llvm.org/ce/z/N1RVAr\r\n\r\nthis:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0) {\r\n %2 = sub <4 x i32> zeroinitializer, %0\r\n %3 = select <4 x i1> <i1 false, i1 true, i1 poison, i1 poison>, <4 x i32> %2, <4 x i32> %0\r\n %4 = sub <4 x i32> zeroinitializer, %3\r\n ret <4 x i32> %4\r\n}\r\n```\r\nis being optimized to:\r\n```llvm\r\ndefine <4 x i32> @f(<4 x i32> %0) {\r\n ret <4 x i32> %0\r\n}\r\n```\r\nhere's Alive's work explaining why this is wrong:\r\n```\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<4 x i32> %#0 = < #x00000001 (1), poison, poison, poison >\r\n\r\nSource:\r\n<4 x i32> %#2 = < #xffffffff (4294967295, -1), poison, poison, poison >\r\n<4 x i32> %#3 = < #x00000001 (1), poison, poison, poison >\r\n<4 x i32> %#4 = < #xffffffff (4294967295, -1), poison, poison, poison >\r\n\r\nTarget:\r\nSource value: < #xffffffff (4294967295, -1), poison, poison, poison >\r\nTarget value: < #x00000001 (1), poison, poison, poison >\r\n```\r\n\r\ncc @nunoplopes @hatsunespica\r\n\r\n", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "topperc", "body": "I think the problem is this code in Negator::visitImpl.\r\n\r\n```\r\n case Instruction::Select: {\r\n if (isKnownNegation(I->getOperand(1), I->getOperand(2))) { \r\n // Of one hand of select is known to be negation of another hand, \r\n // just swap the hands around. \r\n auto *NewSelect = cast<SelectInst>(I->clone()); \r\n // Just swap the operands of the select. \r\n NewSelect->swapValues(); \r\n // Don't swap prof metadata, we didn't change the branch behavior. \r\n NewSelect->setName(I->getName() + \".neg\"); \r\n Builder.Insert(NewSelect); \r\n return NewSelect; \r\n } \r\n```\r\n\r\nThe IR at the time of that code running was\r\n```\r\n%2 = sub <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, %0\r\n%3 = select <4 x i1> <i1 false, i1 true, i1 poison, i1 poison>, <4 x i32> %2, <4 x i32> %0\r\n%4 = sub <4 x i32> zeroinitializer, %3\r\n```\r\n\r\nSo operand element 0 of %2 is poison. This occurred because element 0 isn't selected so SimplifiedDemandedVectorElts replaced with poison.\r\n\r\nOnce Negator swaps the operands, now element 1 of %2 is never selected so we end up with `sub <4 x i32> poison, %0`\r\n\r\nIt doesn't look like swapping the operands of the select is poison safe.\r\n\r\nCC @nikic " }, { "author": "nikic", "body": "Yeah, that analysis sounds right to me. With that in mind, a more direct test case would be:\r\n```llvm\r\ndefine <2 x i32> @f(<2 x i1> %c, <2 x i32> %x) {\r\n %neg = sub <2 x i32> <i32 0, i32 poison>, %x\r\n %sel = select <2 x i1> %c, <2 x i32> %neg, <2 x i32> %x\r\n %neg2 = sub <2 x i32> zeroinitializer, %sel\r\n ret <2 x i32> %neg2\r\n}\r\n```" }, { "author": "regehr", "body": "off topic but do we want an llvm-reduce pass that shrinks vectors? and maybe also shrinks lane sizes? if so I could work on that sort of thing this summer" }, { "author": "XChy", "body": "> off topic but do we want an llvm-reduce pass that shrinks vectors? and maybe also shrinks lane sizes? if so I could work on that sort of thing this summer\r\n\r\nSounds great to me. I think some SLPVectorizer testcases that involve 16 or even 32 lanes should be further reduced." } ] }
true
null
91691
https://github.com/llvm/llvm-project/issues/91691
miscompilation
1fadb2b0c881ced247931f442fdee6c4ed96dccb
2024-05-10T02:43:43
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "b5f4210e9f51f938ae517f219f04f9ab431a2684", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ [ 3343, 3349 ], [ 3366, 3371 ], [ 3379, 3384 ], [ 3448, 3461 ] ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [ "foldBitCeil", "isSafeToRemoveBitCeilSelect" ], "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit b5f4210e9f51f938ae517f219f04f9ab431a2684 Author: Yingwei Zheng <[email protected]> Date: Mon May 13 14:27:59 2024 +0800 [InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776) See the following case: ``` define i32 @src1(i32 %x) { %dec = sub nuw i32 -2, %x %ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false) %sub = sub nsw i32 32, %ctlz %shl = shl i32 1, %sub %ugt = icmp ult i32 %x, -2 %sel = select i1 %ugt, i32 %shl, i32 1 ret i32 %sel } define i32 @tgt1(i32 %x) { %dec = sub nuw i32 -2, %x %ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false) %sub = sub nsw i32 32, %ctlz %and = and i32 %sub, 31 %shl = shl nuw i32 1, %and ret i32 %shl } ``` `nuw` in `%dec` should be dropped after the select instruction is eliminated. Alive2: https://alive2.llvm.org/ce/z/7S9529 Fixes https://github.com/llvm/llvm-project/issues/91691. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index ee090e012508..a3ddb402bf66 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3343,7 +3343,8 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { // pattern. static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, const APInt *Cond1, Value *CtlzOp, - unsigned BitWidth) { + unsigned BitWidth, + bool &ShouldDropNUW) { // The challenge in recognizing std::bit_ceil(X) is that the operand is used // for the CTLZ proper and select condition, each possibly with some // operation like add and sub. @@ -3366,6 +3367,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, ConstantRange CR = ConstantRange::makeExactICmpRegion( CmpInst::getInversePredicate(Pred), *Cond1); + ShouldDropNUW = false; + // Match the operation that's used to compute CtlzOp from CommonAncestor. If // CtlzOp == CommonAncestor, return true as no operation is needed. If a // match is found, execute the operation on CR, update CR, and return true. @@ -3379,6 +3382,7 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, return true; } if (match(CtlzOp, m_Sub(m_APInt(C), m_Specific(CommonAncestor)))) { + ShouldDropNUW = true; CR = ConstantRange(*C).sub(CR); return true; } @@ -3448,14 +3452,20 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) { Pred = CmpInst::getInversePredicate(Pred); } + bool ShouldDropNUW; + if (!match(FalseVal, m_One()) || !match(TrueVal, m_OneUse(m_Shl(m_One(), m_OneUse(m_Sub(m_SpecificInt(BitWidth), m_Value(Ctlz)))))) || !match(Ctlz, m_Intrinsic<Intrinsic::ctlz>(m_Value(CtlzOp), m_Zero())) || - !isSafeToRemoveBitCeilSelect(Pred, Cond0, Cond1, CtlzOp, BitWidth)) + !isSafeToRemoveBitCeilSelect(Pred, Cond0, Cond1, CtlzOp, BitWidth, + ShouldDropNUW)) return nullptr; + if (ShouldDropNUW) + cast<Instruction>(CtlzOp)->setHasNoUnsignedWrap(false); + // Build 1 << (-CTLZ & (BitWidth-1)). The negation likely corresponds to a // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth // is an integer constant. Masking with BitWidth-1 comes free on some
[ { "file": "llvm/test/Transforms/InstCombine/bit_ceil.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "pr91691", "test_body": "define i32 @pr91691(i32 %0) {\n %2 = sub nuw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "bit_ceil_v4i32", "test_body": "define <4 x i32> @bit_ceil_v4i32(<4 x i32> %x) {\n %dec = add <4 x i32> %x, splat (i32 -1)\n %ctlz = tail call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %dec, i1 false)\n %sub = sub <4 x i32> splat (i32 32), %ctlz\n %shl = shl <4 x i32> splat (i32 1), %sub\n %ugt = icmp ugt <4 x i32> %x, splat (i32 1)\n %sel = select <4 x i1> %ugt, <4 x i32> %shl, <4 x i32> splat (i32 1)\n ret <4 x i32> %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i32> @llvm.ctlz.v4i32(<4 x i32>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr91691_keep_nsw", "test_body": "define i32 @pr91691_keep_nsw(i32 %0) {\n %2 = sub nsw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "instcombine removes a select, making code more poisonous", "body": "https://alive2.llvm.org/ce/z/c__jy8\r\n\r\nthis function:\r\n```llvm\r\ndefine i32 @f(i32 %0) {\r\n %2 = sub nuw i32 -2, %0\r\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\r\n %4 = sub i32 32, %3\r\n %5 = shl i32 1, %4\r\n %6 = icmp ult i32 %0, -2\r\n %7 = select i1 %6, i32 %5, i32 1\r\n ret i32 %7\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nis getting rewritten to not have the select, but the select was blocking a poison value. the bad thing happens when -1 is passed as an argument, see the Alive link for a detailed execution trace\r\n\r\n```llvm\r\ndefine i32 @f(i32 %0) {\r\n %2 = sub nuw i32 -2, %0\r\n %3 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %2, i1 false)\r\n %4 = sub nsw i32 0, %3\r\n %5 = and i32 %4, 31\r\n %6 = shl nuw i32 1, %5\r\n ret i32 %6\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\ncc @nunoplopes ", "author": "regehr", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
125357
https://github.com/llvm/llvm-project/issues/125357
crash
cdeeb390a9ea21540fc44ba10dede66fbc0b2fc8
2025-02-01T20:11:30
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "0c70a26f46e4efd5a29eb281ff99d2cf7f04c6f6", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 20147, 20153 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 0c70a26f46e4efd5a29eb281ff99d2cf7f04c6f6 Author: Alexey Bataev <[email protected]> Date: Mon Feb 3 04:37:49 2025 -0800 [SLP]Clear root node reordering only if the root node is not re-used in graph The reordering of the root node can be safely cleared only if the root node is not reused, otherwise the graph might be broken Fixes #125357 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4f83b9cfa18d..539c9227af7e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -20147,7 +20147,7 @@ public: } V.reorderTopToBottom(); // No need to reorder the root node at all. - V.reorderBottomToTop(/*IgnoreReorder=*/true); + V.reorderBottomToTop(!V.doesRootHaveInTreeUses()); // Keep extracted other reduction values, if they are used in the // vectorization trees. BoUpSLP::ExtraValueToDebugLocsMap LocalExternallyUsedValues(
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/root-node-reordered-reused.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "; ModuleID = 'test.ll'\nsource_filename = \"test.c\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i32 %0) {\nentry:\n %tobool.not = icmp eq i32 %0, 0\n br i1 %tobool.not, label %if.end6, label %if.then\n\nif.then: ; preds = %entry\n br i1 %tobool.not, label %if.end, label %i\n\nif.end: ; preds = %if.then\n br i1 %tobool.not, label %if.end6, label %i\n\nif.end6: ; preds = %if.end, %entry\n %h.0 = phi i32 [ %0, %if.end ], [ 0, %entry ]\n br i1 %tobool.not, label %i, label %if.end13\n\ni: ; preds = %if.end13, %if.end6, %if.end, %if.then\n %h.1 = phi i32 [ %0, %if.then ], [ %h.2, %if.end13 ], [ %0, %if.end ], [ %h.0, %if.end6 ]\n %j.0 = phi i32 [ undef, %if.then ], [ %j.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %k.0 = phi i32 [ undef, %if.then ], [ %k.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %l.0 = phi i32 [ undef, %if.then ], [ %l.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %or = or i32 %j.0, %h.1\n %or9 = or i32 %or, %k.0\n %or10 = or i32 %or9, %l.0\n %tobool11.not = icmp eq i32 %or10, 0\n br i1 %tobool11.not, label %if.end13, label %land.rhs\n\nland.rhs: ; preds = %i\n br label %if.end13\n\nif.end13: ; preds = %i, %land.rhs, %if.end6\n %h.2 = phi i32 [ %h.0, %if.end6 ], [ %h.1, %land.rhs ], [ %h.1, %i ]\n %j.1 = phi i32 [ %0, %if.end6 ], [ %j.0, %land.rhs ], [ %j.0, %i ]\n %k.1 = phi i32 [ %0, %if.end6 ], [ %k.0, %land.rhs ], [ %k.0, %i ]\n %l.1 = phi i32 [ %0, %if.end6 ], [ %l.0, %land.rhs ], [ %l.0, %i ]\n br i1 true, label %if.end15, label %i\n\nif.end15: ; preds = %if.end13\n ret i32 0\n\n; uselistorder directives\n uselistorder i32 %k.0, { 1, 2, 0 }\n uselistorder i32 %l.0, { 1, 2, 0 }\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `TE->isSame(VL) && \"Expected same scalars.\"' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/6ca9841xE\n\n```\n[512] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 7612dcc6e8d8e7f19b364084effbb01946294720)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[513] % \n[513] % clangtk -O3 small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3011: llvm::slpvectorizer::BoUpSLP::TreeEntry* llvm::slpvectorizer::BoUpSLP::getVectorizedOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int): Assertion `TE->isSame(VL) && \"Expected same scalars.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250201-clangtk-m64-O3-build-174536/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250201-clangtk-m64-O3-build-174536/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/21 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-b035e7.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x00005596296c84af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x479d4af)\n #1 0x00005596296c5c84 SignalHandler(int) Signals.cpp:0:0\n #2 0x00007fe817057420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007fe816a8e00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007fe816a6d859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007fe816a6d729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007fe816a6d729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007fe816a7efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x000055962b1df5c7 llvm::slpvectorizer::BoUpSLP::getSpillCost() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x62b45c7)\n #9 0x000055962b243030 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6318030)\n#10 0x000055962b247f34 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#11 0x000055962b24a205 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x631f205)\n#12 0x000055962b24ee25 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6323e25)\n#13 0x000055962b24fedb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#14 0x000055962b253720 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6328720)\n#15 0x000055962b259f46 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#16 0x000055962b25aaa3 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x632faa3)\n#17 0x000055962ac7c7e6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5d517e6)\n#18 0x000055962903ed49 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4113d49)\n#19 0x000055962693a376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1a0f376)\n#20 0x000055962903d5b2 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x41125b2)\n#21 0x0000559626938aa6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1a0daa6)\n#22 0x000055962903cfd1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4111fd1)\n#23 0x0000559629991596 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#24 0x0000559629995253 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4a6a253)\n#25 0x000055962a09f2ce clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51742ce)\n#26 0x000055962ba0f29c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6ae429c)\n#27 0x000055962a09f708 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5174708)\n#28 0x000055962a3719d9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x54469d9)\n#29 0x000055962a2f25be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x53c75be)\n#30 0x000055962a466746 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x553b746)\n#31 0x00005596264d4a87 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a9a87)\n#32 0x00005596264cc33a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x00005596264d0471 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a5471)\n#34 0x00005596263bb29b main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x149029b)\n#35 0x00007fe816a6f083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#36 0x00005596264cbdce _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a0dce)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 7612dcc6e8d8e7f19b364084effbb01946294720)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-401f68.c\nclangtk: note: diagnostic msg: /tmp/small-401f68.sh\nclangtk: note: diagnostic msg: \n\n********************\n[514] % \n[514] % cat small.c\nint a, b, c, d, e;\nvolatile int f;\nint main() {\n int h = 0, j, k, l;\n if (d) {\n h = c;\n if (f)\n goto i;\n if (f)\n goto i;\n }\n l = j = k = d;\n if (!b)\n i:\n (l | (h | j) | k) && f;\n if (a != e)\n goto i;\n return 0;\n}\n```\n\n\n", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/TWadzP8Gc\n" } ] }
true
null
122558
https://github.com/llvm/llvm-project/issues/122558
crash
25f28ddd69ed2453726c0934ba6feea8ae6f10f8
2025-01-11T00:36:48
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "1de3dc7d23dd6b856efad3a3a04f2396328726d7", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 4052, 4058 ], [ 4064, 4069 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::computeMaxVF" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 1de3dc7d23dd6b856efad3a3a04f2396328726d7 Author: Florian Hahn <[email protected]> Date: Tue Jan 14 22:07:38 2025 +0000 [LV] Bail out early if BTC+1 wraps. Currently we fail to detect the case where BTC + 1 wraps, i.e. the vector trip count is 0, In those cases, the minimum iteration count check will fail, and the vector code will never be executed. Explicitly check for this condition in computeMaxVF and avoid trying to vectorize alltogether. Note that a number of tests needed to be updated, because the vector loop would never be executed given the input IR. Fixes https://github.com/llvm/llvm-project/issues/122558. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 744faef19243..fe2fb5e9faae 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4052,7 +4052,8 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { return FixedScalableVFPair::getNone(); } - unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop); + ScalarEvolution *SE = PSE.getSE(); + unsigned TC = SE->getSmallConstantTripCount(TheLoop); unsigned MaxTC = PSE.getSmallConstantMaxTripCount(); LLVM_DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n'); if (TC != MaxTC) @@ -4064,6 +4065,22 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { return FixedScalableVFPair::getNone(); } + // If BTC matches the widest induction type and is -1 then the trip count + // computation will wrap to 0 and the vector trip count will be 0. Do not try + // to vectorize. + const SCEV *BTC = SE->getBackedgeTakenCount(TheLoop); + if (!isa<SCEVCouldNotCompute>(BTC) && + BTC->getType()->getScalarSizeInBits() >= + Legal->getWidestInductionType()->getScalarSizeInBits() && + SE->isKnownPredicate(CmpInst::ICMP_EQ, BTC, + SE->getMinusOne(BTC->getType()))) { + reportVectorizationFailure( + "Trip count computation wrapped", + "backedge-taken count is -1, loop trip count wrapped to 0", + "TripCountWrapped", ORE, TheLoop); + return FixedScalableVFPair::getNone(); + } + switch (ScalarEpilogueStatus) { case CM_ScalarEpilogueAllowed: return computeFeasibleMaxVF(MaxTC, UserVF, false);
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll", "commands": [ "opt -mattr=+dotprod -passes=loop-vectorize -force-vector-interleave=1 -S < %s" ], "tests": [ { "test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-mixed.ll", "commands": [ "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+i8mm,+dotprod -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+dotprod -S < %s" ], "tests": [ { "test_name": "dotp_z_s", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_z_s(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dotp_s_z", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_s_z(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-neon.ll", "commands": [ "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -vectorizer-maximize-bandwidth -S < %s" ], "tests": [ { "test_name": "dotp_unrolled", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_predicated_pragma", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_not_loop_carried", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_different_types", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_not_phi", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_extend_user", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_predicated", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-interleave=1 -enable-epilogue-vectorization=false -S < %s", "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -S < %s", "opt -passes=loop-vectorize -force-vector-interleave=1 -vectorizer-maximize-bandwidth -enable-epilogue-vectorization=false -S < %s" ], "tests": [ { "test_name": "not_dotp_not_phi2", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @not_dotp_not_phi2(ptr %matrix, i32 %n) #0 {\nentry:\n %cmp = icmp sgt i32 %n, 0\n br i1 %cmp, label %for.preheader, label %exit\n\nfor.preheader: ; preds = %entry\n %load.a = load i8, ptr null, align 1\n %load.a1 = load i8, ptr inttoptr (i64 1 to ptr), align 1\n %a.ext = sext i8 %load.a to i32\n %a.ext1 = sext i8 %load.a1 to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.preheader\n %iv = phi i32 [ %iv.next, %for.body ], [ 0, %for.preheader ]\n %ptr = phi ptr [ %scevgep, %for.body ], [ %matrix, %for.preheader ]\n %accum = phi i32 [ %add.1, %for.body ], [ 0, %for.preheader ]\n %gep.b = getelementptr i8, ptr %ptr, i64 1\n %gep.b1 = getelementptr i8, ptr %ptr, i64 2\n %load.b = load i8, ptr %gep.b, align 1\n %b.ext = sext i8 %load.b to i32\n %mul = mul nsw i32 %a.ext, %b.ext\n %add = add i32 %mul, %accum\n %load.b1 = load i8, ptr %gep.b1, align 1\n %b.ext1 = sext i8 %load.b1 to i32\n %mul.1 = mul nsw i32 %a.ext1, %b.ext1\n %add.1 = add i32 %mul.1, %add\n %scevgep = getelementptr i8, ptr %ptr, i64 16\n %iv.next = add nuw nsw i32 %iv, 1\n %exitcond.not = icmp eq i32 %iv.next, %n\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %add.1.lcssa = phi i32 [ %add.1, %for.body ]\n %add.float = sitofp i32 %add.1.lcssa to float\n br label %exit\n\nexit: ; preds = %for.exit, %entry\n %result = phi float [ 0.000000e+00, %entry ], [ %add.float, %for.exit ]\n store float %result, ptr %matrix, align 4\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_ext_outside_plan2", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan2(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.b, %ext.a\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dotp_unrolled", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_predicated_pragma", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dotp_cost_disagreement", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @dotp_cost_disagreement(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i.iv = phi i64 [ 0, %entry ], [ %i.iv.next, %for.body ]\n %sum = phi i64 [ 0, %entry ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds nuw i8, ptr %a, i64 %i.iv\n %0 = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %0 to i64\n %i.iv.next = add nuw nsw i64 %i.iv, 1\n %arrayidx2 = getelementptr inbounds nuw i8, ptr %b, i64 %i.iv.next\n %1 = load i8, ptr %arrayidx2, align 1\n %conv3 = zext i8 %1 to i64\n %mul = mul nuw nsw i64 %conv3, %conv\n %add = add i64 %sum, %mul\n %exitcond.not = icmp eq i64 %i.iv.next, 16\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i64 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_not_loop_carried", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_different_types", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_not_phi", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_extend_user", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_ext_outside_plan", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.a, %ext.b\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_dotp_predicated", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll", "commands": [ "opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon -S < %s" ], "tests": [ { "test_name": "not_dotp", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/store-costs-sve.ll", "commands": [ "opt -p loop-vectorize -S %s", "opt -p loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S %s" ], "tests": [ { "test_name": "trunc_store", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @trunc_store(ptr %dst, ptr %src, i16 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %x.ext = zext i16 %x to i64\n %l = load i64, ptr %src, align 8\n %and = and i64 %l, %x.ext\n %trunc = trunc i64 %and to i8\n %gep = getelementptr i8, ptr %dst, i64 %iv\n store i8 %trunc, ptr %gep, align 1\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll", "commands": [ "opt -mattr=+neon,+dotprod -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -disable-output %s 2>&1" ], "tests": [ { "test_name": "print_partial_reduction", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @print_partial_reduction(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/Hexagon/maximum-vf-crash.ll", "commands": [ "opt -mtriple=hexagon -hexagon-autohvx -passes=loop-vectorize -S < %s 2>&1" ], "tests": [ { "test_name": "f", "test_body": "target datalayout = \"e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048\"\n\n; Function Attrs: optsize\ndefine i32 @f(ptr %src) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %g.016 = phi i32 [ 0, %entry ], [ %g.1.lcssa, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = load i8, ptr %src, align 1\n %g.1.lcssa = add i32 %g.016, 1\n %iv.next = add nsw i32 %iv, 1\n %exitcond = icmp eq i32 %iv.next, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %g.1.lcssa\n}\n\nattributes #0 = { optsize \"target-features\"=\"+hvx-length128b\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "second_lshr_operand_zero_via_scev", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @second_lshr_operand_zero_via_scev() {\nentry:\n %ext.0 = sext i8 0 to i32\n br label %loops\n\nloops: ; preds = %loops, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loops ]\n %red = phi i64 [ 0, %entry ], [ %red.next, %loops ]\n %c = icmp eq i64 %iv, 0\n %and = and i64 %iv, 0\n %0 = trunc i64 %iv to i32\n %shr = lshr i32 %0, %ext.0\n %conv.1 = zext i32 %shr to i64\n %red.next.v = select i1 %c, i64 %and, i64 %conv.1\n %red.next = or i64 %red.next.v, %red\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loops\n\nexit: ; preds = %loops\n %res = phi i64 [ %red.next, %loops ]\n ret i64 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": [ "opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S" ], "tests": [ { "test_name": "narrowed_reduction", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {\nentry:\n %conv = zext i1 %cmp to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]\n %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]\n %and = and i32 %or13, 1\n %or = or i32 %and, %conv\n %inc = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 16\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %or\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll", "commands": [ "opt %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S" ], "tests": [ { "test_name": "drop_zext_nneg", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc-linux-gnu\"\n\n; Function Attrs: noinline nounwind uwtable\ndefine void @drop_zext_nneg(ptr noalias %p, ptr noalias %p1) #0 {\nentry:\n br label %body\n\nbody: ; preds = %else, %entry\n %iv = phi i64 [ %next, %else ], [ 0, %entry ]\n %0 = trunc i64 %iv to i32\n %c = icmp eq i32 %0, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %body\n %zext = zext nneg i32 %0 to i64\n %idx1 = getelementptr double, ptr %p, i64 %zext\n %idx2 = getelementptr double, ptr %p, i64 %zext\n %1 = load double, ptr %idx2, align 8\n br label %else\n\nelse: ; preds = %then, %body\n %phi = phi double [ %1, %then ], [ 0.000000e+00, %body ]\n store double %phi, ptr %p1, align 8\n %next = add i64 %iv, 1\n %cmp = icmp eq i64 %next, 1024\n br i1 %cmp, label %exit, label %body\n\nexit: ; preds = %else\n ret void\n}\n\nattributes #0 = { noinline nounwind uwtable \"target-features\"=\"+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/interleave-cost.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "test_free_instructions_feeding_geps_for_interleave_groups", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @test_free_instructions_feeding_geps_for_interleave_groups(ptr noalias %p.invar, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.0 = load float, ptr %p.invar, align 4\n %iv.mul = shl i64 %iv, 2\n %gep.dst.19 = getelementptr float, ptr %dst.1, i64 %iv.mul\n store float %l.0, ptr %gep.dst.19, align 4\n %l.1 = load float, ptr %p.invar, align 4\n %add.1 = or disjoint i64 %iv.mul, 1\n %gep.dst.119 = getelementptr float, ptr %dst.1, i64 %add.1\n store float %l.1, ptr %gep.dst.119, align 4\n %add.2 = or disjoint i64 %iv.mul, 2\n %gep.dst.129 = getelementptr float, ptr %dst.1, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.129, align 4\n %add.3 = or disjoint i64 %iv.mul, 3\n %gep.dst.140 = getelementptr float, ptr %dst.1, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.140, align 4\n %l.2 = load float, ptr %p.invar, align 4\n %gep.dst.247 = getelementptr float, ptr %dst.2, i64 %iv.mul\n store float %l.2, ptr %gep.dst.247, align 4\n %gep.dst.255 = getelementptr float, ptr %dst.2, i64 %add.1\n store float 0.000000e+00, ptr %gep.dst.255, align 4\n %gep.dst.265 = getelementptr float, ptr %dst.2, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.265, align 4\n %gep.dst.276 = getelementptr float, ptr %dst.2, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.276, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/replicate-uniform-call.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "smax_call_uniform", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @smax_call_uniform(ptr %dst, i64 %x) {\nentry:\n %c = icmp ult i8 -68, -69\n %mul = mul nuw nsw i64 %x, 0\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %rem = urem i64 %mul, %x\n %smax = tail call i64 @llvm.smax.i64(i64 %rem, i64 0)\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %p = phi i64 [ 1, %loop.header ], [ %smax, %else ]\n %add = add i64 %p, 1\n %gep = getelementptr i64, ptr %dst, i64 %add\n store i64 0, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.smax.i64(i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/epilog-vectorization-vector-trip-count-zero.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=2 -epilogue-vectorization-force-VF=2 -S %s" ], "tests": [ { "test_name": "vector_trip_count_0_as_btc_is_all_1", "test_body": "target datalayout = \"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64\"\n\ndefine void @vector_trip_count_0_as_btc_is_all_1(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i32 %iv, -1\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test_resinking_required", "test_body": "define double @test_resinking_required(ptr %p, ptr noalias %a, ptr noalias %b) {\nEntry:\n br label %Loop\n\nLoop: ; preds = %Loop, %Entry\n %for.1 = phi double [ %l1, %Loop ], [ 0.000000e+00, %Entry ]\n %for.2 = phi double [ %l2, %Loop ], [ 0.000000e+00, %Entry ]\n %for.3 = phi double [ %for.2, %Loop ], [ 0.000000e+00, %Entry ]\n %iv = phi i64 [ %iv.next, %Loop ], [ 0, %Entry ]\n %USE_2_FORS = fdiv double %for.3, %for.1\n %div = fdiv double 0.000000e+00, %for.1\n %l1 = load double, ptr %a, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %l2 = load double, ptr %b, align 8\n store double %div, ptr %p, align 8\n %cond = icmp eq i64 %iv.next, 1000\n br i1 %cond, label %End, label %Loop\n\nEnd: ; preds = %Loop\n %res.1 = fadd double %for.1, %for.2\n %res.2 = fadd double %res.1, %for.3\n ret double %res.2\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/if-pred-stores.ll", "commands": [ "opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s", "opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize -verify-loop-info < %s", "opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s" ], "tests": [ { "test_name": "minimal_bit_widths_with_aliasing_store", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @minimal_bit_widths_with_aliasing_store(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1000, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/induction.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S", "opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -enable-interleaved-mem-accesses -S" ], "tests": [ { "test_name": "max_i32_backedgetaken", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine i32 @max_i32_backedgetaken() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]\n %b.0 = phi i32 [ 0, %entry ], [ %b.next, %loop ]\n %a.0.and = and i32 %a.0, 4\n %b.next = add i32 %b.0, -1\n %ec = icmp eq i32 %b.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %a.0.and\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -debug -disable-output %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s" ], "tests": [ { "test_name": "scalarize_ptrtoint", "test_body": "define void @scalarize_ptrtoint(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr ptr, ptr %src, i64 %iv\n %l = load ptr, ptr %gep, align 8\n %cast = ptrtoint ptr %l to i64\n %add = add i64 %cast, 10\n %cast.2 = inttoptr i64 %add to ptr\n store ptr %cast.2, ptr %dst, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/is_fpclass.ll", "commands": [ "opt < %s -passes=loop-vectorize -force-vector-width=2 -S" ], "tests": [ { "test_name": "d", "test_body": "define void @d() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %i = phi i64 [ 0, %entry ], [ %i7, %loop ]\n %i3 = load float, ptr null, align 4\n %i4 = getelementptr float, ptr @d, i64 %i\n %i5 = tail call i1 @llvm.is.fpclass.f32(float %i3, i32 0)\n %i6 = select i1 %i5, float 0.000000e+00, float 0.000000e+00\n store float %i6, ptr %i4, align 4\n %i7 = add i64 %i, 1\n %i8 = icmp eq i64 %i7, 128\n br i1 %i8, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i1 @llvm.is.fpclass.f32(float, i32 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll", "commands": [ "opt -passes='loop-vectorize' -force-vector-width=4 -enable-epilogue-vectorization -epilogue-vectorization-force-VF=4 -S %s", "opt -passes='loop-vectorize' -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 -S %s" ], "tests": [ { "test_name": "multiple_ivs_wide", "test_body": "target datalayout = \"e-m:e-i64:64-n32:64-v128:128:128\"\n\ndefine void @multiple_ivs_wide(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ -64, %entry ], [ %iv.2.next, %loop ]\n %iv.next = add i32 %iv, 2\n %iv.2.next = add i32 %iv.2, 2\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.2.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 128\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll", "commands": [ "opt < %s -passes='loop-vectorize' -force-vector-interleave=1 -S -force-vector-width=4 -debug-only=loop-accesses,loop-vectorize,loop-utils" ], "tests": [ { "test_name": "stride_check_known_via_loop_guard", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @stride_check_known_via_loop_guard(ptr %C, ptr %A, i32 %Acols) {\nentry:\n %pre.c = icmp ugt i32 %Acols, 0\n br i1 %pre.c, label %exit, label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]\n %mul.us = mul i32 %outer.iv, %Acols\n %arrayidx.us = getelementptr double, ptr %A, i32 %mul.us\n br label %inner\n\ninner: ; preds = %inner, %outer.header\n %inner.iv = phi i32 [ 0, %outer.header ], [ %inner.iv.next, %inner ]\n %gep.C = getelementptr inbounds double, ptr %C, i32 %inner.iv\n %l = load double, ptr %arrayidx.us, align 8\n store double %l, ptr %gep.C, align 8\n %inner.iv.next = add i32 %inner.iv, 1\n %inner.c = icmp eq i32 %inner.iv.next, 1000\n br i1 %inner.c, label %outer.latch, label %inner\n\nouter.latch: ; preds = %inner\n %outer.iv.next = add i32 %outer.iv, 1\n %outer.c = icmp ult i32 %outer.iv, 128\n br i1 %outer.c, label %exit, label %outer.header\n\nexit: ; preds = %outer.latch, %entry\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -lv-strided-pointer-ivs=true -S %s" ], "tests": [ { "test_name": "step_direction_unknown", "test_body": "define void @step_direction_unknown(i32 %arg, ptr %dst) {\nentry:\n %add = add i32 %arg, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 0, %entry ], [ %add2, %loop ]\n %trunc = trunc i64 %phi to i32\n %mul = mul i32 %add, %trunc\n %zext = zext i32 %mul to i64\n %getelementptr = getelementptr double, ptr %dst, i64 %zext\n store double 0.000000e+00, ptr %getelementptr, align 8\n %add2 = add i64 %phi, 1\n %icmp = icmp eq i64 %add2, 1024\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "integer_induction_wraps_scev_predicate_known", "test_body": "define void @integer_induction_wraps_scev_predicate_known(i32 %x, ptr %call, ptr %start) {\nentry:\n %mul = shl i32 %x, 1\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %entry\n %iv = phi i32 [ 30, %entry ], [ %inc, %for.cond ]\n %p.0 = phi ptr [ %start, %entry ], [ %add.ptr, %for.cond ]\n %add.ptr = getelementptr i8, ptr %p.0, i32 %mul\n %arrayidx = getelementptr ptr, ptr %call, i32 %iv\n store ptr %p.0, ptr %arrayidx, align 4\n %inc = add i32 %iv, 1\n %tobool.not = icmp eq i32 %iv, 1024\n br i1 %tobool.not, label %for.end, label %for.cond\n\nfor.end: ; preds = %for.cond\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -debug -disable-output %s 2>&1" ], "tests": [ { "test_name": "sink_with_sideeffects", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @sink_with_sideeffects(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1024, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[LoopVectorizer] Assertion `EPResumeVal && \"must have a resume value for the canonical IV\"' failed.", "body": "clang -Wno-incompatible-pointer-types -O3 -march=z13 -S -c crash19.i -o a.out -w -mllvm -disable-licm-promotion -mllvm -epilogue-vectorization-force-VF=2 \n\n[crash19.tar.gz](https://github.com/user-attachments/files/18383534/crash19.tar.gz)\n\n#9 0x000002aa3ff5e440 preparePlanForEpilogueVectorLoop\n#12 0x000002aa3ffa098a llvm::LoopVectorizePass::run\n\n@bmahjour \n@fhahn ", "author": "JonPsson1", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "@JonPsson1 Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count." }, { "author": "JonPsson1", "body": "> [@JonPsson1](https://github.com/JonPsson1) Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count.\n\nNo, it was a CSmith test case." }, { "author": "fhahn", "body": "@JonPsson1 Could you check if it fixes the full reproducer? If not, it would be great if you could share the full reproducer?" } ] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": [ [ 859, 865 ] ], "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": [ "cloneLoopBlocks" ], "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
102279
https://github.com/llvm/llvm-project/issues/102279
crash
f7e1efe8bcea14686d1c303e058f687b6ca1c79f
2024-08-07T07:28:15
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "441f94f4bdf6e2b9747ec12194c595098d9c3a5b", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 17336, 17362 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 441f94f4bdf6e2b9747ec12194c595098d9c3a5b Author: Alexey Bataev <[email protected]> Date: Wed Aug 7 04:09:55 2024 -0700 [SLP]Fix PR102279: check the tracked values for extractelements, not the original values If the reduced value was replaced by the extractelement instruction during vectorization and we attempt to check if this is so, need to check the tracked value, not the original (deleted) instruction. Otherwise, the compiler may crash Fixes https://github.com/llvm/llvm-project/issues/102279 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c9335b7a89e1..1fee06d145b9 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -17336,27 +17336,23 @@ public: // Try to handle shuffled extractelements. if (S.getOpcode() == Instruction::ExtractElement && !S.isAltShuffle() && I + 1 < E) { - InstructionsState NextS = getSameOpcode(ReducedVals[I + 1], TLI); - if (NextS.getOpcode() == Instruction::ExtractElement && - !NextS.isAltShuffle()) { - SmallVector<Value *> CommonCandidates(Candidates); - for (Value *RV : ReducedVals[I + 1]) { - Value *RdxVal = TrackedVals.find(RV)->second; - // Check if the reduction value was not overriden by the - // extractelement instruction because of the vectorization and - // exclude it, if it is not compatible with other values. - if (auto *Inst = dyn_cast<Instruction>(RdxVal)) - if (!NextS.getOpcode() || !NextS.isOpcodeOrAlt(Inst)) - continue; - CommonCandidates.push_back(RdxVal); - TrackedToOrig.try_emplace(RdxVal, RV); - } - SmallVector<int> Mask; - if (isFixedVectorShuffle(CommonCandidates, Mask)) { - ++I; - Candidates.swap(CommonCandidates); - ShuffledExtracts = true; - } + SmallVector<Value *> CommonCandidates(Candidates); + for (Value *RV : ReducedVals[I + 1]) { + Value *RdxVal = TrackedVals.find(RV)->second; + // Check if the reduction value was not overriden by the + // extractelement instruction because of the vectorization and + // exclude it, if it is not compatible with other values. + auto *Inst = dyn_cast<ExtractElementInst>(RdxVal); + if (!Inst) + continue; + CommonCandidates.push_back(RdxVal); + TrackedToOrig.try_emplace(RdxVal, RV); + } + SmallVector<int> Mask; + if (isFixedVectorShuffle(CommonCandidates, Mask)) { + ++I; + Candidates.swap(CommonCandidates); + ShuffledExtracts = true; } }
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-value-replace-extractelement.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\n %trunc = trunc i64 0 to i32\n %mul = mul i32 0, %trunc\n %mul3 = mul i32 %trunc, %phi\n %mul4 = mul i32 %mul3, %mul\n %mul5 = mul i32 %mul4, %mul\n %trunc6 = trunc i64 0 to i32\n %mul7 = mul i32 0, %trunc6\n %mul8 = mul i32 %mul5, %mul7\n %mul9 = mul i32 %mul8, %mul7\n br label %bb1\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-gather-non-scheduled-extracts.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-sie-ps5 < %s" ], "tests": [ { "test_name": "tes", "test_body": "define void @tes() {\nentry:\n %0 = extractelement <2 x i1> zeroinitializer, i64 0\n %1 = extractelement <2 x i1> zeroinitializer, i64 0\n %2 = fcmp ole <2 x double> zeroinitializer, zeroinitializer\n %3 = extractelement <2 x i1> %2, i64 0\n %4 = extractelement <2 x i1> zeroinitializer, i64 0\n br label %5\n\n5: ; preds = %entry\n %6 = select i1 false, i1 false, i1 false\n %7 = select i1 %6, i1 %0, i1 false\n %8 = select i1 %7, i1 %1, i1 false\n %9 = select i1 %8, i1 false, i1 false\n %10 = select i1 %9, i1 %3, i1 false\n %11 = select i1 %10, i1 %4, i1 false\n br i1 %11, label %12, label %13\n\n12: ; preds = %5\n ret void\n\n13: ; preds = %5\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Crash in getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int)", "body": " To reproduce run the test below with `-passes slp-vectorizer -slp-threshold=-99999`\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\r\n %trunc = trunc i64 0 to i32\r\n %mul = mul i32 0, %trunc\r\n %mul3 = mul i32 %trunc, %phi\r\n %mul4 = mul i32 %mul3, %mul\r\n %mul5 = mul i32 %mul4, %mul\r\n %trunc6 = trunc i64 0 to i32\r\n %mul7 = mul i32 0, %trunc6\r\n %mul8 = mul i32 %mul5, %mul7\r\n %mul9 = mul i32 %mul8, %mul7\r\n br label %bb1\r\n}\r\n\r\n```\r\nReproducer: https://godbolt.org/z/sqEov8n9h\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\r\n #0 0x0000000004f2ff18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f2ff18)\r\n #1 0x0000000004f2d68c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007a3cdfe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000000000403fb8a getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n #4 0x000000000406b0a4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n #5 0x000000000406dab4 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x406dab4)\r\n #6 0x00000000040720f8 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40720f8)\r\n #7 0x00000000040763be llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40763be)\r\n #8 0x000000000407c648 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n #9 0x000000000407d11b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x407d11b)\r\n#10 0x0000000002e7f61e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e7f61e)\r\n#11 0x0000000004d2d348 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2d348)\r\n#12 0x0000000000de6cce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde6cce)\r\n#13 0x0000000004d2bd3e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2bd3e)\r\n#14 0x0000000000de731e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde731e)\r\n#15 0x0000000004d29ea0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d29ea0)\r\n#16 0x00000000008e4312 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e4312)\r\n#17 0x00000000008d723c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d723c)\r\n#18 0x00007a3cdfe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#19 0x00007a3cdfe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#20 0x00000000008ce6ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce6ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "RKSimon", "body": "CC @alexey-bataev " } ] }
true
null
128401
https://github.com/llvm/llvm-project/issues/128401
crash
22a5bb32b787443b70476cc1359709b6c888b591
2025-02-23T05:19:16
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "eb14d2a1d48fe76c5faed71a08547135a35ee742", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13320, 13328 ], [ 13874, 13888 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledSingleRegisterEntry", "BoUpSLP::isGatherShuffledEntry" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit eb14d2a1d48fe76c5faed71a08547135a35ee742 Author: Alexey Bataev <[email protected]> Date: Mon Feb 24 06:02:56 2025 -0800 [SLP]Fix check for matched gather node, if it is a subvector node If the gather node is a subvector node, it may match the existing vector/gather node in the graph, but still may require reordering. in this case need to fully check its dependencies to prevent a compiler crash. Fixes #128401 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index bf256d82ae17..5fc5fb10fad5 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13320,9 +13320,16 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( Entries.clear(); // TODO: currently checking only for Scalars in the tree entry, need to count // reused elements too for better cost estimation. - const EdgeInfo &TEUseEI = TE == VectorizableTree.front().get() - ? EdgeInfo(const_cast<TreeEntry *>(TE), 0) - : TE->UserTreeIndex; + auto GetUserEntry = [&](const TreeEntry *TE) { + while (TE->UserTreeIndex && TE->UserTreeIndex.EdgeIdx == UINT_MAX) + TE = TE->UserTreeIndex.UserTE; + if (TE == VectorizableTree.front().get()) + return EdgeInfo(const_cast<TreeEntry *>(TE), 0); + return TE->UserTreeIndex; + }; + const EdgeInfo TEUseEI = GetUserEntry(TE); + if (!TEUseEI) + return std::nullopt; const Instruction *TEInsertPt = &getLastInstructionInBundle(TEUseEI.UserTE); const BasicBlock *TEInsertBlock = nullptr; // Main node of PHI entries keeps the correct order of operands/incoming @@ -13874,15 +13881,13 @@ BoUpSLP::isGatherShuffledEntry( assert(VL.size() % NumParts == 0 && "Number of scalars must be divisible by NumParts."); if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->isGather() && - TE->UserTreeIndex.EdgeIdx == UINT_MAX) { - assert( - (TE->Idx == 0 || - (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || - isSplat(TE->Scalars) || - getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && - "Expected splat or extractelements only node."); + TE->UserTreeIndex.EdgeIdx == UINT_MAX && + (TE->Idx == 0 || + (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || + isSplat(TE->Scalars) || + (TE->hasState() && + getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)))) return {}; - } unsigned SliceSize = getPartNumElems(VL.size(), NumParts); SmallVector<std::optional<TTI::ShuffleKind>> Res; for (unsigned Part : seq<unsigned>(NumParts)) {
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/bv-matched-node-reorder.ll", "commands": [ "opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\n;\nentry:\n %l2.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %li.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %l1.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %l6.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %end\n\npre:\n br label %end\n\nend:\n %0 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n %1 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %9 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %10 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %11 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %12 = phi i8 [ %l1.i.i.i.i, %entry ], [ %3, %end ]\n %13 = phi i8 [ 0, %entry ], [ %2, %end ]\n %14 = phi i8 [ %l2.i.i.i.i, %entry ], [ %1, %end ]\n %15 = phi i8 [ %li.i.i.i, %entry ], [ %0, %end ]\n %16 = phi i8 [ 0, %entry ], [ %6, %end ]\n %17 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %18 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %19 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %20 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %21 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %22 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %c1.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %c1.i.1.i.i.i = icmp eq i8 %16, 0\n %c1.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %c1.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %c1.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %c1.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %c1.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %c1.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %c1.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `\"Expected splat or extractelements only node.\"' failed.", "body": "Reproducer: https://godbolt.org/z/9jx1xejoe\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.promoted42.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %.promoted.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %.promoted51.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %.promoted56.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %if.end151.1.i.1.i.i.i.i\n\nfor.cond79.preheader.us.preheader.1.i.1.i.i.i.i:\n br label %if.end151.1.i.1.i.i.i.i\n\nif.end151.1.i.1.i.i.i.i:\n %0 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n %1 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %9 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %10 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %11 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %12 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %3, %if.end151.1.i.1.i.i.i.i ]\n %13 = phi i8 [ 0, %entry ], [ %2, %if.end151.1.i.1.i.i.i.i ]\n %14 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %1, %if.end151.1.i.1.i.i.i.i ]\n %15 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %0, %if.end151.1.i.1.i.i.i.i ]\n %16 = phi i8 [ 0, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %17 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %18 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %19 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %20 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %21 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %22 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %cmp258.1.i.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %cmp258.1.i.i.1.i.i.i = icmp eq i8 %16, 0\n %cmp258.1.i.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %cmp258.1.i.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %cmp258.1.i.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %cmp258.1.i.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %cmp258.1.i.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %cmp258.1.i.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %cmp258.1.i.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13878: llvm::SmallVector<std::optional<llvm::TargetTransformInfo::ShuffleKind> > llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<const llvm::slpvectorizer::BoUpSLP::TreeEntry*> >&, unsigned int, bool): Assertion `(TE->Idx == 0 || (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || isSplat(TE->Scalars) || getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && \"Expected splat or extractelements only node.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005447b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5447b18)\n #1 0x00000000054454d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000072c4b8a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000072c4b8a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000072c4b8a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000072c4b8a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000072c4b8a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000072c4b8a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000447b405 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447b405)\n #9 0x000000000447c786 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447c786)\n#10 0x000000000447ec37 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447ec37)\n#11 0x00000000044b3879 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44b3879)\n#12 0x00000000044bd45d llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44bd45d)\n#13 0x00000000044c1701 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c1701)\n#14 0x00000000044c1fab llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#15 0x00000000044c575f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c575f)\n#16 0x00000000044cbef6 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#17 0x00000000044cca4b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44cca4b)\n#18 0x0000000003182e1e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3182e1e)\n#19 0x00000000052431d0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52431d0)\n#20 0x0000000000e6e03e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e03e)\n#21 0x0000000005241aeb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5241aeb)\n#22 0x0000000000e6d34e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6d34e)\n#23 0x00000000052414f0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52414f0)\n#24 0x0000000000935a5a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935a5a)\n#25 0x00000000009290cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290cc)\n#26 0x000072c4b8a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000072c4b8a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x00000000009209a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9209a5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\nllvm version: dbd219aef4be56754c793589c60bd787b7de60c2\n", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid", "generated by fuzzer" ], "comments": [] }
true
null
106248
https://github.com/llvm/llvm-project/issues/106248
crash
616f7d3d4f6d9bea6f776e357c938847e522a681
2024-08-27T17:02:16
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "0a272d3a1703415abca42dc2e2cc2b57cb30734e", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ [ 6529, 6534 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [ "LoopVectorizationCostModel::getInstructionCost" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 0a272d3a1703415abca42dc2e2cc2b57cb30734e Author: Florian Hahn <[email protected]> Date: Thu Aug 29 12:08:27 2024 +0100 [LV] Use SCEV to analyze second operand for cost query. Improve operand analysis using SCEV for cost purposes. This fixes a divergence between legacy and VPlan-based cost-modeling after 533e6bbd0d34. Fixes https://github.com/llvm/llvm-project/issues/106248. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 56f51e14a6eb..4cc75e2e7546 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6529,6 +6529,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, // Certain instructions can be cheaper to vectorize if they have a constant // second vector operand. One example of this are shifts on x86. Value *Op2 = I->getOperand(1); + if (!isa<Constant>(Op2) && PSE.getSE()->isSCEVable(Op2->getType()) && + isa<SCEVConstant>(PSE.getSCEV(Op2))) { + Op2 = cast<SCEVConstant>(PSE.getSCEV(Op2))->getValue(); + } auto Op2Info = TTI.getOperandInfo(Op2); if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue && Legal->isInvariant(Op2))
[ { "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", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Assertion failed in Vectorize", "body": "In #105722 , we resolved the assertion failure in vectorization. However, I met this crash again with the following case:\r\n\r\n```c\r\n#include <stdint.h>\r\nint a;\r\nlong b;\r\nstruct e {\r\n uint16_t f;\r\n uint64_t g;\r\n int32_t h\r\n} static i = {65530};\r\nvoid c(int d) {\r\n for (; a; a++)\r\n b *= d;\r\n}\r\nuint32_t j(struct e, uint16_t);\r\nuint64_t k() { j(i, 0); }\r\nuint32_t j(struct e, uint16_t) { c(i.f - 65528); }\r\n```\r\nI compiled it with -O2 flag and it crashed. But when I compiled with -O1/-O0, it worked.\r\n\r\nThe crash is: clang++: /root/llvm-project/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\n\r\nThe details can be found here: https://godbolt.org/z/8x48xsKs6", "author": "cardigan1008", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Thanks for the report @cardigan1008, should be fixed now" } ] }
true
null
104761
https://github.com/llvm/llvm-project/issues/104761
crash
5cfa8baef33636827e5aa8dd76888c724433b53e
2024-08-19T11:00:31
[ "llvm/test/Analysis/LoopCacheAnalysis" ]
{ "fix_commit": "2e6deb1dd3a4422807633ba08773e8d786e43d4c", "components": [ "LoopCacheAnalysis" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": [ [ 16, 21 ], [ 31, 37 ], [ 192, 199 ] ], "llvm/lib/Analysis/LoopCacheAnalysis.cpp": [ [ 328, 333 ], [ 338, 351 ], [ 696, 702 ] ], "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": [ "CacheCost::computeLoopCacheCost", "IndexedReference::computeRefCost", "IndexedReference::tryDelinearizeFixedSize" ], "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 2e6deb1dd3a4422807633ba08773e8d786e43d4c Author: Sjoerd Meijer <[email protected]> Date: Thu Nov 14 08:40:45 2024 +0000 [LoopInterchange] Fix overflow in cost calculation (#111807) If the iteration count is really large, e.g. UINT_MAX, then the cost calculation can overflows and trigger an assert. So saturate the cost to INT_MAX if this is the case by using InstructionCost as a type which already supports this kind of overflow handling. This fixes #104761 diff --git a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h index 4fd2485e39d6..3e22487e5e34 100644 --- a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h +++ b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h @@ -16,6 +16,7 @@ #include "llvm/Analysis/LoopAnalysisManager.h" #include "llvm/IR/PassManager.h" +#include "llvm/Support/InstructionCost.h" #include <optional> namespace llvm { @@ -31,7 +32,7 @@ class ScalarEvolution; class SCEV; class TargetTransformInfo; -using CacheCostTy = int64_t; +using CacheCostTy = InstructionCost; using LoopVectorTy = SmallVector<Loop *, 8>; /// Represents a memory reference as a base pointer and a set of indexing @@ -192,8 +193,6 @@ class CacheCost { using LoopCacheCostTy = std::pair<const Loop *, CacheCostTy>; public: - static CacheCostTy constexpr InvalidCost = -1; - /// Construct a CacheCost object for the loop nest described by \p Loops. /// The optional parameter \p TRT can be used to specify the max. distance /// between array elements accessed in a loop so that the elements are diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp index 7ca9f15ad5fc..2897b922f61e 100644 --- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp +++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp @@ -328,6 +328,8 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L, const SCEV *TripCount = computeTripCount(*AR->getLoop(), *Sizes.back(), SE); Type *WiderType = SE.getWiderType(RefCost->getType(), TripCount->getType()); + // For the multiplication result to fit, request a type twice as wide. + WiderType = WiderType->getExtendedType(); RefCost = SE.getMulExpr(SE.getNoopOrZeroExtend(RefCost, WiderType), SE.getNoopOrZeroExtend(TripCount, WiderType)); } @@ -338,14 +340,18 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L, assert(RefCost && "Expecting a valid RefCost"); // Attempt to fold RefCost into a constant. + // CacheCostTy is a signed integer, but the tripcount value can be large + // and may not fit, so saturate/limit the value to the maximum signed + // integer value. if (auto ConstantCost = dyn_cast<SCEVConstant>(RefCost)) - return ConstantCost->getValue()->getZExtValue(); + return ConstantCost->getValue()->getLimitedValue( + std::numeric_limits<int64_t>::max()); LLVM_DEBUG(dbgs().indent(4) << "RefCost is not a constant! Setting to RefCost=InvalidCost " "(invalid value).\n"); - return CacheCost::InvalidCost; + return CacheCostTy::getInvalid(); } bool IndexedReference::tryDelinearizeFixedSize( @@ -696,7 +702,7 @@ CacheCostTy CacheCost::computeLoopCacheCost(const Loop &L, const ReferenceGroupsTy &RefGroups) const { if (!L.isLoopSimplifyForm()) - return InvalidCost; + return CacheCostTy::getInvalid(); LLVM_DEBUG(dbgs() << "Considering loop '" << L.getName() << "' as innermost loop.\n");
[ { "file": "llvm/test/Analysis/LoopCacheAnalysis/interchange-refcost-overflow.ll", "commands": [ "opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1" ], "tests": [ { "test_name": "foo", "test_body": "@A = external local_unnamed_addr global [11 x [11 x [11 x i32]]], align 16\n\ndefine void @foo(i32 noundef %b) {\nentry:\n %0 = sext i32 %b to i64\n br label %outer.loop\n\nouter.loop: ; preds = %outer.loop.cleanup, %entry\n %indvars.iv = phi i64 [ %indvars.iv.next, %outer.loop.cleanup ], [ 0, %entry ]\n br label %inner.loop\n\nouter.loop.cleanup: ; preds = %inner.loop\n %indvars.iv.next = add nsw i64 %indvars.iv, %0\n br label %outer.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %inner.iv = phi i64 [ 0, %outer.loop ], [ %add, %inner.loop ]\n %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %inner.iv, i64 %inner.iv\n store i32 0, ptr %arrayidx3, align 4\n %add = add nuw i64 %inner.iv, 2\n %cmp = icmp ult i64 %inner.iv, -5\n br i1 %cmp, label %inner.loop, label %outer.loop.cleanup\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[LoopInterchange] Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"", "body": "With options \"-O3 --target=aarch64 func.cpp -mllvm -enable-loopinterchange\" and this input:\r\n```\r\nunsigned int A[11][11][11] __attribute__((aligned(16)));\r\nvoid a(int b) {\r\n for (int c;; c += b)\r\n for (long d = 0; d < -3ULL; d += 2ULL)\r\n A[c][d][d] = 0;\r\n}\r\n```\r\n\r\nLoop-interchange runs in an assert:\r\n\r\n```\r\nllvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' failed.\r\n```\r\n\r\nIR reproducer, compile this with \"opt -passes=loop-interchange -S\":\r\n\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\n@A = local_unnamed_addr global [11 x [11 x [11 x i32]]] zeroinitializer, align 16\r\n\r\ndefine void @_Z1ai(i32 noundef %b) local_unnamed_addr #0 {\r\nentry:\r\n %0 = sext i32 %b to i64\r\n br label %for.cond\r\n\r\n; Loop:\r\nfor.cond: ; preds = %for.cond.cleanup, %entry\r\n %indvars.iv = phi i64 [ %indvars.iv.next, %for.cond.cleanup ], [ 0, %entry ]\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %indvars.iv.next = add nsw i64 %indvars.iv, %0\r\n br label %for.cond\r\n\r\nfor.body: ; preds = %for.cond, %for.body\r\n %d.010 = phi i64 [ 0, %for.cond ], [ %add, %for.body ]\r\n %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %d.010, i64 %d.010\r\n store i32 0, ptr %arrayidx3, align 4\r\n %add = add nuw i64 %d.010, 2\r\n %cmp = icmp ult i64 %d.010, -5\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup\r\n}\r\n```", "author": "sjoerdmeijer", "labels": [ "crash-on-valid", "llvm:analysis" ], "comments": [ { "author": "RKSimon", "body": "```\r\nopt: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' 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-interchange -debug <source>\r\n1.\tRunning pass \"function(loop(loop-interchange))\" on module \"<source>\"\r\n2.\tRunning pass \"loop(loop-interchange)\" on function \"_Z1ai\"\r\n #0 0x0000000004f7f528 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f7f528)\r\n #1 0x0000000004f7cc9c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f497b842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f497b8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f497b842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f497b8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f497b82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f497b839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000045677cc llvm::IndexedReference::computeRefCost(llvm::Loop const&, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45677cc)\r\n #9 0x000000000456995f llvm::CacheCost::computeLoopCacheCost(llvm::Loop const&, llvm::SmallVector<llvm::SmallVector<std::unique_ptr<llvm::IndexedReference, std::default_delete<llvm::IndexedReference>>, 8u>, 8u> const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x456995f)\r\n#10 0x000000000456c137 llvm::CacheCost::calculateCacheFootprint() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x456c137)\r\n#11 0x0000000004573d5c llvm::CacheCost::getCacheCost(llvm::Loop&, llvm::LoopStandardAnalysisResults&, llvm::DependenceInfo&, std::optional<unsigned int>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4573d5c)\r\n#12 0x0000000003c71d66 llvm::LoopInterchangePass::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c71d66)\r\n#13 0x0000000002eb0a6e llvm::detail::PassModel<llvm::LoopNest, llvm::LoopInterchangePass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2eb0a6e)\r\n#14 0x0000000003c85255 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c85255)\r\n#15 0x0000000003c85ce3 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+0x3c85ce3)\r\n#16 0x0000000003c868b8 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c868b8)\r\n#17 0x0000000000df128e llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf128e)\r\n#18 0x0000000004d7c368 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7c368)\r\n#19 0x0000000000df14be 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+0xdf14be)\r\n#20 0x0000000004d7ad5e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7ad5e)\r\n#21 0x0000000000df0f8e 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+0xdf0f8e)\r\n#22 0x0000000004d78ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d78ec0)\r\n#23 0x00000000008e7582 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+0x8e7582)\r\n#24 0x00000000008da45c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8da45c)\r\n#25 0x00007f497b829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x00007f497b829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008d1eee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d1eee)\r\n```\r\nWhich seems to be due to the getZExtValue() call inside IndexedReference::computeRefCost\r\nhttps://github.com/llvm/llvm-project/blob/b05c55472bf7cadcd0e4cb1a669b3474695b0524/llvm/lib/Analysis/LoopCacheAnalysis.cpp#L340:L343" }, { "author": "svs-quic", "body": "cc: @caojoshua " }, { "author": "sjoerdmeijer", "body": "I have a fix, will put it up for review tomorrow. " } ] }
true
null
114738
https://github.com/llvm/llvm-project/issues/114738
miscompilation
2588b8be5624f721c56f44fd2a69f7327de8c0c1
2024-11-04T05:50:07
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "899336735aeb2b41a48b6ac2c895da5e0f22dbf0", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 19490, 19498 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "tryToReduce" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit 899336735aeb2b41a48b6ac2c895da5e0f22dbf0 Author: Alexey Bataev <[email protected]> Date: Mon Nov 4 06:02:06 2024 -0800 [SLP]Be more pessimistic about poisonous reductions Consider all possible reductions ops as being non-poisoning boolean logical operations, which require freeze to be fully correct. https://alive2.llvm.org/ce/z/TKWDMP Fixes #114738 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 427b8bd0e75a..3c6daf7b9fbb 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -19490,9 +19490,7 @@ public: // To prevent poison from leaking across what used to be sequential, // safe, scalar boolean logic operations, the reduction operand must be // frozen. - if ((isBoolLogicOp(RdxRootInst) || - (AnyBoolLogicOp && VL.size() != TrackedVals.size())) && - !isGuaranteedNotToBePoison(VectorizedRoot)) + if (AnyBoolLogicOp && !isGuaranteedNotToBePoison(VectorizedRoot)) VectorizedRoot = Builder.CreateFreeze(VectorizedRoot); // Emit code to correctly handle reused reduced values, if required.
[ { "file": "llvm/test/Transforms/SLPVectorizer/reudction-or-non-poisoned.ll", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "test", "test_body": "define i1 @test(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\n %cmp = icmp sgt i32 %x, 1\n %cmp2 = icmp sgt i32 %b, 1\n %cmp3 = icmp sgt i32 %c, 1\n %cmp4 = icmp sgt i32 %d, 1\n %sel2 = select i1 %cmp4, i1 true, i1 %cmp2\n %sel3 = select i1 %sel2, i1 true, i1 %cmp3\n %sel4 = select i1 %cmp, i1 true, i1 %cmp4\n %ret = or i1 %sel3, %sel4\n ret i1 %ret\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] wrong vectorization to `reduce_or` due to poisonous value", "body": "Alive2 report: https://alive2.llvm.org/ce/z/f8PDZj\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @test1.2(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\r\n#0:\r\n %cmp = icmp sgt i32 %x, 1\r\n %cmp2 = icmp sgt i32 %b, 1\r\n %cmp3 = icmp sgt i32 %c, 1\r\n %cmp4 = icmp sgt i32 %d, 1\r\n %sel2 = select i1 %cmp4, i1 1, i1 %cmp2\r\n %sel3 = select i1 %sel2, i1 1, i1 %cmp3\r\n %sel4 = select i1 %cmp, i1 1, i1 %cmp4\r\n %ret = or i1 %sel3, %sel4\r\n ret i1 %ret\r\n}\r\n=>\r\ndefine i1 @test1.2(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\r\n#0:\r\n %#1 = insertelement <4 x i32> poison, i32 %d, i32 0\r\n %#2 = insertelement <4 x i32> %#1, i32 %b, i32 1\r\n %#3 = insertelement <4 x i32> %#2, i32 %c, i32 2\r\n %#4 = insertelement <4 x i32> %#3, i32 %x, i32 3\r\n %#5 = icmp sgt <4 x i32> %#4, { 1, 1, 1, 1 }\r\n %#6 = reduce_or <4 x i1> %#5\r\n ret i1 %#6\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\ni32 %a = poison\r\ni32 %b = #x00000002 (2)\r\ni32 %c = poison\r\ni32 %d = #x00000000 (0)\r\n\r\nSource:\r\ni1 %cmp = #x0 (0)\r\ni1 %cmp2 = #x1 (1)\r\ni1 %cmp3 = poison\r\ni1 %cmp4 = #x0 (0)\r\ni1 %sel2 = #x1 (1)\r\ni1 %sel3 = #x1 (1)\r\ni1 %sel4 = #x0 (0)\r\ni1 %ret = #x1 (1)\r\n\r\nTarget:\r\n<4 x i32> %#1 = < #x00000000 (0), poison, poison, poison >\r\n<4 x i32> %#2 = < #x00000000 (0), #x00000002 (2), poison, poison >\r\n<4 x i32> %#3 = < #x00000000 (0), #x00000002 (2), poison, poison >\r\n<4 x i32> %#4 = < #x00000000 (0), #x00000002 (2), poison, #x00000000 (0) >\r\n<4 x i1> %#5 = < #x0 (0), #x1 (1), poison, #x0 (0) >\r\ni1 %#6 = poison\r\nSource value: #x1 (1)\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": [] }
true
null
118030
https://github.com/llvm/llvm-project/issues/118030
crash
6f4b4f41ca41d7d0b44a32d9968aef7667c68184
2024-11-28T19:14:48
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "f4974e09312afc9549fcfc0304b738d235da9eca", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 17799, 17804 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::collectValuesToDemote" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit f4974e09312afc9549fcfc0304b738d235da9eca Author: Alexey Bataev <[email protected]> Date: Fri Nov 29 06:20:19 2024 -0800 [SLP] Add a check for poison value in AShrChecker Need to check if the value in AShrChecker is a poison before casting it to instruction to avoid compiler crash Fixes #118030 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 48a8520a966f..7723442bc0fb 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -17799,6 +17799,8 @@ bool BoUpSLP::collectValuesToDemote( // original type and the sign bit of the truncate type are similar. auto AShrChecker = [&](unsigned BitWidth, unsigned OrigBitWidth) { return all_of(E.Scalars, [&](Value *V) { + if (isa<PoisonValue>(V)) + return true; auto *I = cast<Instruction>(V); KnownBits AmtKnownBits = computeKnownBits(I->getOperand(1), *DL); unsigned ShiftedBits = OrigBitWidth - BitWidth;
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/ashr-node-with-poison.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(ptr %n, i32 %conv57, i1 %tobool5.not, i64 %bf.load14) {\n;\nentry:\n br i1 false, label %entry.if.end54_crit_edge, label %while.cond\n\nentry.if.end54_crit_edge:\n br label %if.end54\n\ntthread-pre-split:\n br label %t\n\nt:\n %w.2 = phi i32 [ 1, %tthread-pre-split ], [ 0, %if.end83 ]\n br label %if.end7\n\nt.u_crit_edge:\n br label %if.end7\n\nif.end7:\n %w.4 = phi i32 [ %w.2, %t ], [ %w.2, %t.u_crit_edge ], [ %bf.cast25, %while.body ]\n %a.4 = phi i32 [ 0, %t ], [ %conv57, %t.u_crit_edge ], [ %bf.cast2910, %while.body ]\n %b.4 = phi i32 [ 0, %t ], [ 0, %t.u_crit_edge ], [ %bf.cast2910, %while.body ]\n %c.4 = phi i32 [ 0, %t ], [ 1, %t.u_crit_edge ], [ poison, %while.body ]\n br label %v\n\nwhile.cond:\n %bf.load66.pre.pre1135 = phi i64 [ 0, %entry ], [ %spec.select, %if.end42 ]\n br i1 %tobool5.not, label %if.end54, label %while.body\n\nwhile.body:\n %bf.ashr24 = ashr i64 %bf.load14, 33\n %bf.cast25 = trunc nsw i64 %bf.ashr24 to i32\n %bf.ashr28 = lshr i64 %bf.load14, 1\n %bf.cast2910 = trunc i64 %bf.ashr28 to i32\n br label %if.end7\n\nif.end36:\n br label %v\n\nv:\n %c.7 = phi i32 [ %c.4, %if.end7 ], [ 0, %if.end36 ]\n br i1 true, label %if.end42, label %v.if.end83_crit_edge\n\nv.if.end83_crit_edge:\n br label %if.end83\n\nif.end42:\n %tobool43.not = icmp eq i32 %b.4, 0\n %narrow = select i1 %tobool43.not, i32 0, i32 %w.4\n %spec.select = zext i32 %narrow to i64\n %bf.value48 = zext i32 %a.4 to i64\n store i64 %bf.value48, ptr %n, align 8\n store i32 %c.7, ptr %n, align 4\n br label %while.cond\n\nif.end54:\n %bf.load66.pre.pre113125 = phi i64 [ %bf.load66.pre.pre1135, %while.cond ], [ poison, %entry.if.end54_crit_edge ]\n %0 = icmp eq i64 %bf.load66.pre.pre113125, 0\n br i1 %0, label %if.end83, label %ai.if.end76_crit_edge\n\nai.if.end76_crit_edge:\n br label %if.end83\n\nif.end83:\n br label %t\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed", "body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/cb67rEodY\n\n```\n[516] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 5208bc3694473f9378fc0d98eeee63e5ad5c5f04)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 11.8\n[517] % \n[517] % clangtk -O2 -w small.c\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20241125-clangtk-m64-O3-fpointer-tbaa-build-014338/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241125-clangtk-m64-O3-fpointer-tbaa-build-014338/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -w -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-99895f.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000562e34749b50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x455db50)\n #1 0x0000562e34746f5f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x455af5f)\n #2 0x0000562e347470b5 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007f99ac5bf520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007f99ac613a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\n #5 0x00007f99ac5bf476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007f99ac5a57f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007f99ac5a571b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007f99ac5b6e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000562e31712868 (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1526868)\n#10 0x0000562e3616cf4e llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda9'(unsigned int, unsigned int)::operator()(unsigned int, unsigned int) const::'lambda'(llvm::Value*)::operator()(llvm::Value*) const SLPVectorizer.cpp:0:0\n#11 0x0000562e3616d208 bool llvm::function_ref<bool (unsigned int, unsigned int)>::callback_fn<llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda9'(unsigned int, unsigned int)>(long, unsigned int, unsigned int) SLPVectorizer.cpp:0:0\n#12 0x0000562e361c72e9 llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda6'(unsigned int&, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>, llvm::function_ref<bool (unsigned int, unsigned int)>)::operator()(unsigned int&, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>, llvm::function_ref<bool (unsigned int, unsigned int)>) const SLPVectorizer.cpp:0:0\n#13 0x0000562e361c6065 llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5fda065)\n#14 0x0000562e361c6d09 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes()::'lambda0'(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool, unsigned int, unsigned int, bool, bool)::operator()(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool, unsigned int, unsigned int, bool, bool) const SLPVectorizer.cpp:0:0\n#15 0x0000562e361db4e3 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5fef4e3)\n#16 0x0000562e3623dc1e llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6051c1e)\n#17 0x0000562e362427c0 bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x0000562e36244162 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6058162)\n#19 0x0000562e3624bc96 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#20 0x0000562e3624c802 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6060802)\n#21 0x0000562e35c92cf6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5aa6cf6)\n#22 0x0000562e340cd78f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ee178f)\n#23 0x0000562e31add026 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18f1026)\n#24 0x0000562e340cbb1b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3edfb1b)\n#25 0x0000562e31adb986 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18ef986)\n#26 0x0000562e340cc67d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ee067d)\n#27 0x0000562e349f1d16 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#28 0x0000562e349f566c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x480966c)\n#29 0x0000562e350be425 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4ed2425)\n#30 0x0000562e36cf2c7c clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6b06c7c)\n#31 0x0000562e3539f2c9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x51b32c9)\n#32 0x0000562e353190f5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x512d0f5)\n#33 0x0000562e354836b3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x52976b3)\n#34 0x0000562e316862d1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x149a2d1)\n#35 0x0000562e3167cc8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#36 0x0000562e31681067 clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1495067)\n#37 0x0000562e31579a7b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x138da7b)\n#38 0x00007f99ac5a6d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#39 0x00007f99ac5a6e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#40 0x0000562e3167c3b5 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x14903b5)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 5208bc3694473f9378fc0d98eeee63e5ad5c5f04)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-522eca.c\nclangtk: note: diagnostic msg: /tmp/small-522eca.sh\nclangtk: note: diagnostic msg: \n\n********************\n[518] % \n[518] % cat small.c\nstruct {\n int b : 31;\n int c : 6;\n} f, g, j;\nint d, e, h, i, k, l, m, n, o;\nint main() {\n if (m) {\n short q = d;\n if (d)\n r:\n d = q;\n if (0) {\n s:\n t:\n if (h)\n u:\n o = g.c;\n if (n)\n goto v;\n }\n if (n)\n while (g.c) {\n if (e)\n k;\n int w = j.b, a, b = g.c, c = ~b;\n a = f.b;\n if (l) {\n c = 0 % 0;\n goto u;\n }\n if (a)\n goto s;\n l;\n v:\n if (i)\n goto ae;\n if (b)\n j.b = w;\n f.b = a;\n l = c;\n }\n short p = n;\n if (0) {\n ag:\n h = p;\n if (f.b)\n goto t;\n }\n if (j.b) {\n ae:\n e = 0;\n ai:\n if (q)\n goto r;\n }\n }\n if (j.b)\n goto ai;\n if (d)\n goto ag;\n return 0;\n}\n```", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
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/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 3237, 3251 ] ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "findLaneForValue" ], "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.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", "lli_expected_out": null, "additional_args": 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
77064
https://github.com/llvm/llvm-project/issues/77064
crash
255f95a40377677dd762df5a1aa65bcbb4f75c79
2024-01-05T09:28:42
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a001e9718fd974859f2797a9f9ed7bf87d364e4f", "components": [ "SimplifyLibCalls" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": [ [ 3735, 3760 ] ], "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Analysis/LazyValueInfo.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/Utils/DemoteRegToStack.cpp": null }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": [ "LibCallSimplifier::optimizeCall" ], "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null } }
commit a001e9718fd974859f2797a9f9ed7bf87d364e4f Author: Nikita Popov <[email protected]> Date: Fri Jan 5 10:41:44 2024 +0100 [SimplifyLibCalls] Don't try to manually reprocess calls The current code for reprocessing the result of fortified libcall simplifications is not correct, because we might simplify to an argument of the original call, and if that is again a libcall, mistakenly think that this is actually the simplification result. Instead of trying to fix this, simply remove the code entirely, because InstCombine nowadays correctly handles reprocessing of SimplifyLibCall results. Fixes https://github.com/llvm/llvm-project/issues/77064. diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 760a626c8b6f..a7cd68e860e4 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3735,26 +3735,8 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI, IRBuilderBase &Builder) { // Also try to simplify calls to fortified library functions. if (Value *SimplifiedFortifiedCI = - FortifiedSimplifier.optimizeCall(CI, Builder)) { - // Try to further simplify the result. - CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI); - if (SimplifiedCI && SimplifiedCI->getCalledFunction()) { - // Ensure that SimplifiedCI's uses are complete, since some calls have - // their uses analyzed. - replaceAllUsesWith(CI, SimplifiedCI); - - // Set insertion point to SimplifiedCI to guarantee we reach all uses - // we might replace later on. - IRBuilderBase::InsertPointGuard Guard(Builder); - Builder.SetInsertPoint(SimplifiedCI); - if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, Builder)) { - // If we were able to further simplify, remove the now redundant call. - substituteInParent(SimplifiedCI, V); - return V; - } - } + FortifiedSimplifier.optimizeCall(CI, Builder)) return SimplifiedFortifiedCI; - } // Then check for known library functions. if (TLI->getLibFunc(*Callee, Func) && isLibFuncEmittable(M, TLI, Func)) {
[ { "file": "llvm/test/Transforms/InstCombine/pr77064.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "main", "test_body": "define void @main(ptr %ptr) {\n %opendir = call fastcc ptr @opendir(ptr %ptr)\n %memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)\n ret void\n}\n\ndeclare ptr @__memset_chk(ptr, i32, i64, i64)\n\ndeclare fastcc ptr @opendir(ptr)\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SimplifyLibCalls] Calling convention assertion fails", "body": "```llvm\r\n; RUN: opt -S -passes=instcombine\r\ndefine void @main(ptr %ptr) {\r\n %opendir = call fastcc ptr @opendir(ptr %ptr)\r\n %memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)\r\n ret void\r\n}\r\n\r\ndeclare ptr @__memset_chk(ptr, i32, i64, i64)\r\n\r\ndeclare fastcc ptr @opendir(ptr)\r\n```\r\n\r\n> opt: /home/npopov/repos/llvm-project/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:3488: Value *llvm::LibCallSimplifier::optimizeStringMemoryLibCall(CallInst *, IRBuilderBase &): Assertion `(ignoreCallingConv(Func) || TargetLibraryInfoImpl::isCallingConvCCompatible(CI)) && \"Optimizing string/memory libcall would change the calling convention\"' failed.\r\n\r\nEncountered when building openjpeg2.", "author": "nikic", "labels": [ "llvm:crash", "llvm:instcombine" ], "comments": [] }
true
null