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
128770
https://github.com/llvm/llvm-project/issues/128770
crash
7f482aa848c5f136d2b32431f91f88492c78c709
2025-02-25T20:34:44
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "418a9872851ef5342b29baa36dd672129f129953", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13353, 13358 ], [ 13453, 13459 ] ], "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" ], "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 418a9872851ef5342b29baa36dd672129f129953 Author: Alexey Bataev <[email protected]> Date: Wed Feb 26 12:59:27 2025 -0800 [SLP]Do not use node, if it is a subvector or buildvector node If the buildvector has some matches with another node, which is a subvector of another buildvector node, need to check for this and cancel matching to avoid incorrect ordering of the nodes. Fixes #128770 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 02fea2eaf9d4..b25b09306aca 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13353,6 +13353,14 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( return EdgeInfo(const_cast<TreeEntry *>(TE), 0); return TE->UserTreeIndex; }; + auto HasGatherUser = [&](const TreeEntry *TE) { + while (TE->Idx != 0 && TE->UserTreeIndex) { + if (TE->UserTreeIndex.EdgeIdx == UINT_MAX) + return true; + TE = TE->UserTreeIndex.UserTE; + } + return false; + }; const EdgeInfo TEUseEI = GetUserEntry(TE); if (!TEUseEI) return std::nullopt; @@ -13453,7 +13461,8 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( // If the user instruction is used for some reason in different // vectorized nodes - make it depend on index. if (TEUseEI.UserTE != UseEI.UserTE && - TEUseEI.UserTE->Idx < UseEI.UserTE->Idx) + (TEUseEI.UserTE->Idx < UseEI.UserTE->Idx || + HasGatherUser(TEUseEI.UserTE))) continue; }
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-reused-with-bv-subvector.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(ptr %0, i64 %1, i64 %2) {\n;\n %4 = ptrtoint ptr %0 to i64\n %5 = ptrtoint ptr %0 to i64\n %6 = ptrtoint ptr %0 to i64\n %7 = ptrtoint ptr %0 to i64\n %8 = ptrtoint ptr %0 to i64\n br label %.preheader.lr.ph\n\n.preheader.lr.ph:\n br label %.preheader.us.us.preheader\n\n.preheader.us.us.preheader:\n %9 = or i64 %1, %7\n %10 = or i64 %2, %7\n %11 = or i64 %1, %4\n %12 = or i64 %1, %8\n %13 = or i64 %5, %8\n %14 = or i64 %8, %4\n %15 = or i64 %5, %6\n %16 = or i64 %6, %4\n br label %.preheader.us.us\n\n.preheader.us.us:\n %diff.check1 = icmp ult i64 %9, 32\n %diff.check2 = icmp ult i64 %10, 32\n %conflict.rdx3 = or i1 %diff.check1, %diff.check2\n %diff.check4 = icmp ult i64 %11, 32\n %conflict.rdx5 = or i1 %conflict.rdx3, %diff.check4\n %diff.check6 = icmp ult i64 %12, 32\n %conflict.rdx7 = or i1 %conflict.rdx5, %diff.check6\n %diff.check8 = icmp ult i64 %13, 32\n %conflict.rdx9 = or i1 %conflict.rdx7, %diff.check8\n %diff.check10 = icmp ult i64 %14, 32\n %conflict.rdx11 = or i1 %conflict.rdx9, %diff.check10\n %diff.check12 = icmp ult i64 %15, 32\n %conflict.rdx13 = or i1 %conflict.rdx11, %diff.check12\n %diff.check14 = icmp ult i64 %16, 32\n %conflict.rdx15 = or i1 %conflict.rdx13, %diff.check14\n br i1 %conflict.rdx15, label %scalar.ph, label %.preheader.us.us\n\nscalar.ph:\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "SLP: Instruction does not dominate all uses (insertelement/shufflevector)", "body": "[slp.ll.gz](https://github.com/user-attachments/files/18972113/slp.ll.gz)\n\nReproducer: `opt -passes=slp-vectorizer slp.ll -mcpu=skylake`\n\n@alexey-bataev can you please take a look?", "author": "vzakhari", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
126181
https://github.com/llvm/llvm-project/issues/126181
miscompilation
317a644ae6d501f1a1ec54d17ea8559bcdea35c0
2025-02-07T05:51:32
[ "llvm/test/Transforms/DeadStoreElimination" ]
{ "fix_commit": "2d31a12dbe2339d20844ede70cbb54dbaf4ceea9", "components": [ "DeadStoreElimination" ], "bug_location_lineno": { "llvm/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": [ [ 2283, 2289 ] ], "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": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [ "DSEState::getInitializesArgMemLoc" ], "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 2d31a12dbe2339d20844ede70cbb54dbaf4ceea9 Author: Nikita Popov <[email protected]> Date: Mon Feb 10 10:34:03 2025 +0100 [DSE] Don't use initializes on byval argument (#126259) There are two ways we can fix this problem, depending on how the semantics of byval and initializes should interact: * Don't infer initializes on byval arguments. initializes on byval refers to the original caller memory (or having both attributes is made a verifier error). * Infer initializes on byval, but don't use it in DSE. initializes on byval refers to the callee copy. This matches the semantics of readonly on byval. This is slightly more powerful, for example, we could do a backend optimization where byval + initializes will allocate the full size of byval on the stack but not copy over the parts covered by initializes. I went with the second variant here, skipping byval + initializes in DSE (FunctionAttrs already doesn't propagate initializes past byval). I'm open to going in the other direction though. Fixes https://github.com/llvm/llvm-project/issues/126181. diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 05b4f176bfc3..38454053b039 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -2283,7 +2283,9 @@ DSEState::getInitializesArgMemLoc(const Instruction *I) { for (unsigned Idx = 0, Count = CB->arg_size(); Idx < Count; ++Idx) { ConstantRangeList Inits; Attribute InitializesAttr = CB->getParamAttr(Idx, Attribute::Initializes); - if (InitializesAttr.isValid()) + // initializes on byval arguments refers to the callee copy, not the + // original memory the caller passed in. + if (InitializesAttr.isValid() && !CB->isByValArgument(Idx)) Inits = InitializesAttr.getValueAsConstantRangeList(); Value *CurArg = CB->getArgOperand(Idx);
[ { "file": "llvm/test/Transforms/DeadStoreElimination/inter-procedural.ll", "commands": [ "opt < %s -passes=dse -enable-dse-initializes-attr-improvement -S" ], "tests": [ { "test_name": "test_byval", "test_body": "%struct.a = type { i32, i64, i32, i32 }\n\n@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8\n\ndefine i8 @ad(ptr byval(%struct.a) %ah) {\nentry:\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine i64 @af(ptr byval(%struct.a) initializes((0, 24)) %am) {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n\ndefine i32 @main() {\n %res = call i8 @ad(ptr @e)\n %val = sext i8 %res to i32\n ret i32 %val\n}\n", "lli_expected_out": "", "additional_args": null } ] } ]
{ "title": "[FuncAttrs] `initializes` is incorrectly set on parameters with `byval`", "body": "Reproducer: https://godbolt.org/z/Mcx1nY4E7\n```\n; bin/opt -passes=function-attrs reduced.ll -S\n%struct.a = type { i32, i64, i32, i32 }\n\n@e = dso_local global { i32, [4 x i8], i64, i32, i32 } { i32 5, [4 x i8] zeroinitializer, i64 0, i32 1, i32 90986701 }, align 8\n\ndefine i8 @ad(ptr byval(%struct.a) %ah) {\nentry:\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine i64 @af(ptr byval(%struct.a) %am) {\nentry:\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n\n```\n```\ndefine i8 @ad(ptr byval(%struct.a) captures(none) initializes((0, 4)) %ah) #0 {\n store i32 0, ptr %ah, align 8\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine noundef i64 @af(ptr writeonly byval(%struct.a) captures(none) initializes((0, 24)) %am) #0 {\n call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %am, ptr noundef nonnull align 8 dereferenceable(24) @e, i64 24, i1 false)\n ret i64 0\n}\n```\nAfter DSE:\n```\ndefine i8 @ad(ptr byval(%struct.a) captures(none) initializes((0, 4)) %ah) #0 {\n %call = call i64 @af(ptr %ah)\n %0 = load i8, ptr %ah, align 1\n ret i8 %0\n}\n\ndefine noundef i64 @af(ptr writeonly byval(%struct.a) captures(none) initializes((0, 24)) %am) #0 {\n ret i64 0\n}\n```\n\nllvm version: d21fc58aeeaa7f0369a24dbe70a0360e0edbf76f\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "nikic", "body": "> We should also emit the padding for %struct.a.\n\nWithout commenting on whether we should or shouldn't, why is not having the padding a miscompile? As this is not a packed struct, for a i64:64 target, LLVM will implicitly insert the padding and it should have the correct size." }, { "author": "dtcxzyw", "body": "> As this is not a packed struct, for a i64:64 target, LLVM will implicitly insert the padding and it should have the correct size.\n\nSorry. It is a DSE bug.\n" }, { "author": "dtcxzyw", "body": "cc @haopliu " }, { "author": "nikic", "body": "@dtcxzyw I think your new IR is over-reduced. You have `initializes((0, 24)` on `@af`, so I think eliminating the store is correct." }, { "author": "dtcxzyw", "body": "> [@dtcxzyw](https://github.com/dtcxzyw) I think your new IR is over-reduced. You have `initializes((0, 24)` on `@af`, so I think eliminating the store is correct.\n\nFixed." }, { "author": "nikic", "body": "There are two ways we can fix this, depending on what we want the semantics to do:\n\n 1. Don't infer initializes on byval arguments. initializes on byval refers to the original caller memory (or having both attributes is made a verifier error).\n 2. Infer initializes on byval, but don't use it in DSE. initializes on byval refers to the callee copy. This matches the semantics of readonly on byval.\n\nI think variant 2 is marginally more powerful. For example, we could do a backend optimization where byval + initializes will allocate the full size of byval on the stack but not copy over the parts covered by initializes." } ] }
true
null
113143
https://github.com/llvm/llvm-project/issues/113143
crash
42ba452aa94e4da277842d8990ad958a6256e558
2024-10-21T10:11:54
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "9e03920cbf946e7ba282e99213707643a23ae5fb", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 12466, 12472 ] ], "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" ], "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 9e03920cbf946e7ba282e99213707643a23ae5fb Author: Alexey Bataev <[email protected]> Date: Mon Oct 21 08:57:36 2024 -0700 [SLP]Ignore root gather node, when searching for reuses Root gather/buildvector node should be ignored when SLP vectorizer tries to find matching gather nodes, vectorized earlier. This node is definitely the last one in the pipeline and it does not have users. It may cause the compiler crash Fixes #113143 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 1098bf578d2d..a11e3f3815cb 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -12466,7 +12466,7 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( // Build a list of tree entries where V is used. SmallPtrSet<const TreeEntry *, 4> VToTEs; for (const TreeEntry *TEPtr : ValueToGatherNodes.find(V)->second) { - if (TEPtr == TE) + if (TEPtr == TE || TEPtr->Idx == 0) continue; assert(any_of(TEPtr->Scalars, [&](Value *V) { return GatheredScalars.contains(V); }) &&
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/root-gather-reused-scalar.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %a, i32 %0, i32 %1, i1 %cmp1) {\nentry:\n %2 = load i32, ptr %a, align 4\n %tobool10.not = icmp eq i32 %0, 0\n %cmp4.3 = icmp ne i32 %1, 0\n %3 = and i1 %cmp4.3, %tobool10.not\n %cmp2.2 = xor i1 %tobool10.not, true\n %conv3.2 = zext i1 %cmp2.2 to i32\n %cmp4.2 = icmp ne i32 %2, %conv3.2\n %cmp2.1 = xor i1 %cmp1, true\n %conv3.1 = zext i1 %cmp2.1 to i32\n %cmp4.1 = icmp ne i32 %2, %conv3.1\n %4 = select i1 %3, i1 %cmp4.2, i1 false\n %5 = select i1 %4, i1 %cmp4.1, i1 false\n %and.3 = zext i1 %5 to i32\n store i32 %and.3, ptr %a, align 4\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "clang crashes on valid code at -O2 on x86_64-linux-gnu: Assertion `TEPtr->UserTreeIndices.size() == 1 && \"Expected only single user of a gather node.\"' 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/a1W3c5ard\r\n\r\n```\r\n[523] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git df8b785838a2db01b4d056e603f7317209accefb)\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[524] % \r\n[524] % clangtk -O2 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:12559: std::optional<llvm::TargetTransformInfo::ShuffleKind> llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef<llvm::Value*>, llvm::MutableArrayRef<int>, llvm::SmallVectorImpl<const llvm::slpvectorizer::BoUpSLP::TreeEntry*>&, unsigned int, bool): Assertion `TEPtr->UserTreeIndices.size() == 1 && \"Expected only single user of a gather node.\"' 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/20241020-clangtk-m64-O2-build-231331/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241020-clangtk-m64-O2-build-231331/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-572b89.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 \"slp-vectorizer\" on function \"main\"\r\n #0 0x0000560576c8b9af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x43f29af)\r\n #1 0x0000560576c89184 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f4623c27420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f462365e00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f462363d859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f462363d729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f462363d729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f462364efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000560578707edc llvm::slpvectorizer::BoUpSLP::isGatherShuffledSingleRegisterEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::MutableArrayRef<int>, llvm::SmallVectorImpl<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>&, unsigned int, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e6eedc)\r\n #9 0x0000560578708cd8 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e6fcd8)\r\n#10 0x000056057870a6f3 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e716f3)\r\n#11 0x000056057870cde7 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e73de7)\r\n#12 0x0000560578745f69 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5eacf69)\r\n#13 0x000056057874b57b (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#14 0x000056057874eb79 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-20+0x5eb5b79)\r\n#15 0x000056057875349b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#16 0x0000560578757d50 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5ebed50)\r\n#17 0x000056057875e590 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#18 0x000056057875f263 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5ec6263)\r\n#19 0x00005605781e0e66 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-20+0x5947e66)\r\n#20 0x0000560576614891 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+0x3d7b891)\r\n#21 0x000056057410e656 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+0x1875656)\r\n#22 0x00005605766131fd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3d7a1fd)\r\n#23 0x000056057410d196 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+0x1874196)\r\n#24 0x0000560576612c31 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+0x3d79c31)\r\n#25 0x0000560576f44dd3 (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#26 0x0000560576f483a8 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+0x46af3a8)\r\n#27 0x000056057764462c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4dab62c)\r\n#28 0x000056057951629c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6c7d29c)\r\n#29 0x0000560577644a48 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4daba48)\r\n#30 0x000056057790d3d9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x50743d9)\r\n#31 0x00005605778895ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4ff05ce)\r\n#32 0x00005605779f9f26 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5160f26)\r\n#33 0x0000560573cd1fe5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1438fe5)\r\n#34 0x0000560573cc9afa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#35 0x0000560573cce52e clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x143552e)\r\n#36 0x0000560573bba67b main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x132167b)\r\n#37 0x00007f462363f083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#38 0x0000560573cc958e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x143058e)\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 df8b785838a2db01b4d056e603f7317209accefb)\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-d99d4e.c\r\nclangtk: note: diagnostic msg: /tmp/small-d99d4e.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[525] % \r\n[525] % cat small.c\r\nint a, b, c, d, e, f;\r\nint main() {\r\n for (f = 0; f < 4; f++) {\r\n d &= (((a > 0) != b) != c) && b;\r\n for (b = 0; b < 1; b++)\r\n if (e)\r\n break;\r\n }\r\n return 0;\r\n}\r\n```\r\n\r\n", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
114082
https://github.com/llvm/llvm-project/issues/114082
crash
0f040433d325aa68ec6840aa179f3f314c26153a
2024-10-29T16:26:31
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "77bec78878762e34150fe23734fa43df796c873c", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13398, 13404 ] ], "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::getLastInstructionInBundle" ], "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 77bec78878762e34150fe23734fa43df796c873c Author: Alexey Bataev <[email protected]> Date: Fri Nov 8 04:16:01 2024 -0800 [SLP]Do not look for last instruction in schedule block for buildvectors If looking for the insertion point for the node and the node is a buildvector node, the compiler should not use scheduling info for such nodes, they may contain only partial info, which is not fully correct and may cause compiler crash. Fixes #114082 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index b2f677fb84f9..c5b3537bc57b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13398,7 +13398,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) { // scheduled, and the last instruction is VL.back(). So we start with // VL.back() and iterate over schedule data until we reach the end of the // bundle. The end of the bundle is marked by null ScheduleData. - if (BlocksSchedules.count(BB)) { + if (BlocksSchedules.count(BB) && !E->isGather()) { Value *V = E->isOneOf(E->Scalars.back()); if (doesNotNeedToBeScheduled(V)) V = *find_if_not(E->Scalars, doesNotNeedToBeScheduled);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n %icmp = icmp samesign ult i32 0, 0\n %select = select i1 %icmp, i32 0, i32 0\n %zext = zext i32 %select to i64\n %getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext\n store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8\n %icmp1 = icmp eq i32 0, 0\n %icmp2 = icmp eq i32 0, 0\n %icmp3 = icmp samesign ult i32 0, 0\n %icmp4 = icmp eq i32 0, 0\n %add = add i32 1, 0\n %icmp5 = icmp samesign ult i32 %add, 0\n store volatile i32 0, ptr addrspace(1) null, align 4\n %call = call i32 null(<2 x double> zeroinitializer)\n %icmp6 = icmp eq i32 %call, 0\n %icmp7 = icmp samesign ult i32 0, 0\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with the test below with -passes=slp-vectorizer -slp-threshold=-99999\r\n```; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() #0 gc \"statepoint-example\" {\r\nbb:\r\n %icmp = icmp samesign ult i32 0, 0\r\n %select = select i1 %icmp, i32 0, i32 0\r\n %zext = zext i32 %select to i64\r\n %getelementptr = getelementptr ptr addrspace(1), ptr addrspace(1) null, i64 %zext\r\n store ptr addrspace(1) null, ptr addrspace(1) %getelementptr, align 8\r\n %icmp1 = icmp eq i32 0, 0\r\n %icmp2 = icmp eq i32 0, 0\r\n %icmp3 = icmp samesign ult i32 0, 0\r\n %icmp4 = icmp eq i32 0, 0\r\n %add = add i32 1, 0\r\n %icmp5 = icmp samesign ult i32 %add, 0\r\n store volatile i32 0, ptr addrspace(1) null, align 4\r\n %call = call i32 @llvm.x86.sse2.cvttsd2si(<2 x double> zeroinitializer)\r\n %icmp6 = icmp eq i32 %call, 0\r\n %icmp7 = icmp samesign ult i32 0, 0\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\r\ndeclare i32 @llvm.x86.sse2.cvttsd2si(<2 x double>) #1\r\n\r\nattributes #0 = { \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\r\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(none) \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\r\n```\r\nReproducer: https://godbolt.org/z/nTE84xq7n\r\n\r\nStack dump\r\n```\r\nInstruction does not dominate all uses!\r\n %5 = icmp eq <4 x i32> %4, zeroinitializer\r\n %2 = call <8 x i1> @llvm.vector.insert.v8i1.v4i1(<8 x i1> poison, <4 x i1> %5, i64 0)\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"verify\" on module \"<source>\"\r\n #0 0x00000000050e7a98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50e7a98)\r\n #1 0x00000000050e548c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000078c8a0042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000078c8a00969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000078c8a0042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000078c8a00287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007d7d7b llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x00000000050265b8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50265b8)\r\n #8 0x0000000004f24790 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f24790)\r\n #9 0x00000000009015ce llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9015ce)\r\n#10 0x0000000004ee5440 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ee5440)\r\n#11 0x000000000090c1ea llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90c1ea)\r\n#12 0x00000000008ff258 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff258)\r\n#13 0x000078c8a0029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x000078c8a0029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008f6d2e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d2e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
126974
https://github.com/llvm/llvm-project/issues/126974
miscompilation
dab9156923133b4ce3c40efcae4f80b0d720e72f
2025-02-12T21:21:07
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "29f3a352068ce562bcb65e18a676c82a9991583c", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 5637, 5642 ] ], "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::foldICmpWithMinMax" ], "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 29f3a352068ce562bcb65e18a676c82a9991583c Author: Yingwei Zheng <[email protected]> Date: Sun Feb 16 20:18:29 2025 +0800 [InstCombine] Do not keep samesign when speculatively executing icmps (#127007) Closes https://github.com/llvm/llvm-project/issues/126974. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 96d6db2ba5bf..76020d2b1dbf 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -5637,6 +5637,11 @@ Instruction *InstCombinerImpl::foldICmpWithMinMax(Instruction &I, return false; return std::nullopt; }; + // Remove samesign here since it is illegal to keep it when we speculatively + // execute comparisons. For example, `icmp samesign ult umax(X, -46), -32` + // cannot be decomposed into `(icmp samesign ult X, -46) or (icmp samesign ult + // -46, -32)`. `X` is allowed to be non-negative here. + Pred = static_cast<CmpInst::Predicate>(Pred); auto CmpXZ = IsCondKnownTrue(simplifyICmpInst(Pred, X, Z, Q)); auto CmpYZ = IsCondKnownTrue(simplifyICmpInst(Pred, Y, Z, Q)); if (!CmpXZ.has_value() && !CmpYZ.has_value())
[ { "file": "llvm/test/Transforms/InstCombine/umax-icmp.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr126974", "test_body": "define i1 @pr126974(i8 %x) {\nentry:\n %cond = icmp sgt i8 %x, -2\n br i1 %cond, label %if.then, label %if.else\n\nif.then: ; preds = %entry\n %umax = call i8 @llvm.umax.i8(i8 %x, i8 -46)\n %cmp = icmp samesign ult i8 %umax, -32\n ret i1 %cmp\n\nif.else: ; preds = %entry\n ret i1 false\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.umax.i8(i8, i8) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[RISC-V] Miscompile using rv64gcv", "body": "Testcase:\n```c\nint a[][21][21];\nvoid b(int c, int d, int e, short f, _Bool g, char h, char i, int j, int k,\n int l, unsigned char m, int n, char o, int p, long long q[],\n unsigned short r[][10], unsigned s[][10],\n unsigned long long t[][10][10][10], unsigned long long u[][10][10][10],\n int w[][10][10][10][10], _Bool x) {\n for (signed z = 0; z < (char)m + 3; z = 4)\n for (short aa = ({\n __typeof__(0) ab = 173;\n __typeof__(0) ac = ({\n __typeof__(0) ab = m;\n ab;\n });\n ab > ac ? ab : ac;\n }) -\n 171;\n aa < 9; aa = k)\n a[z][aa][aa] = ~0;\n}\ntypedef int ad;\nint printf(const char *, ...);\nlong long ae;\nvoid af(long long *ae, int v) { *ae ^= v; }\nint c;\nint d;\nint e;\nshort f;\n_Bool g;\nchar h;\nchar i;\nint j;\nint k = 2805750831;\nint l;\nchar m;\nint n;\nchar o;\nint p;\nlong long q[0];\nunsigned short r[0][10];\nunsigned s[0][10];\nunsigned long long t[0][10][10][10];\nunsigned long long u[0][10][10][10];\nint w[0][10][10][10][10];\n_Bool x;\nint a[21][21][21];\nvoid ag() {\n for (ad y = 0; y < 10; ++y)\n for (ad ah = 0; ah < 10; ++ah)\n for (ad ai = 0; ai < 10; ++ai)\n af(&ae, a[y][ah][ai]);\n}\nint main() {\n b(c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, w, x);\n ag();\n printf(\"%llu\\n\", ae);\n}\n```\n\nCommands:\n```\n# riscv \n$ QEMU_CPU=rv64,vlen=128,rvv_ta_all_1s=true,rvv_ma_all_1s=true,v=true,vext_spec=v1.0,zve32f=true,zve64f=true timeout --verbose -k 0.1 4 /scratch/ewlu/daily-upstream-build/build-gcv/bin/qemu-riscv64 user-config.out 1\n0\n\n# x86\n$ ./native.out 1\n18446744073709551615\n```\n\nGodbolt: https://godbolt.org/z/85rz18rxY\n\nBisected to cfee344dda7394631f2177a15e56cfeee1d61fc4 as the first bad commit\n\nI tried reducing the testcase down farther but was unsuccessful\n\nFound via fuzzer. First detected 01/24/2025", "author": "ewlu", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "dzaima", "body": "Some manual simplification, reproduces on x86-64 `-O3` too:\n\n```c\n#include<stdio.h>\n\nvoid f(int more_than_20, unsigned char zero) {\n int i = 0;\n while (i < (signed char)zero + 2) {\n int max = zero < 210 ? 210 : zero; // 210; has to be >127\n int j = max - 200; // 10\n while (j < 20) {\n printf(\"I should be printed once\\n\");\n j = more_than_20;\n }\n i = 2; // can be anything >2\n }\n}\n\nint main() {\n f(50, 0);\n}\n```\n\nhttps://godbolt.org/z/qfn9PT6r5" }, { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/adparc" }, { "author": "dtcxzyw", "body": "Further reduced: https://alive2.llvm.org/ce/z/5da83j" } ] }
true
null
107139
https://github.com/llvm/llvm-project/issues/107139
crash
5d17293caaf0f62ea94fecc137b9b6f07c659dac
2024-09-03T18:28:59
[ "llvm/test/Transforms/Coroutines" ]
{ "fix_commit": "853bff2122e1f42398587f76234c05d56f16318e", "components": [ "Coroutines" ], "bug_location_lineno": { "llvm/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": [ [ 2080, 2091 ], [ 2105, 2117 ], [ 2200, 2205 ], [ 2211, 2217 ], [ 2223, 2236 ] ], "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": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": [ "CoroSplitPass::run", "replacePrepare", "splitCoroutine", "updateCallGraphAfterCoroutineSplit" ], "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 853bff2122e1f42398587f76234c05d56f16318e Author: Yuxuan Chen <[email protected]> Date: Thu Sep 12 10:45:20 2024 -0700 [Coroutines] properly update CallGraph in CoroSplit (#107935) Fixes https://github.com/llvm/llvm-project/issues/107139. We weren't updating the call graph properly in CoroSplit. This crash is due to the await_suspend() function calling the coroutine, forming a multi-node SCC. The issue bisected to https://github.com/llvm/llvm-project/pull/79712 but I think this is red herring. We haven't been properly updating the call graph. Added an example of such code as a test case. diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index dc3829d7f28e..8ea460badaad 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -2080,12 +2080,13 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones, return Shape; } -static void updateCallGraphAfterCoroutineSplit( +static LazyCallGraph::SCC &updateCallGraphAfterCoroutineSplit( LazyCallGraph::Node &N, const coro::Shape &Shape, const SmallVectorImpl<Function *> &Clones, LazyCallGraph::SCC &C, LazyCallGraph &CG, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR, FunctionAnalysisManager &FAM) { + auto *CurrentSCC = &C; if (!Clones.empty()) { switch (Shape.ABI) { case coro::ABI::Switch: @@ -2105,13 +2106,16 @@ static void updateCallGraphAfterCoroutineSplit( } // Let the CGSCC infra handle the changes to the original function. - updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM); + CurrentSCC = &updateCGAndAnalysisManagerForCGSCCPass(CG, *CurrentSCC, N, AM, + UR, FAM); } // Do some cleanup and let the CGSCC infra see if we've cleaned up any edges // to the split functions. postSplitCleanup(N.getFunction()); - updateCGAndAnalysisManagerForFunctionPass(CG, C, N, AM, UR, FAM); + CurrentSCC = &updateCGAndAnalysisManagerForFunctionPass(CG, *CurrentSCC, N, + AM, UR, FAM); + return *CurrentSCC; } /// Replace a call to llvm.coro.prepare.retcon. @@ -2200,6 +2204,7 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C, if (Coroutines.empty() && PrepareFns.empty()) return PreservedAnalyses::all(); + auto *CurrentSCC = &C; // Split all the coroutines. for (LazyCallGraph::Node *N : Coroutines) { Function &F = N->getFunction(); @@ -2211,7 +2216,8 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C, coro::Shape Shape = splitCoroutine(F, Clones, FAM.getResult<TargetIRAnalysis>(F), OptimizeFrame, MaterializableCallback); - updateCallGraphAfterCoroutineSplit(*N, Shape, Clones, C, CG, AM, UR, FAM); + CurrentSCC = &updateCallGraphAfterCoroutineSplit( + *N, Shape, Clones, *CurrentSCC, CG, AM, UR, FAM); auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F); ORE.emit([&]() { @@ -2223,14 +2229,14 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C, if (!Shape.CoroSuspends.empty()) { // Run the CGSCC pipeline on the original and newly split functions. - UR.CWorklist.insert(&C); + UR.CWorklist.insert(CurrentSCC); for (Function *Clone : Clones) UR.CWorklist.insert(CG.lookupSCC(CG.get(*Clone))); } } for (auto *PrepareFn : PrepareFns) { - replaceAllPrepares(PrepareFn, CG, C); + replaceAllPrepares(PrepareFn, CG, *CurrentSCC); } return PreservedAnalyses::none();
[ { "file": "llvm/test/Transforms/Coroutines/gh107139-split-in-scc.ll", "commands": [ "opt < %s -passes='cgscc(coro-split)' -S" ], "tests": [ { "test_name": "<module>", "test_body": "; Verify that we don't crash on mutually recursive coroutines\n\ntarget triple = \"x86_64-redhat-linux-gnu\"\n\ndefine void @foo() presplitcoroutine personality ptr null {\nentry:\n\n %0 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)\n %1 = call ptr @llvm.coro.begin(token %0, ptr null)\n %2 = call token @llvm.coro.save(ptr null)\n %3 = call i8 @llvm.coro.suspend(token none, i1 false)\n %4 = call token @llvm.coro.save(ptr null)\n call void @llvm.coro.await.suspend.void(ptr null, ptr null, ptr @bar)\n ret void\n}\n\ndefine void @bar(ptr %0, ptr %1) {\nentry:\n call void @foo()\n ret void\n}\n\n\ndeclare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #0\ndeclare ptr @llvm.coro.begin(token, ptr writeonly) nounwind\ndeclare token @llvm.coro.save(ptr) nomerge nounwind\ndeclare void @llvm.coro.await.suspend.void(ptr, ptr, ptr)\ndeclare i8 @llvm.coro.suspend(token, i1) nounwind\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "\"Invalidated the current SCC\" assertion failure after #79712", "body": "For the source file in https://gist.github.com/smeenai/fcd14380467e813a28f1ef8c5484b775 (reduced from a large example that uses libunifex; it's probably possible to reduce this further but I'm not at all familiar with coroutines), the following command succeeds with Clang 18 but fails with Clang 19 and trunk:\r\n\r\n```\r\n$ clang -c -o /dev/null coroutine_crash.cpp -std=c++20 -w\r\nclang: llvm/lib/Analysis/CGSCCPassManager.cpp:1167: LazyCallGraph::SCC &updateCGAndAnalysisManagerForPass(llvm::LazyCallGraph &, LazyCallGraph::SCC &, LazyCallGraph::Node &, llvm::CGSCCAnalysisManager &, llvm::CGSCCUpdateResult &, llvm::FunctionAnalysisManager &, bool): Assertion `!UR.InvalidatedSCCs.count(C) && \"Invalidated the current SCC!\"' failed.\r\n```\r\n\r\nI bisected this to #79712. CC @fpasserby, @ChuanqiXu9, and @yuxuanchen1997 ", "author": "smeenai", "labels": [ "crash", "coroutines", "llvm:transforms" ], "comments": [ { "author": "yuxuanchen1997", "body": "I took a look at this and I think it was due to incorrect call graph updates. `updateCGAndAnalysisManagerFor(CGSCC|Function)Pass` seems to return an updated SCC but we discarded the updated SCC.\r\n\r\nSee example usage: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/CGSCCPassManager.cpp#L561-L562\r\nSee implementation: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Analysis/CGSCCPassManager.cpp#L1170-L1175\r\n\r\nI have a patch https://github.com/llvm/llvm-project/pull/107935 but still need some time for a test case. " }, { "author": "yuxuanchen1997", "body": "This happens when foo has is not a single node SCC:\r\n```\r\ndefine void @foo() presplitcoroutine personality ptr null {\r\nentry:\r\n %0 = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)\r\n %1 = call ptr @llvm.coro.begin(token %0, ptr null)\r\n %2 = call token @llvm.coro.save(ptr null)\r\n %3 = call i8 @llvm.coro.suspend(token none, i1 false)\r\n %4 = call token @llvm.coro.save(ptr null)\r\n call void @llvm.coro.await.suspend.void(ptr null, ptr null, ptr @bar)\r\n ret void\r\n}\r\n\r\ndefine void @bar(ptr %0, ptr %1) {\r\nentry:\r\n call void @foo()\r\n ret void\r\n}\r\n\r\ndeclare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #0\r\ndeclare ptr @llvm.coro.begin(token, ptr writeonly) nounwind\r\ndeclare token @llvm.coro.save(ptr) nomerge nounwind\r\ndeclare void @llvm.coro.await.suspend.void(ptr, ptr, ptr)\r\ndeclare i8 @llvm.coro.suspend(token, i1) nounwind\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }\r\n```\r\n\r\nRepro the crash with `clang -O0 bad.ll`." }, { "author": "yuxuanchen1997", "body": "The 3rd argument to `@llvm.coro.await.suspend` is the `await_suspend` function in C++. This happens when `await_suspend()` calls the same coroutine from its body. " } ] }
true
null
104637
https://github.com/llvm/llvm-project/issues/104637
crash
13779ec29ed724666407bd60f8c4cc8228107ea5
2024-08-16T19:54:48
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "4a0bbbcbcf6ebc87e794e7b86b9f4651bffcd806", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7144, 7149 ] ], "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 4a0bbbcbcf6ebc87e794e7b86b9f4651bffcd806 Author: Alexey Bataev <[email protected]> Date: Fri Aug 16 13:24:03 2024 -0700 [SLP]Fix PR104637: do not create new nodes for fully overlapped non-schedulable nodes If the scalars do not require scheduling and were already vectorized, but in the different order, compiler still tries to create the new node. It may cause the compiler crash for the gathered operands. Instead need to consider such nodes as full overlap and just reshuffle vectorized node. Fixes https://github.com/llvm/llvm-project/issues/104637 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 667d0df781aa..9ecd8160a978 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7144,6 +7144,21 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, ReuseShuffleIndices); return; } + SmallPtrSet<const TreeEntry *, 4> Nodes; + Nodes.insert(getTreeEntry(S.OpValue)); + for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue)) + Nodes.insert(E); + SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end()); + if (any_of(Nodes, [&](const TreeEntry *E) { + return all_of(E->Scalars, + [&](Value *V) { return Values.contains(V); }); + })) { + LLVM_DEBUG(dbgs() << "SLP: Gathering due to full overlap.\n"); + if (TryToFindDuplicates(S)) + newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx, + ReuseShuffleIndices); + return; + } } else { // Record the reuse of the tree node. FIXME, currently this is only used // to properly draw the graph rather than for the actual vectorization.
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/full-non-schedulable-overlap.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test(double %v) {\nentry:\n %mul.3 = fmul double 0.000000e+00, %v\n %mul.4 = fmul double 0.000000e+00, 0.000000e+00\n br label %loop\n\nloop: ; preds = %loop, %entry\n %t48.0 = phi double [ 0.000000e+00, %entry ], [ %5, %loop ]\n %t50.02 = phi double [ 0.000000e+00, %entry ], [ %3, %loop ]\n %t52.0 = phi double [ 0.000000e+00, %entry ], [ %7, %loop ]\n %0 = fmul double %t52.0, %mul.3\n %1 = fmul double %t48.0, %mul.4\n %2 = fadd double %1, %0\n %3 = fadd double %2, %v\n %4 = fmul double 0.000000e+00, %mul.3\n %5 = fadd double 0.000000e+00, %4\n %6 = fmul double 0.000000e+00, %mul.4\n %7 = fadd double 0.000000e+00, %6\n br label %loop\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "SLP Vectorizer crash due to commit ca654acc16c43191228eadfec8f7241dca10b0c3", "body": "ca654acc16c43191228eadfec8f7241dca10b0c3 change in SLP Vectorizer causes a crash for this test case:\r\n\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 void @a_(double %c__fetch.3) {\r\nalloca_0:\r\n %mul.3 = fmul double 0.000000e+00, %c__fetch.3\r\n %mul.4 = fmul double 0.000000e+00, 0.000000e+00\r\n br label %loop.69\r\n\r\nloop.69: ; preds = %loop.69, %alloca_0\r\n %t48.0 = phi double [ 0.000000e+00, %alloca_0 ], [ %5, %loop.69 ]\r\n %t50.0 = phi double [ 0.000000e+00, %alloca_0 ], [ %3, %loop.69 ]\r\n %t52.0 = phi double [ 0.000000e+00, %alloca_0 ], [ %7, %loop.69 ]\r\n %0 = fmul double %t52.0, %mul.3\r\n %1 = fmul double %t48.0, %mul.4\r\n %2 = fadd double %1, %0\r\n %3 = fadd double %2, 0.000000e+00\r\n %4 = fmul double 0.000000e+00, %mul.3\r\n %5 = fadd double 0.000000e+00, %4\r\n %6 = fmul double 0.000000e+00, %mul.4\r\n %7 = fadd double 0.000000e+00, %6\r\n br label %loop.69\r\n}\r\n```\r\n\r\nAfter slp-vectorizer pass IR is being transformed to as incorrect one:\r\n```\r\ndefine void @a_(double %c__fetch.3) {\r\nalloca_0:\r\n %0 = shufflevector <2 x double> %2, <2 x double> <double 0.000000e+00, double poison>, <2 x i32> <i32 2, i32 0>\r\n %1 = fmul <2 x double> zeroinitializer, %0\r\n %2 = insertelement <2 x double> <double poison, double 0.000000e+00>, double %c__fetch.3, i32 0\r\n %3 = fmul <2 x double> zeroinitializer, %2\r\n br label %loop.69\r\n\r\nloop.69: ; preds = %loop.69, %alloca_0\r\n %t50.0 = phi double [ 0.000000e+00, %alloca_0 ], [ %9, %loop.69 ]\r\n %4 = phi <2 x double> [ zeroinitializer, %alloca_0 ], [ %11, %loop.69 ]\r\n %5 = fmul <2 x double> %4, %1\r\n %6 = extractelement <2 x double> %5, i32 0\r\n %7 = extractelement <2 x double> %5, i32 1\r\n %8 = fadd double %6, %7\r\n %9 = fadd double %8, 0.000000e+00\r\n %10 = fmul <2 x double> zeroinitializer, %3\r\n %11 = fadd <2 x double> zeroinitializer, %10\r\n br label %loop.69\r\n}\r\n```\r\n\r\nError message:\r\n\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = insertelement <2 x double> <double poison, double 0.000000e+00>, double %c__fetch.3, i32 0\r\n %0 = shufflevector <2 x double> %2, <2 x double> <double 0.000000e+00, double poison>, <2 x i32> <i32 2, i32 0>\r\nLLVM ERROR: Broken module found, compilation aborted!\r\n```\r\n\r\nReverting the mentioned commit makes this test pass. @alexey-bataev could you please take a look?\r\n", "author": "ivankelarev", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "ivankelarev", "body": "Update: It appears that the mentioned commit merely obscures a more fundamental issue. The following test continues to fail even after the commit has been reverted:\r\n\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 void @a_(double %c__fetch.3) {\r\nalloca_0:\r\n %mul.3 = fmul double 0.000000e+00, %c__fetch.3\r\n %mul.4 = fmul double 0.000000e+00, 0.000000e+00\r\n br label %loop.69\r\n\r\nloop.69: ; preds = %loop.69, %alloca_0\r\n %t48.0 = phi double [ 0.000000e+00, %alloca_0 ], [ %5, %loop.69 ]\r\n %t50.02 = phi double [ 0.000000e+00, %alloca_0 ], [ %3, %loop.69 ]\r\n %t52.0 = phi double [ 0.000000e+00, %alloca_0 ], [ %7, %loop.69 ]\r\n %0 = fmul double %t52.0, %mul.3\r\n %1 = fmul double %t48.0, %mul.4\r\n %2 = fadd double %1, %0\r\n %3 = fadd double %2, %c__fetch.3\r\n %4 = fmul double 0.000000e+00, %mul.3\r\n %5 = fadd double 0.000000e+00, %4\r\n %6 = fmul double 0.000000e+00, %mul.4\r\n %7 = fadd double 0.000000e+00, %6\r\n br label %loop.69\r\n}\r\n```" }, { "author": "ivankelarev", "body": "It appears that the actual problematic commit is the following:\r\n\r\n```\r\ncommit 66775f8ccdcc8264ef349518e1c59d96d4227823\r\nAuthor: Alexey Bataev <[email protected]>\r\nDate: Mon Oct 16 12:50:29 2023 -0700\r\n\r\n [SLP]Fix PR69196: Instruction does not dominate all uses\r\n \r\n During emission of the postponed gathers, need to insert them before\r\n user instruction to avoid use before definition crash.\r\n```\r\nFor compiler builds prior to this change, the test passes, and the correct code is generated as follows:\r\n```\r\ndefine void @a_(double %c__fetch.3) {\r\nalloca_0:\r\n %0 = insertelement <2 x double> <double poison, double 0.000000e+00>, double %c__fetch.3, i32 0\r\n %1 = fmul <2 x double> zeroinitializer, %0\r\n %2 = shufflevector <2 x double> %0, <2 x double> <double 0.000000e+00, double poison>, <2 x i32> <i32 2, i32 0>\r\n %3 = fmul <2 x double> zeroinitializer, %2\r\n br label %loop.69\r\n\r\nloop.69: ; preds = %loop.69, %alloca_0\r\n %t50.02 = phi double [ 0.000000e+00, %alloca_0 ], [ %9, %loop.69 ]\r\n %4 = phi <2 x double> [ zeroinitializer, %alloca_0 ], [ %11, %loop.69 ]\r\n %5 = fmul <2 x double> %4, %3\r\n %6 = extractelement <2 x double> %5, i32 0\r\n %7 = extractelement <2 x double> %5, i32 1\r\n %8 = fadd double %6, %7\r\n %9 = fadd double %8, %c__fetch.3\r\n %10 = fmul <2 x double> zeroinitializer, %1\r\n %11 = fadd <2 x double> zeroinitializer, %10\r\n br label %loop.69\r\n}\r\n```\r\n\r\nAlthough the commit may seem quite old, there is a test case for which it causes incorrect code generation. Alexey, could you please revisit this change and address the code generation issue for the provided test case?" }, { "author": "alexey-bataev", "body": "> It appears that the actual problematic commit is the following:\r\n> \r\n> ```\r\n> commit 66775f8ccdcc8264ef349518e1c59d96d4227823\r\n> Author: Alexey Bataev <[email protected]>\r\n> Date: Mon Oct 16 12:50:29 2023 -0700\r\n> \r\n> [SLP]Fix PR69196: Instruction does not dominate all uses\r\n> \r\n> During emission of the postponed gathers, need to insert them before\r\n> user instruction to avoid use before definition crash.\r\n> ```\r\n> \r\n> For compiler builds prior to this change, the test passes, and the correct code is generated as follows:\r\n> \r\n> ```\r\n> define void @a_(double %c__fetch.3) {\r\n> alloca_0:\r\n> %0 = insertelement <2 x double> <double poison, double 0.000000e+00>, double %c__fetch.3, i32 0\r\n> %1 = fmul <2 x double> zeroinitializer, %0\r\n> %2 = shufflevector <2 x double> %0, <2 x double> <double 0.000000e+00, double poison>, <2 x i32> <i32 2, i32 0>\r\n> %3 = fmul <2 x double> zeroinitializer, %2\r\n> br label %loop.69\r\n> \r\n> loop.69: ; preds = %loop.69, %alloca_0\r\n> %t50.02 = phi double [ 0.000000e+00, %alloca_0 ], [ %9, %loop.69 ]\r\n> %4 = phi <2 x double> [ zeroinitializer, %alloca_0 ], [ %11, %loop.69 ]\r\n> %5 = fmul <2 x double> %4, %3\r\n> %6 = extractelement <2 x double> %5, i32 0\r\n> %7 = extractelement <2 x double> %5, i32 1\r\n> %8 = fadd double %6, %7\r\n> %9 = fadd double %8, %c__fetch.3\r\n> %10 = fmul <2 x double> zeroinitializer, %1\r\n> %11 = fadd <2 x double> zeroinitializer, %10\r\n> br label %loop.69\r\n> }\r\n> ```\r\n> \r\n> Although the commit may seem quite old, there is a test case for which it causes incorrect code generation. Alexey, could you please revisit this change and address the code generation issue for the provided test case?\r\n\r\nThe actual problem is not in this commit, the fix is almost ready" } ] }
true
null
112356
https://github.com/llvm/llvm-project/issues/112356
miscompilation
a3a9ba80337ec1b276a7571049eda6ea03276ea3
2024-10-15T13:21:27
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "9b7491e8669126180253480821d5addde34874d0", "components": [ "IR" ], "bug_location_lineno": { "llvm/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": [ [ 50, 55 ] ], "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": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": [ "Operator::hasPoisonGeneratingFlags" ], "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 9b7491e8669126180253480821d5addde34874d0 Author: Yingwei Zheng <[email protected]> Date: Tue Oct 15 23:07:16 2024 +0800 [IR] Add support for `samesign` in `Operator::hasPoisonGeneratingFlags` (#112358) Fix https://github.com/llvm/llvm-project/issues/112356. diff --git a/llvm/lib/IR/Operator.cpp b/llvm/lib/IR/Operator.cpp index f93ff8f6fc8a..199eb4d90f55 100644 --- a/llvm/lib/IR/Operator.cpp +++ b/llvm/lib/IR/Operator.cpp @@ -50,6 +50,8 @@ bool Operator::hasPoisonGeneratingFlags() const { if (auto *NNI = dyn_cast<PossiblyNonNegInst>(this)) return NNI->hasNonNeg(); return false; + case Instruction::ICmp: + return cast<ICmpInst>(this)->hasSameSign(); default: if (const auto *FP = dyn_cast<FPMathOperator>(this)) return FP->hasNoNaNs() || FP->hasNoInfs();
[ { "file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "icmp_samesign_logical_or", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @icmp_samesign_logical_or(i32 %In) {\n %c1 = icmp samesign slt i32 %In, 0\n %c2 = icmp samesign ne i32 %In, 1\n %V = select i1 %c1, i1 true, i1 %c2\n ret i1 %V\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_and_inv_pow2_or_zero_ne_0", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i1 @icmp_and_inv_pow2_or_zero_ne_0(i32 %A, i32 %B) {\n %popcnt = tail call i32 @llvm.ctpop.i32(i32 %A)\n %cond = icmp ult i32 %popcnt, 2\n call void @llvm.assume(i1 %cond)\n %inv = xor i32 %B, -1\n %and = and i32 %A, %inv\n %cmp = icmp ne i32 %and, 0\n ret i1 %cmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctpop.i32(i32) #1\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_samesign_logical_and", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @icmp_samesign_logical_and(i32 %In) {\n %c1 = icmp samesign sgt i32 %In, -1\n %c2 = icmp samesign eq i32 %In, 1\n %V = select i1 %c1, i1 %c2, i1 false\n ret i1 %V\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped", "body": "Reproducer:\r\n```\r\ndefine i1 @src(i32 %In) {\r\n %c1 = icmp samesign sgt i32 %In, -1\r\n %c2 = icmp samesign eq i32 %In, 1\r\n %V = select i1 %c1, i1 %c2, i1 false\r\n ret i1 %V\r\n}\r\n\r\ndefine i1 @tgt(i32 %In) {\r\n %c2 = icmp samesign eq i32 %In, 1\r\n ret i1 %c2\r\n}\r\n```\r\n\r\nWe should check this flag in `Operator::hasPoisonGeneratingFlags`.\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:ir" ], "comments": [] }
true
null
84051
https://github.com/llvm/llvm-project/issues/84051
crash
b64482e23eefaef7738fde35d0b7c4174aaa6597
2024-03-05T17:59:45
[ "llvm/test/Transforms/DeadStoreElimination" ]
{ "fix_commit": "eb8f379567e8d014194faefe02ce92813e237afc", "components": [ "DeadStoreElimination" ], "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": [ [ 1908, 1922 ] ], "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": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [ "tryFoldIntoCalloc" ], "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 eb8f379567e8d014194faefe02ce92813e237afc Author: Florian Hahn <[email protected]> Date: Wed Mar 6 20:08:00 2024 +0000 [DSE] Remove malloc from EarliestEscapeInfo before removing. (#84157) Not removing the malloc from earliest escape info leaves stale entries in the cache. Fixes https://github.com/llvm/llvm-project/issues/84051. PR: https://github.com/llvm/llvm-project/pull/84157 diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 3d1dac5ea17e..392e6ad5a66b 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1908,15 +1908,15 @@ struct DSEState { Malloc->getArgOperand(0), IRB, TLI); if (!Calloc) return false; + MemorySSAUpdater Updater(&MSSA); auto *NewAccess = Updater.createMemoryAccessAfter(cast<Instruction>(Calloc), nullptr, MallocDef); auto *NewAccessMD = cast<MemoryDef>(NewAccess); Updater.insertDef(NewAccessMD, /*RenameUses=*/true); - Updater.removeMemoryAccess(Malloc); Malloc->replaceAllUsesWith(Calloc); - Malloc->eraseFromParent(); + deleteDeadInstruction(Malloc); return true; }
[ { "file": "llvm/test/Transforms/DeadStoreElimination/malloc-earliest-escape-info-invalidation.ll", "commands": [ "opt -p dse -S %s" ], "tests": [ { "test_name": "widget", "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 @widget(ptr %a) {\nbb:\n %call = tail call ptr @malloc(i64 1)\n tail call void @llvm.memset.p0.i64(ptr %call, i8 0, i64 1, i1 false)\n %call1 = tail call noalias ptr @malloc(i64 0)\n store ptr %call1, ptr %a, align 8\n %load = load ptr, ptr %a, align 8\n %load2 = load i32, ptr %load, align 8\n %getelementptr = getelementptr i8, ptr %call1, i64 0\n %getelementptr3 = getelementptr i8, ptr %getelementptr, i64 1\n store i8 0, ptr %call1, align 1\n %getelementptr4 = getelementptr i8, ptr %getelementptr, i64 8\n store i16 0, ptr %getelementptr4, align 4\n %getelementptr5 = getelementptr i8, ptr %getelementptr, i64 12\n store i32 0, ptr %call1, align 4\n %load6 = load i32, ptr inttoptr (i64 4 to ptr), align 4\n br label %bb48\n\nbb7: ; No predecessors!\n br label %bb9\n\nbb8: ; No predecessors!\n br label %bb53\n\nbb9: ; preds = %bb43, %bb7\n %phi = phi ptr [ %call1, %bb7 ], [ %a, %bb43 ]\n %getelementptr10 = getelementptr i8, ptr %phi, i64 0\n %getelementptr11 = getelementptr i8, ptr %phi, i64 0\n %getelementptr12 = getelementptr i8, ptr %phi, i64 0\n %getelementptr13 = getelementptr i8, ptr %getelementptr12, i64 1\n store i8 0, ptr %call1, align 1\n br label %bb29\n\nbb14: ; No predecessors!\n %getelementptr15 = getelementptr i8, ptr %getelementptr10, i64 8\n %load16 = load i16, ptr %call1, align 4\n br i1 false, label %bb22, label %bb17\n\nbb17: ; preds = %bb14\n %getelementptr18 = getelementptr i8, ptr %getelementptr11, i64 8\n %load19 = load i16, ptr %call1, align 4\n %getelementptr20 = getelementptr i8, ptr %getelementptr12, i64 8\n store i16 0, ptr %call1, align 4\n %getelementptr21 = getelementptr i8, ptr %phi, i64 0\n br label %bb25\n\nbb22: ; preds = %bb14\n %getelementptr23 = getelementptr i8, ptr %phi, i64 0\n %getelementptr24 = getelementptr i8, ptr %getelementptr23, i64 12\n br label %bb25\n\nbb25: ; preds = %bb22, %bb17\n %phi26 = phi ptr [ %a, %bb17 ], [ %call1, %bb22 ]\n %phi27 = phi ptr [ %call1, %bb17 ], [ %call1, %bb22 ]\n %phi28 = phi ptr [ %call1, %bb17 ], [ %call1, %bb22 ]\n store i32 0, ptr %call1, align 4\n br label %bb29\n\nbb29: ; preds = %bb25, %bb9\n %phi30 = phi ptr [ %call1, %bb9 ], [ %call1, %bb25 ]\n %phi31 = phi ptr [ %call1, %bb9 ], [ %call1, %bb25 ]\n %load32 = load i8, ptr %call1, align 4\n %load33 = load i8, ptr %call1, align 4\n %getelementptr34 = getelementptr i8, ptr %phi31, i64 12\n %getelementptr35 = getelementptr i8, ptr %getelementptr12, i64 12\n br label %bb86\n\nbb36: ; No predecessors!\n %getelementptr37 = getelementptr i8, ptr %phi30, i64 12\n br label %bb38\n\nbb38: ; preds = %bb38, %bb36\n %getelementptr39 = getelementptr [0 x i32], ptr %getelementptr34, i64 0, i64 0\n %load40 = load i32, ptr %call1, align 4\n %getelementptr41 = getelementptr [0 x i32], ptr %getelementptr37, i64 0, i64 0\n %load42 = load i32, ptr %call1, align 4\n br label %bb38\n\nbb43: ; No predecessors!\n %getelementptr44 = getelementptr i8, ptr %getelementptr12, i64 8\n %load45 = load i16, ptr %call1, align 4\n store i16 0, ptr %call1, align 4\n store i8 0, ptr %call1, align 4\n %getelementptr46 = getelementptr i8, ptr %getelementptr12, i64 12\n store i32 0, ptr %call1, align 4\n %getelementptr47 = getelementptr i8, ptr %getelementptr12, i64 16\n store i32 0, ptr %call1, align 4\n br label %bb9\n\nbb48: ; preds = %bb48, %bb\n %getelementptr49 = getelementptr i8, ptr %call1, i64 0\n %getelementptr50 = getelementptr i8, ptr %getelementptr49, i64 1\n store i8 0, ptr %call1, align 1\n %getelementptr51 = getelementptr i8, ptr %getelementptr49, i64 8\n store i16 0, ptr %call1, align 4\n %getelementptr52 = getelementptr i8, ptr %getelementptr49, i64 12\n store i32 0, ptr %call1, align 4\n br label %bb48\n\nbb53: ; preds = %bb71, %bb8\n %phi54 = phi ptr [ %call1, %bb8 ], [ %a, %bb71 ]\n %getelementptr55 = getelementptr i8, ptr %phi54, i64 0\n %getelementptr56 = getelementptr i8, ptr %phi54, i64 0\n %getelementptr57 = getelementptr i8, ptr %phi54, i64 0\n %getelementptr58 = getelementptr i8, ptr %getelementptr57, i64 1\n br label %bb71\n\nbb59: ; No predecessors!\n %getelementptr60 = getelementptr i8, ptr %phi54, i64 0\n %getelementptr61 = getelementptr i8, ptr %getelementptr60, i64 12\n br label %bb67\n\nbb62: ; No predecessors!\n %getelementptr63 = getelementptr i8, ptr %getelementptr56, i64 8\n %load64 = load i16, ptr %call1, align 4\n %getelementptr65 = getelementptr i8, ptr %getelementptr57, i64 8\n store i16 0, ptr %call1, align 4\n %getelementptr66 = getelementptr i8, ptr %phi54, i64 0\n br label %bb67\n\nbb67: ; preds = %bb62, %bb59\n %phi68 = phi ptr [ %a, %bb62 ], [ %call1, %bb59 ]\n %phi69 = phi ptr [ %call1, %bb62 ], [ %call1, %bb59 ]\n %phi70 = phi ptr [ %call1, %bb62 ], [ %call1, %bb59 ]\n store i32 0, ptr %call1, align 4\n br label %bb71\n\nbb71: ; preds = %bb67, %bb53\n %phi72 = phi ptr [ %call1, %bb53 ], [ %call1, %bb67 ]\n %phi73 = phi ptr [ %call1, %bb53 ], [ %call1, %bb67 ]\n %load74 = load i8, ptr %call1, align 4\n %load75 = load i8, ptr %call1, align 4\n %getelementptr76 = getelementptr i8, ptr %phi72, i64 12\n %getelementptr77 = getelementptr i8, ptr %getelementptr57, i64 12\n %getelementptr78 = getelementptr [0 x i32], ptr %getelementptr76, i64 0, i64 0\n %load79 = load i32, ptr %call1, align 4\n %getelementptr80 = getelementptr [0 x i32], ptr %getelementptr77, i64 0, i64 0\n store i32 0, ptr %call1, align 4\n %load81 = load i8, ptr %call1, align 4\n %getelementptr82 = getelementptr i8, ptr %getelementptr57, i64 8\n %load83 = load i16, ptr %call1, align 4\n store i16 0, ptr %call1, align 4\n store i8 0, ptr %call1, align 4\n %getelementptr84 = getelementptr i8, ptr %getelementptr57, i64 12\n store i32 0, ptr %call1, align 4\n %getelementptr85 = getelementptr i8, ptr %getelementptr57, i64 16\n store i32 0, ptr %call1, align 4\n br label %bb53\n\nbb86: ; preds = %bb86, %bb29\n %getelementptr87 = getelementptr [0 x i32], ptr %getelementptr34, i64 0, i64 0\n %load88 = load i32, ptr %call1, align 4\n %getelementptr89 = getelementptr [0 x i32], ptr %getelementptr35, i64 0, i64 0\n store i32 0, ptr %call1, align 4\n br label %bb86\n}\n\ndeclare ptr @malloc(i64)\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\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[DSE] crash", "body": "Reduced test case:\r\n[tc_dse.tar.gz](https://github.com/llvm/llvm-project/files/14499403/tc_dse.tar.gz)\r\n\r\nopt -mtriple=s390x-unknown-linux -mcpu=z16 -O3 -S ./tc_dse.ll\r\n\r\n#6 0x0000000005287456 llvm::BasicAAResult::aliasCheck\r\n#11 0x00000000048f0646 (anonymous namespace)::DSEState::isReadClobber\r\n14 0x00000000049004d8 llvm::DSEPass::run\r\nSegmentation fault (core dumped)\r\n\r\nThis is reported by user on F37 with clang-15, and is still failing on trunk.\r\n\r\n@fhahn @BK1603 @nikic ", "author": "JonPsson1", "labels": [ "release:backport", "crash-on-valid", "llvm:transforms" ], "comments": [ { "author": "nikic", "body": "llvm-reduce result for `-passes=dse`: https://gist.github.com/nikic/d52c888425c5d4ff3fbd37b4f84778b6\r\n\r\nvalgrind reports a use-after-free. Probably not invalidating EII correctly somewhere." }, { "author": "fhahn", "body": "Also reproduces with ASAn, looking now" } ] }
true
null
98610
https://github.com/llvm/llvm-project/issues/98610
hang
9ad72df55cb74b29193270c28f6974d2af8e0b71
2024-07-12T10:31:22
[ "llvm/test/Transforms/MemCpyOpt" ]
{ "fix_commit": "71051deff27928cff908ea794e09806eee662801", "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": [ [ 1296, 1301 ], [ 1312, 1318 ], [ 1726, 1733 ] ], "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::processMemCpy", "MemCpyOptPass::processMemSetMemCpyDependence" ], "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 71051deff27928cff908ea794e09806eee662801 Author: Nikita Popov <[email protected]> Date: Mon Jul 15 09:41:11 2024 +0200 [MemCpyOpt] Fix infinite loop in memset+memcpy fold (#98638) For the case where the memcpy size is zero, this transform is a complex no-op. This can lead to an infinite loop when the size is zero in a way that BasicAA understands, because it can still understand that dst and dst + src_size are MustAlias. I've tried to mitigate this before using the isZeroSize() check, but we can hit cases where InstSimplify doesn't understand that the size is zero, but BasicAA does. As such, this bites the bullet and adds an explicit isKnownNonZero() check to guard against no-op transforms. Fixes https://github.com/llvm/llvm-project/issues/98610. diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 4063762c88a2..cee34f0a6da1 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1296,6 +1296,15 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy, if (!BAA.isMustAlias(MemSet->getDest(), MemCpy->getDest())) return false; + // Don't perform the transform if src_size may be zero. In that case, the + // transform is essentially a complex no-op and may lead to an infinite + // loop if BasicAA is smart enough to understand that dst and dst + src_size + // are still MustAlias after the transform. + Value *SrcSize = MemCpy->getLength(); + if (!isKnownNonZero(SrcSize, + SimplifyQuery(MemCpy->getDataLayout(), DT, AC, MemCpy))) + return false; + // Check that src and dst of the memcpy aren't the same. While memcpy // operands cannot partially overlap, exact equality is allowed. if (isModSet(BAA.getModRefInfo(MemCpy, MemoryLocation::getForSource(MemCpy)))) @@ -1312,7 +1321,6 @@ bool MemCpyOptPass::processMemSetMemCpyDependence(MemCpyInst *MemCpy, // Use the same i8* dest as the memcpy, killing the memset dest if different. Value *Dest = MemCpy->getRawDest(); Value *DestSize = MemSet->getLength(); - Value *SrcSize = MemCpy->getLength(); if (mayBeVisibleThroughUnwinding(Dest, MemSet, MemCpy)) return false; @@ -1726,8 +1734,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) { return true; } - // If the size is zero, remove the memcpy. This also prevents infinite loops - // in processMemSetMemCpyDependence, which is a no-op for zero-length memcpys. + // If the size is zero, remove the memcpy. if (isZeroSize(M->getLength())) { ++BBI; eraseInstruction(M);
[ { "file": "llvm/test/Transforms/MemCpyOpt/memcpy-zero-size.ll", "commands": [ "opt -S -passes=memcpyopt < %s" ], "tests": [ { "test_name": "pr64886", "test_body": "; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0\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) #1\n\ndefine void @pr64886(i64 %len, ptr noalias %p) {\n call void @llvm.memset.p0.i64(ptr inttoptr (i64 -1 to ptr), i8 0, i64 %len, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr inttoptr (i64 -1 to ptr), ptr %p, i64 poison, i1 false)\n ret void\n}\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr98610", "test_body": "; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0\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) #1\n\ndefine void @pr98610(ptr %p, ptr noalias %p2) {\n call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 1, i1 false)\n %zero.ext = zext i32 0 to i64\n %mul = mul i64 %zero.ext, 1\n call void @llvm.memcpy.p0.p0.i64(ptr %p, ptr %p2, i64 %mul, i1 false)\n ret void\n}\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/MemCpyOpt/memset-memcpy-dbgloc.ll", "commands": [ "opt -passes=memcpyopt -S %s -verify-memoryssa" ], "tests": [ { "test_name": "test_constant", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\n@C = external constant [0 x i8]\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\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) #1\n\ndefine void @test_constant(i64 %src_size, ptr %dst, i64 %dst_size, i8 %c) !dbg !5 {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false), !dbg !11\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr @C, i64 %src_size, i1 false), !dbg !12\n ret void, !dbg !13\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n\n!llvm.dbg.cu = !{!0}\n!llvm.debugify = !{!2, !3}\n!llvm.module.flags = !{!4}\n\n!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: \"debugify\", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)\n!1 = !DIFile(filename: \"memset-memcpy-dbgloc.ll\", directory: \"/\")\n!2 = !{i32 3}\n!3 = !{i32 1}\n!4 = !{i32 2, !\"Debug Info Version\", i32 3}\n!5 = distinct !DISubprogram(name: \"test_constant\", linkageName: \"test_constant\", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)\n!6 = !DISubroutineType(types: !7)\n!7 = !{}\n!8 = !{!9}\n!9 = !DILocalVariable(name: \"1\", scope: !5, file: !1, line: 3, type: !10)\n!10 = !DIBasicType(name: \"ty32\", size: 32, encoding: DW_ATE_unsigned)\n!11 = !DILocation(line: 1, column: 1, scope: !5)\n!12 = !DILocation(line: 2, column: 1, scope: !5)\n!13 = !DILocation(line: 3, column: 1, scope: !5)\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/MemCpyOpt/memset-memcpy-redundant-memset.ll", "commands": [ "opt -passes=memcpyopt -S %s -verify-memoryssa" ], "tests": [ { "test_name": "test_different_types_i32_i128", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_different_types_i32_i128(ptr noalias %dst, ptr %src, i32 %dst_size, i128 %src_size, i8 %c) {\n %non.zero = icmp ne i128 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i32(ptr %dst, i8 %c, i32 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i128(ptr %dst, ptr %src, i128 %src_size, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) #0\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i128(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i128, i1 immarg) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_missing_noalias", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_missing_noalias(ptr %src, i64 %src_size, ptr %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_different_types_i128_i32", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_different_types_i128_i32(ptr noalias %dst, ptr %src, i128 %dst_size, i32 %src_size, i8 %c) {\n %non.zero = icmp ne i32 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i128(ptr %dst, i8 %c, i128 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %src_size, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg) #0\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i128(ptr nocapture writeonly, i8, i128, i1 immarg) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_align_memcpy", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_align_memcpy(ptr %src, ptr noalias %dst, i64 %dst_size) {\n call void @llvm.memset.p0.i64(ptr %dst, i8 0, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr align 8 %dst, ptr align 8 %src, i64 80, i1 false)\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\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) #1\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_different_dst", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_different_dst(ptr noalias %dst2, ptr %src, i64 %src_size, ptr noalias %dst, i64 %dst_size) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 0, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst2, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_non_i8_dst_type", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_non_i8_dst_type(ptr %src, i64 %src_size, ptr noalias %dst_pi64, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst_pi64, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst_pi64, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_different_types_i64_i32", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_different_types_i64_i32(ptr noalias %dst, ptr %src, i64 %dst_size, i32 %src_size, i8 %c) {\n %non.zero = icmp ne i32 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i32(ptr %dst, ptr %src, i32 %src_size, i1 false)\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\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_intermediate_write", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\n%struct = type { [8 x i8], [8 x i8] }\n\ndefine void @test_intermediate_write(ptr %b) {\n %a = alloca %struct, align 8\n %a1 = getelementptr %struct, ptr %a, i32 0, i32 1, i32 0\n call void @llvm.memset.p0.i64(ptr %a, i8 0, i64 16, i1 false)\n store i8 1, ptr %a1, align 1\n call void @llvm.memcpy.p0.p0.i64(ptr %a, ptr %b, i64 8, i1 false)\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\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) #1\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test(ptr %src, i64 %src_size, ptr noalias %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_same_dynamic_size", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_same_dynamic_size(ptr noalias %src, ptr noalias %dst, i64 %size, i8 %c) {\n %non.zero = icmp ne i64 %size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_weird_element_type", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_weird_element_type(ptr %src, i64 %src_size, ptr noalias %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_throwing_call", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_throwing_call(ptr %src, i64 %src_size, ptr noalias %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @call() #3\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\ndeclare void @call()\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\nattributes #3 = { memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_same_const_size", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_same_const_size(ptr noalias %src, ptr noalias %dst, i8 %c) {\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 16, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 16, i1 false)\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\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) #1\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_must_alias_different_size", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_must_alias_different_size(ptr noalias %src, i64 %src_size, ptr noalias %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n %gep1 = getelementptr i8, ptr %dst, i64 16\n call void @llvm.memset.p0.i64(ptr %gep1, i8 %c, i64 %dst_size, i1 false)\n %gep2 = getelementptr i8, ptr %dst, i64 16\n call void @llvm.memcpy.p0.p0.i64(ptr %gep2, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_throwing_call_alloca", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_throwing_call_alloca(ptr %src, i64 %src_size, i64 %dst_size, i8 %c) {\n %dst = alloca i8, align 1\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @call() #3\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\ndeclare void @call()\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\nattributes #3 = { memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_addrspace", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_addrspace(ptr addrspace(1) %src, i64 %src_size, ptr addrspace(1) noalias %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p1.i64(ptr addrspace(1) %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) %dst, ptr addrspace(1) %src, i64 %src_size, i1 false)\n ret void\n}\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p1.i64(ptr addrspace(1) nocapture writeonly, i8, i64, i1 immarg) #0\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memcpy.p1.p1.i64(ptr addrspace(1) noalias nocapture writeonly, ptr addrspace(1) noalias nocapture readonly, i64, i1 immarg) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_constant", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\n@C = external constant [0 x i8]\n\ndefine void @test_constant(i64 %src_size, ptr %dst, i64 %dst_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr @C, i64 %src_size, i1 false)\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\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) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_different_types_i32_i64", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_different_types_i32_i64(ptr noalias %dst, ptr %src, i32 %dst_size, i64 %src_size, i8 %c) {\n %non.zero = icmp ne i64 %src_size, 0\n call void @llvm.assume(i1 %non.zero)\n call void @llvm.memset.p0.i32(ptr %dst, i8 %c, i32 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, 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\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg) #1\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #2\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #2 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_must_alias_same_size", "test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @test_must_alias_same_size(ptr noalias %src, ptr noalias %dst, i8 %c) {\n %gep1 = getelementptr i8, ptr %dst, i64 16\n call void @llvm.memset.p0.i64(ptr %gep1, i8 %c, i64 16, i1 false)\n %gep2 = getelementptr i8, ptr %dst, i64 16\n call void @llvm.memcpy.p0.p0.i64(ptr %gep2, ptr %src, i64 16, i1 false)\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\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) #1\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/MemCpyOpt/opaque-ptr.ll", "commands": [ "opt -passes=memcpyopt -S %s -verify-memoryssa" ], "tests": [ { "test_name": "test_memset_memcpy", "test_body": "define void @test_memset_memcpy(ptr %src, i64 range(i64 1, 42) %src_size, ptr noalias %dst, i64 %dst_size, i8 %c) {\n call void @llvm.memset.p0.i64(ptr %dst, i8 %c, i64 %dst_size, i1 false)\n call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 %src_size, i1 false)\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\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) #1\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\nattributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Clang hangs forever building under -O1", "body": "ToT Clang hangs when building under -O1.\r\n\r\n```\r\nclang++ test.i -fno-exceptions -O1 -c -emit-llvm\r\n```\r\n\r\nThe reproducer, `test.i`:\r\n\r\n```c++\r\nclass MockDevice;\r\nstruct sp {\r\n MockDevice operator*();\r\n};\r\nvoid memset(void *__dest, int __ch, unsigned __len) {\r\n long __trans_tmp_1 = __builtin_object_size(__dest, 0);\r\n __builtin___memset_chk(__dest, __ch, __len, __trans_tmp_1);\r\n}\r\ntemplate <class>\r\nclass function;\r\ntemplate <class _Rp, class... _ArgTypes>\r\nclass function<_Rp(_ArgTypes...)> {\r\n public:\r\n template <class _Fp>\r\n function operator=(_Fp);\r\n};\r\ntemplate <typename T>\r\nstruct hidl_vec {\r\n hidl_vec() : mSize() { memset(mPad, 0, 0); }\r\n hidl_vec(hidl_vec &other) { *this = other; }\r\n hidl_vec &operator=(hidl_vec &other) {\r\n copyFrom(other, other.mSize);\r\n return *this;\r\n }\r\n T &operator[](unsigned index) { return mBuffer[index]; }\r\n T* mBuffer;\r\n unsigned mSize;\r\n unsigned mPad[];\r\n template <typename Array>\r\n void copyFrom(Array &data, unsigned size) {\r\n mSize = size;\r\n if (mSize) mBuffer = new T();\r\n for (int i = 0; i < size; ++i) mBuffer[i] = data[i];\r\n }\r\n};\r\nstruct Capabilities {\r\n struct OperandPerformance {\r\n int a, b, c;\r\n };\r\n hidl_vec<OperandPerformance> operandPerformance;\r\n};\r\ntemplate <typename>\r\nclass Action;\r\ntemplate <typename R, typename... Args>\r\nclass Action<R(Args...)> {\r\n using F = R();\r\n public:\r\n template <typename G>\r\n Action(G fun) {\r\n fun_ = fun;\r\n }\r\n function<F> fun_;\r\n};\r\nstruct OnCallSpec {\r\n OnCallSpec WillByDefault(Action<void()>);\r\n};\r\nstruct MockSpec {\r\n OnCallSpec InternalDefaultActionSetAt();\r\n};\r\nstruct MockDevice {\r\n MockSpec gmock_getCapabilities();\r\n};\r\nsp createMockDevice_mockDevice;\r\nMockDevice createMockDevice() {\r\n Capabilities getCapabilities_ret;\r\n (*createMockDevice_mockDevice)\r\n .gmock_getCapabilities()\r\n .InternalDefaultActionSetAt()\r\n .WillByDefault(getCapabilities_ret);\r\n return *createMockDevice_mockDevice;\r\n}\r\n```", "author": "kongy", "labels": [ "confirmed", "llvm:hang", "llvm:transforms" ], "comments": [ { "author": "AaronBallman", "body": "This seems to be hanging somewhere in this vicinity:\r\n```\r\n>\tclang.exe!llvm::detail::CheckedInt::from<int,0>(int FromValue) Line 136\tC++\r\n \tclang.exe!llvm::detail::CheckedInt::from<enum llvm::IRMemLocation,0>(llvm::IRMemLocation FromValue) Line 143\tC++\r\n \tclang.exe!llvm::detail::SafeIntIterator<enum llvm::IRMemLocation,0>::SafeIntIterator<enum llvm::IRMemLocation,0>(llvm::IRMemLocation Value) Line 196\tC++\r\n \tclang.exe!llvm::iota_range<enum llvm::IRMemLocation>::iota_range<enum llvm::IRMemLocation>(llvm::IRMemLocation Begin, llvm::IRMemLocation End, bool Inclusive) Line 275\tC++\r\n \tclang.exe!llvm::enum_seq_inclusive<enum llvm::IRMemLocation,void>(llvm::IRMemLocation Begin, llvm::IRMemLocation End, llvm::force_iteration_on_noniterable_enum_t __formal) Line 381\tC++\r\n \tclang.exe!llvm::MemoryEffectsBase<enum llvm::IRMemLocation>::locations() Line 96\tC++\r\n \tclang.exe!llvm::MemoryEffectsBase<enum llvm::IRMemLocation>::MemoryEffectsBase<enum llvm::IRMemLocation>(llvm::ModRefInfo MR) Line 107\tC++\r\n \tclang.exe!llvm::MemoryEffectsBase<enum llvm::IRMemLocation>::unknown() Line 113\tC++\r\n \tclang.exe!llvm::GlobalsAAResult::getMemoryEffects(const llvm::Function * F) Line 244\tC++\r\n \tclang.exe!llvm::AAResults::Model<llvm::GlobalsAAResult>::getMemoryEffects(const llvm::Function * F) Line 784\tC++\r\n \tclang.exe!llvm::AAResults::getMemoryEffects(const llvm::Function * F) Line 396\tC++\r\n \tclang.exe!llvm::BasicAAResult::getMemoryEffects(const llvm::CallBase * Call, llvm::AAQueryInfo & AAQI) Line 830\tC++\r\n \tclang.exe!llvm::AAResults::Model<llvm::BasicAAResult>::getMemoryEffects(const llvm::CallBase * Call, llvm::AAQueryInfo & AAQI) Line 780\tC++\r\n \tclang.exe!llvm::AAResults::getMemoryEffects(const llvm::CallBase * Call, llvm::AAQueryInfo & AAQI) Line 377\tC++\r\n \tclang.exe!llvm::AAResults::getModRefInfo(const llvm::CallBase * Call, const llvm::MemoryLocation & Loc, llvm::AAQueryInfo & AAQI) Line 230\tC++\r\n \tclang.exe!llvm::AAResults::getModRefInfo(const llvm::Instruction * I, const std::optional<llvm::MemoryLocation> & OptLoc, llvm::AAQueryInfo & AAQIP) Line 628\tC++\r\n \tclang.exe!llvm::BatchAAResults::getModRefInfo(const llvm::Instruction * I, const std::optional<llvm::MemoryLocation> & OptLoc) Line 646\tC++\r\n \tclang.exe!llvm::MemCpyOptPass::processMemSetMemCpyDependence(llvm::MemCpyInst * MemCpy, llvm::MemSetInst * MemSet, llvm::BatchAAResults & BAA) Line 1252\tC++\r\n \tclang.exe!llvm::MemCpyOptPass::processMemCpy(llvm::MemCpyInst * M, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction,1,0,void,1,llvm::BasicBlock>,0,0> & BBI) Line 1725\tC++\r\n \tclang.exe!llvm::MemCpyOptPass::iterateOnFunction(llvm::Function & F) Line 2013\tC++\r\n \tclang.exe!llvm::MemCpyOptPass::runImpl(llvm::Function & F, llvm::TargetLibraryInfo * TLI_, llvm::AAResults * AA_, llvm::AssumptionCache * AC_, llvm::DominatorTree * DT_, llvm::PostDominatorTree * PDT_, llvm::MemorySSA * MSSA_) Line 2070\tC++\r\n \tclang.exe!llvm::MemCpyOptPass::run(llvm::Function & F, llvm::AnalysisManager<llvm::Function> & AM) Line 2045\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::Function,llvm::MemCpyOptPass,llvm::AnalysisManager<llvm::Function>>::run(llvm::Function & IR, llvm::AnalysisManager<llvm::Function> & AM) Line 90\tC++\r\n \tclang.exe!llvm::PassManager<llvm::Function,llvm::AnalysisManager<llvm::Function>>::run(llvm::Function & IR, llvm::AnalysisManager<llvm::Function> & AM) Line 85\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::Function,llvm::PassManager<llvm::Function,llvm::AnalysisManager<llvm::Function>>,llvm::AnalysisManager<llvm::Function>>::run(llvm::Function & IR, llvm::AnalysisManager<llvm::Function> & AM) Line 90\tC++\r\n \tclang.exe!llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC & C, llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &> & AM, llvm::LazyCallGraph & CG, llvm::CGSCCUpdateResult & UR) Line 543\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::LazyCallGraph::SCC,llvm::CGSCCToFunctionPassAdaptor,llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &>,llvm::LazyCallGraph &,llvm::CGSCCUpdateResult &>::run(llvm::LazyCallGraph::SCC & IR, llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &> & AM, llvm::LazyCallGraph & <ExtraArgs_0>, llvm::CGSCCUpdateResult & <ExtraArgs_1>) Line 90\tC++\r\n \tclang.exe!llvm::PassManager<llvm::LazyCallGraph::SCC,llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &>,llvm::LazyCallGraph &,llvm::CGSCCUpdateResult &>::run(llvm::LazyCallGraph::SCC & InitialC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &> & AM, llvm::LazyCallGraph & G, llvm::CGSCCUpdateResult & UR) Line 90\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::LazyCallGraph::SCC,llvm::PassManager<llvm::LazyCallGraph::SCC,llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &>,llvm::LazyCallGraph &,llvm::CGSCCUpdateResult &>,llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &>,llvm::LazyCallGraph &,llvm::CGSCCUpdateResult &>::run(llvm::LazyCallGraph::SCC & IR, llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &> & AM, llvm::LazyCallGraph & <ExtraArgs_0>, llvm::CGSCCUpdateResult & <ExtraArgs_1>) Line 90\tC++\r\n \tclang.exe!llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC & InitialC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &> & AM, llvm::LazyCallGraph & CG, llvm::CGSCCUpdateResult & UR) Line 415\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::LazyCallGraph::SCC,llvm::DevirtSCCRepeatedPass,llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &>,llvm::LazyCallGraph &,llvm::CGSCCUpdateResult &>::run(llvm::LazyCallGraph::SCC & IR, llvm::AnalysisManager<llvm::LazyCallGraph::SCC,llvm::LazyCallGraph &> & AM, llvm::LazyCallGraph & <ExtraArgs_0>, llvm::CGSCCUpdateResult & <ExtraArgs_1>) Line 90\tC++\r\n \tclang.exe!llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module & M, llvm::AnalysisManager<llvm::Module> & AM) Line 277\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::Module,llvm::ModuleToPostOrderCGSCCPassAdaptor,llvm::AnalysisManager<llvm::Module>>::run(llvm::Module & IR, llvm::AnalysisManager<llvm::Module> & AM) Line 90\tC++\r\n \tclang.exe!llvm::PassManager<llvm::Module,llvm::AnalysisManager<llvm::Module>>::run(llvm::Module & IR, llvm::AnalysisManager<llvm::Module> & AM) Line 85\tC++\r\n \tclang.exe!llvm::ModuleInlinerWrapperPass::run(llvm::Module & M, llvm::AnalysisManager<llvm::Module> & MAM) Line 631\tC++\r\n \tclang.exe!llvm::detail::PassModel<llvm::Module,llvm::ModuleInlinerWrapperPass,llvm::AnalysisManager<llvm::Module>>::run(llvm::Module & IR, llvm::AnalysisManager<llvm::Module> & AM) Line 90\tC++\r\n \tclang.exe!llvm::PassManager<llvm::Module,llvm::AnalysisManager<llvm::Module>>::run(llvm::Module & IR, llvm::AnalysisManager<llvm::Module> & AM) Line 85\tC++\r\n \tclang.exe!`anonymous namespace'::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction Action, std::unique_ptr<llvm::raw_pwrite_stream,std::default_delete<llvm::raw_pwrite_stream>> & OS, std::unique_ptr<llvm::ToolOutputFile,std::default_delete<llvm::ToolOutputFile>> & ThinLinkOS, clang::BackendConsumer * BC) Line 1114\tC++\r\n \tclang.exe!`anonymous namespace'::EmitAssemblyHelper::EmitAssembly(clang::BackendAction Action, std::unique_ptr<llvm::raw_pwrite_stream,std::default_delete<llvm::raw_pwrite_stream>> OS, clang::BackendConsumer * BC) Line 1180\tC++\r\n \tclang.exe!clang::EmitBackendOutput(clang::DiagnosticsEngine & Diags, const clang::HeaderSearchOptions & HeaderOpts, const clang::CodeGenOptions & CGOpts, const clang::TargetOptions & TOpts, const clang::LangOptions & LOpts, llvm::StringRef TDesc, llvm::Module * M, clang::BackendAction Action, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, std::unique_ptr<llvm::raw_pwrite_stream,std::default_delete<llvm::raw_pwrite_stream>> OS, clang::BackendConsumer * BC) Line 1341\tC++\r\n \tclang.exe!clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext & C) Line 354\tC++\r\n \tclang.exe!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 183\tC++\r\n \tclang.exe!clang::ASTFrontendAction::ExecuteAction() Line 1192\tC++\r\n \tclang.exe!clang::CodeGenAction::ExecuteAction() Line 1144\tC++\r\n \tclang.exe!clang::FrontendAction::Execute() Line 1078\tC++\r\n \tclang.exe!clang::CompilerInstance::ExecuteAction(clang::FrontendAction & Act) Line 1061\tC++\r\n \tclang.exe!clang::ExecuteCompilerInvocation(clang::CompilerInstance * Clang) Line 280\tC++\r\n \tclang.exe!cc1_main(llvm::ArrayRef<char const *> Argv, const char * Argv0, void * MainAddr) Line 283\tC++\r\n \tclang.exe!ExecuteCC1Tool(llvm::SmallVectorImpl<char const *> & ArgV, const llvm::ToolContext & ToolContext) Line 215\tC++\r\n \tclang.exe!clang_main(int Argc, char * * Argv, const llvm::ToolContext & ToolContext) Line 256\tC++\r\n \tclang.exe!main(int argc, char * * argv) Line 17\tC++\r\n \tclang.exe!invoke_main() Line 79\tC++\r\n \tclang.exe!__scrt_common_main_seh() Line 288\tC++\r\n \tclang.exe!__scrt_common_main() Line 331\tC++\r\n \tclang.exe!mainCRTStartup(void * __formal) Line 17\tC++\r\n \tkernel32.dll!00007ff830e07344()\tUnknown\r\n \tntdll.dll!00007ff83149cc91()\tUnknown\r\n```" }, { "author": "nikic", "body": "Reduced:\r\n```llvm\r\n; RUN: opt -S -passes=memcpyopt < %s\r\ndefine void @test(ptr %p, ptr noalias %p2) {\r\n call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 1, i1 false)\r\n %zero.ext = zext i32 0 to i64\r\n %mul = mul i64 %zero.ext, 1\r\n call void @llvm.memcpy.p0.p0.i64(ptr %p, ptr %p2, i64 %mul, i1 false)\r\n ret void\r\n}\r\n```" }, { "author": "nikic", "body": "This is an infinite loop in the processMemSetMemCpyDependence() transform. I've tried to mitigate this in the past, but it looks like the mitigation doesn't work for this case. I guess we'll have to add an isKnownNonZero() check to prevent it." } ] }
true
null
119002
https://github.com/llvm/llvm-project/issues/119002
crash
6797b0f0c002c9f3dda7a2b502ddf33e2c8f6777
2024-12-06T17:29:17
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "376dad72abb4960cd93e37e3e98de3950b5c3dfe", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 16215, 16220 ] ], "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 376dad72abb4960cd93e37e3e98de3950b5c3dfe Author: Alexey Bataev <[email protected]> Date: Fri Dec 6 13:39:05 2024 -0800 [SLP]Move resulting vector before inert point, if the late generated buildvector fully matched If the perfect diamond match was detected for the postponed buildvectors and the vector for the previous node comes after the current node, need to move the vector register before the current inserting point to prevent compiler crash. Fixes #119002 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 51841a842ce0..50590e51ae0e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -16215,6 +16215,11 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, } Builder.SetCurrentDebugLocation(UserI->getDebugLoc()); Value *Vec = vectorizeTree(TE, /*PostponedPHIs=*/false); + if (auto *VecI = dyn_cast<Instruction>(Vec); + VecI && VecI->getParent() == Builder.GetInsertBlock() && + Builder.GetInsertPoint()->comesBefore(VecI)) + VecI->moveBeforePreserving(*Builder.GetInsertBlock(), + Builder.GetInsertPoint()); if (Vec->getType() != PrevVec->getType()) { assert(Vec->getType()->isIntOrIntVectorTy() && PrevVec->getType()->isIntOrIntVectorTy() &&
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/perfect-matched-reused-bv.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n %phi = phi i32 [ 0, %bb ], [ %add6, %bb4 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb4 ]\n %or = or i32 %phi2, 0\n %or3 = or i32 %phi, 0\n br i1 false, label %bb7, label %bb4\n\nbb4: ; preds = %bb1\n %add = add i32 0, 0\n %add5 = add i32 0, 0\n %add6 = add i32 %phi, 0\n br i1 false, label %bb7, label %bb1\n\nbb7: ; preds = %bb4, %bb1\n %phi8 = phi i32 [ %or, %bb1 ], [ %add5, %bb4 ]\n %phi9 = phi i32 [ %or3, %bb1 ], [ %add6, %bb4 ]\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted! (yet another)", "body": "To reproduce run the test below with -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 void @wombat() #0 gc \"statepoint-example\" {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb4, %bb\n %phi = phi i32 [ 0, %bb ], [ %add6, %bb4 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb4 ]\n %or = or i32 %phi2, 0\n %or3 = or i32 %phi, 0\n br i1 false, label %bb7, label %bb4\n\nbb4: ; preds = %bb1\n %add = add i32 0, 0\n %add5 = add i32 0, 0\n %add6 = add i32 %phi, 0\n br i1 false, label %bb7, label %bb1\n\nbb7: ; preds = %bb4, %bb1\n %phi8 = phi i32 [ %or, %bb1 ], [ %add5, %bb4 ]\n %phi9 = phi i32 [ %or3, %bb1 ], [ %add6, %bb4 ]\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-amx-fp8,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,-movrs,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,-amx-tf32,-amx-avx512,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-amx-transpose,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-amx-movrs,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\n```\nReproducer: https://godbolt.org/z/Kqddzds1c\n\nStack dump:\n```\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer <source>\n1.\tRunning pass \"verify\" on module \"<source>\"\n #0 0x00000000051b4a48 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b4a48)\n #1 0x00000000051b243c SignalHandler(int) Signals.cpp:0:0\n #2 0x00007c6fb5442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007c6fb54969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007c6fb5442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007c6fb54287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00000000007e2469 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\n #7 0x00000000050f32d8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50f32d8)\n #8 0x0000000004ff2498 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ff2498)\n #9 0x00000000009057ae 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+0x9057ae)\n#10 0x0000000004fb1d10 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb1d10)\n#11 0x0000000000910d7a 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+0x910d7a)\n#12 0x00000000009033f9 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9033f9)\n#13 0x00007c6fb5429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#14 0x00007c6fb5429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#15 0x00000000008facde _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8facde)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
112666
https://github.com/llvm/llvm-project/issues/112666
miscompilation
d6d73ec89e493c69cf24dc3a710d861e2ce08acb
2024-10-17T06:28:53
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "ff07df6620c32571c7e13ff96ec7976c63ed0ab8", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 333, 338 ] ], "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": 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": 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 ff07df6620c32571c7e13ff96ec7976c63ed0ab8 Author: Yingwei Zheng <[email protected]> Date: Fri Nov 8 16:20:04 2024 +0800 [InstCombine] Drop nsw in negation of select (#112893) Closes https://github.com/llvm/llvm-project/issues/112666 and https://github.com/llvm/llvm-project/issues/114181. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp index 9bd848552615..2210336d92bf 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp @@ -333,6 +333,17 @@ std::array<Value *, 2> Negator::getSortedOperandsOfBinOp(Instruction *I) { NewSelect->swapValues(); // Don't swap prof metadata, we didn't change the branch behavior. NewSelect->setName(I->getName() + ".neg"); + // Poison-generating flags should be dropped + Value *TV = NewSelect->getTrueValue(); + Value *FV = NewSelect->getFalseValue(); + if (match(TV, m_Neg(m_Specific(FV)))) + cast<Instruction>(TV)->dropPoisonGeneratingFlags(); + else if (match(FV, m_Neg(m_Specific(TV)))) + cast<Instruction>(FV)->dropPoisonGeneratingFlags(); + else { + cast<Instruction>(TV)->dropPoisonGeneratingFlags(); + cast<Instruction>(FV)->dropPoisonGeneratingFlags(); + } Builder.Insert(NewSelect); return NewSelect; }
[ { "file": "llvm/test/Transforms/InstCombine/sub-of-negatible.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "negate_select_of_op_vs_negated_op_nsw_commuted", "test_body": "define i8 @negate_select_of_op_vs_negated_op_nsw_commuted(i8 %x, i8 %y, i1 %c) {\n %t0 = sub nsw i8 0, %x\n %t1 = select i1 %c, i8 %x, i8 %t0\n %t2 = sub i8 %y, %t1\n ret i8 %t2\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "negate_select_of_op_vs_negated_op_nsw", "test_body": "define i8 @negate_select_of_op_vs_negated_op_nsw(i8 %x, i8 %y, i1 %c) {\n %t0 = sub nsw i8 0, %x\n %t1 = select i1 %c, i8 %t0, i8 %x\n %t2 = sub i8 %y, %t1\n ret i8 %t2\n}\n", "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 }, { "test_name": "negate_select_of_op_vs_negated_op_nsw_xyyx", "test_body": "define i8 @negate_select_of_op_vs_negated_op_nsw_xyyx(i8 %x, i8 %y, i8 %z, i1 %c) {\n %sub1 = sub nsw i8 %x, %y\n %sub2 = sub nsw i8 %y, %x\n %t1 = select i1 %c, i8 %sub1, i8 %sub2\n %t2 = sub i8 %z, %t1\n ret i8 %t2\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "negate_select_of_op_vs_negated_op", "test_body": "declare void @use8(i8)\n\ndefine i8 @negate_select_of_op_vs_negated_op(i8 %x, i8 %y, i1 %c) {\n %t0 = sub i8 0, %x\n call void @use8(i8 %t0)\n %t1 = select i1 %c, i8 %t0, i8 %x, !prof !0\n %t2 = sub i8 %y, %t1\n ret i8 %t2\n}\n\n!0 = !{!\"branch_weights\", i32 40, i32 1}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `nsw` flag should be dropped in Negator", "body": "Reproducer: https://alive2.llvm.org/ce/z/ZFF_QK\r\n```\r\ndefine i8 @src(i8 %x, i8 %y, i1 %c) {\r\n %t0 = sub nsw i8 0, %x\r\n %t1 = select i1 %c, i8 %t0, i8 %x\r\n %t2 = sub i8 %y, %t1\r\n ret i8 %t2\r\n}\r\n\r\ndefine i8 @tgt(i8 %x, i8 %y, i1 %c) {\r\n %t0 = sub nsw i8 0, %x\r\n %1 = select i1 %c, i8 %x, i8 %t0\r\n %t2 = add i8 %1, %y\r\n ret i8 %t2\r\n}\r\n```\r\n```\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni8 %x = #x80 (128, -128)\r\ni8 %y = #x00 (0)\r\ni1 %c = #x0 (0)\r\n\r\nSource:\r\ni8 %t0 = poison\r\ni8 %t1 = #x80 (128, -128)\r\ni8 %t2 = #x80 (128, -128)\r\n\r\nTarget:\r\ni8 %t0 = poison\r\ni8 %#1 = poison\r\ni8 %t2 = poison\r\nSource value: #x80 (128, -128)\r\nTarget value: poison\r\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "AZero13", "body": "Is this an issue in 19.x or just main?" }, { "author": "AZero13", "body": "Confirmed this issue exists in 19.x" } ] }
true
null
104714
https://github.com/llvm/llvm-project/issues/104714
crash
a2d8743cc86f96f6b1cbd85798328bd3fb2bf4de
2024-08-18T15:54:27
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "cb4efe1d078144a72306732a56afea3885650e8d", "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": [ [ 7237, 7242 ], [ 7292, 7298 ] ], "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::computeBestVF", "LoopVectorizationPlanner::cost" ], "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 cb4efe1d078144a72306732a56afea3885650e8d Author: Florian Hahn <[email protected]> Date: Thu Aug 22 21:38:06 2024 +0100 [VPlan] Don't trigger VF assertion if VPlan has extra simplifications. There are cases where VPlans contain some simplifications that are very hard to accurately account for up-front in the legacy cost model. Those cases are caused by un-simplified inputs, which trigger the assert ensuring both the legacy and VPlan-based cost model agree on the VF. To avoid false positives due to missed simplifications in general, only trigger the assert if the chosen VPlan doesn't contain any additional simplifications. Fixes https://github.com/llvm/llvm-project/issues/104714. Fixes https://github.com/llvm/llvm-project/issues/105713. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 8e9324ba718b..32e8f3312578 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7237,6 +7237,56 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, return Cost; } +/// Return true if the original loop \ TheLoop contains any instructions that do +/// not have corresponding recipes in \p Plan and are not marked to be ignored +/// in \p CostCtx. This means the VPlan contains simplification that the legacy +/// cost-model did not account for. +static bool +planContainsAdditionalSimplifications(VPlan &Plan, ElementCount VF, + VPCostContext &CostCtx, Loop *TheLoop, + LoopVectorizationCostModel &CM) { + // First collect all instructions for the recipes in Plan. + auto GetInstructionForCost = [](const VPRecipeBase *R) -> Instruction * { + if (auto *S = dyn_cast<VPSingleDefRecipe>(R)) + return dyn_cast_or_null<Instruction>(S->getUnderlyingValue()); + if (auto *WidenMem = dyn_cast<VPWidenMemoryRecipe>(R)) + return &WidenMem->getIngredient(); + return nullptr; + }; + + DenseSet<Instruction *> SeenInstrs; + auto Iter = vp_depth_first_deep(Plan.getEntry()); + for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(Iter)) { + for (VPRecipeBase &R : *VPBB) { + if (auto *IR = dyn_cast<VPInterleaveRecipe>(&R)) { + auto *IG = IR->getInterleaveGroup(); + unsigned NumMembers = IG->getNumMembers(); + for (unsigned I = 0; I != NumMembers; ++I) { + if (Instruction *M = IG->getMember(I)) + SeenInstrs.insert(M); + } + continue; + } + if (Instruction *UI = GetInstructionForCost(&R)) + SeenInstrs.insert(UI); + } + } + + // Return true if the loop contains any instructions that are not also part of + // the VPlan or are skipped for VPlan-based cost computations. This indicates + // that the VPlan contains extra simplifications. + return any_of( + TheLoop->blocks(), [&SeenInstrs, VF, &CostCtx, &CM](BasicBlock *BB) { + return any_of(*BB, [&SeenInstrs, VF, &CostCtx, &CM](Instruction &I) { + if (isa<PHINode>(&I)) + return false; + return !SeenInstrs.contains(&I) && + !CostCtx.skipCostComputation(&I, true) && + !CM.canTruncateToMinimalBitwidth(&I, VF); + }); + }); +} + VectorizationFactor LoopVectorizationPlanner::computeBestVF() { if (VPlans.empty()) return VectorizationFactor::Disabled(); @@ -7292,7 +7342,20 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() { // cost-model and will be retired once the VPlan-based cost-model is // stabilized. VectorizationFactor LegacyVF = selectVectorizationFactor(); - assert(BestFactor.Width == LegacyVF.Width && + VPlan &BestPlan = getPlanFor(BestFactor.Width); + + // Pre-compute the cost and use it to check if BestPlan contains any + // simplifications not accounted for in the legacy cost model. If that's the + // case, don't trigger the assertion, as the extra simplifications may cause a + // different VF to be picked by the VPlan-based cost model. + LLVMContext &LLVMCtx = OrigLoop->getHeader()->getContext(); + VPCostContext CostCtx(CM.TTI, *CM.TLI, Legal->getWidestInductionType(), + LLVMCtx, CM); + precomputeCosts(BestPlan, BestFactor.Width, CostCtx); + assert((BestFactor.Width == LegacyVF.Width || + planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), + BestFactor.Width, CostCtx, + OrigLoop, CM)) && " VPlan cost model and legacy cost model disagreed"); assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) && "when vectorizing, the scalar cost must be computed.");
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/blocks-with-dead-instructions.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "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": "dead_load_in_block", "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 @dead_load_in_block(ptr %dst, ptr %src, i8 %N, i64 %x) #0 {\nentry:\n %N.ext = zext i8 %N to i64\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %l.0 = load i32, ptr %src, align 4\n %c.0 = icmp eq i32 %l.0, 0\n br i1 %c.0, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %gep.src.x = getelementptr i32, ptr %src, i64 %x\n %l.dead = load i32, ptr %gep.src.x, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %gep.dst = getelementptr i32, ptr %dst, i64 %iv\n store i32 0, ptr %gep.dst, align 4\n %iv.next = add i64 %iv, 3\n %cmp = icmp ult i64 %iv, %N.ext\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\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_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": "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 }, { "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": "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": "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 } ] } ]
{ "title": "[VPlan] Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using d082f1f37d8cb7a0c6875537ba873a631b154d53\r\n\r\nC Testcase:\r\n```c\r\nint a;\r\nextern int b[];\r\nsigned char c;\r\nint d[1];\r\nvoid e() {\r\n for (short f = 2; f < c; f += 3) {\r\n a = ({ d[f - 1]; }) ? d[f] : 0;\r\n b[f] = 0;\r\n }\r\n}\r\n```\r\nCommand:\r\n```\r\n/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -march=rv64gcv_zvl256b -O3 red.c -o /dev/null\r\n```\r\n\r\nTestcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @e(i8 %0, i64 %indvars.iv) #0 {\r\nentry:\r\n %1 = zext i8 %0 to i64\r\n br label %for.body\r\n\r\nfor.cond.for.cond.cleanup_crit_edge: ; preds = %cond.end\r\n ret void\r\n\r\nfor.body: ; preds = %cond.end, %entry\r\n %indvars.iv1 = phi i64 [ 0, %entry ], [ %indvars.iv.next, %cond.end ]\r\n %sub = add i64 0, 0\r\n %arrayidx = getelementptr [1 x i32], ptr null, i64 0, i64 %sub\r\n %2 = load i32, ptr %arrayidx, align 4\r\n %tobool.not = icmp eq i32 %2, 0\r\n br i1 %tobool.not, label %cond.end, label %cond.true\r\n\r\ncond.true: ; preds = %for.body\r\n %arrayidx5 = getelementptr [1 x i32], ptr null, i64 0, i64 %indvars.iv\r\n %3 = load i32, ptr %arrayidx5, align 4\r\n br label %cond.end\r\n\r\ncond.end: ; preds = %cond.true, %for.body\r\n %arrayidx7 = getelementptr [0 x i32], ptr null, i64 0, i64 %indvars.iv1\r\n store i32 0, ptr %arrayidx7, align 4\r\n %indvars.iv.next = add i64 %indvars.iv1, 3\r\n %cmp = icmp ult i64 %indvars.iv1, %1\r\n br i1 %cmp, label %for.body, label %for.cond.for.cond.cleanup_crit_edge\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+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,-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:10037: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"e\"\r\n #0 0x000063e889a673c0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ff63c0)\r\n #1 0x000063e889a647df llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ff37df)\r\n #2 0x000063e889a64935 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007a5322242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007a53222969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007a53222969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007a53222969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007a5322242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007a53222287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007a532222871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007a5322239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000063e888a5ba9a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1feaa9a)\r\n#12 0x000063e888a5df51 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fecf51)\r\n#13 0x000063e888a5e5c7 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fed5c7)\r\n#14 0x000063e8878c6096 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+0xe55096)\r\n#15 0x000063e88987deef 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+0x2e0ceef)\r\n#16 0x000063e8878c91d6 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+0xe581d6)\r\n#17 0x000063e88987cc6b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e0bc6b)\r\n#18 0x000063e8878c54c6 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+0xe544c6)\r\n#19 0x000063e88987accd 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+0x2e09ccd)\r\n#20 0x000063e8870f3eb6 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+0x682eb6)\r\n#21 0x000063e8870e5c41 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x674c41)\r\n#22 0x00007a5322229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x00007a5322229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x00007a5322229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x000063e8870dbff5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66aff5)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nGodbolt: https://godbolt.org/z/v1nbzWqMb\r\n\r\nFound via fuzzer.\r\n\r\ncc @fhahn ", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "patrick-rivos", "body": "Linking some meta-discussion about the assert here: https://github.com/llvm/llvm-project/issues/100591" }, { "author": "zhendongsu", "body": "Some additional reproducers on x86_64-linux-gnu in case they are of help:\r\n\r\n```\r\n[519] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 410f751144e8b2e9574f03e0d0fb8560fe3cb797)\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 -Os small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7288: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `BestFactor.Width == LegacyVF.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, 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/WAIT/20240822-clangtk-m64-Os-Wall-Wextra-pipe-fPIC-build-182745/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/WAIT/20240822-clangtk-m64-Os-Wall-Wextra-pipe-fPIC-build-182745/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 -Os -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-e51115.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-use-loop-info;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x00005559685ec3ef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x42ea3ef)\r\n #1 0x00005559685e9934 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f0380f76420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f03809ad00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f038098c859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f038098c729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f038098c729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f038099dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000555969ef4948 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5bf2948)\r\n #9 0x0000555969f0f9ea llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c0d9ea)\r\n#10 0x0000555969f12691 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c10691)\r\n#11 0x0000555969f12d43 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c10d43)\r\n#12 0x0000555969a9d326 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+0x579b326)\r\n#13 0x0000555967f872a1 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+0x3c852a1)\r\n#14 0x0000555965ae2ae6 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+0x17e0ae6)\r\n#15 0x0000555967f85bed llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3c83bed)\r\n#16 0x0000555965ae19e6 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+0x17df9e6)\r\n#17 0x0000555967f83cf1 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+0x3c81cf1)\r\n#18 0x00005559688a0c29 (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 0x00005559688a3d83 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+0x45a1d83)\r\n#20 0x0000555968f440fa clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c420fa)\r\n#21 0x000055596ad8938c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6a8738c)\r\n#22 0x0000555968f44598 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c42598)\r\n#23 0x00005559691dec59 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4edcc59)\r\n#24 0x00005559691603be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4e5e3be)\r\n#25 0x00005559692cb886 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4fc9886)\r\n#26 0x00005559656b5dd5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b3dd5)\r\n#27 0x00005559656aee7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x00005559656b284e clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b084e)\r\n#29 0x00005559655a31bb main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x12a11bb)\r\n#30 0x00007f038098e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x00005559656ae90e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13ac90e)\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 410f751144e8b2e9574f03e0d0fb8560fe3cb797)\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-1b0f28.c\r\nclangtk: note: diagnostic msg: /tmp/small-1b0f28.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[521] % \r\n[521] % cat small.c\r\nchar a;\r\nint b, *c = &b, d[3], e;\r\nint main() {\r\n int f, g[3] = {0,0,0};\r\n g[e] = *c = 0;\r\n for (; *c < 3; (*c)++) {\r\n f = a ? b % a : 0;\r\n g[2] &= d[*c] & f;\r\n }\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\n[537] % clangtk -O3 small.c\r\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7288: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `BestFactor.Width == LegacyVF.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, 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/WAIT/20240814-clangtk-m64-O3-build-085604/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/WAIT/20240814-clangtk-m64-O3-build-085604/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 -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-83d1cf.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,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 \"small.c\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x0000558427a123ef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x42ea3ef)\r\n #1 0x0000558427a0f934 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fa32f70a420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007fa32f14100b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007fa32f120859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007fa32f120729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007fa32f120729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007fa32f131fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x000055842931a948 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5bf2948)\r\n #9 0x00005584293359ea llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c0d9ea)\r\n#10 0x0000558429338691 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c10691)\r\n#11 0x0000558429338d43 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c10d43)\r\n#12 0x0000558428ec3326 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+0x579b326)\r\n#13 0x00005584273ad2a1 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+0x3c852a1)\r\n#14 0x0000558424f08ae6 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+0x17e0ae6)\r\n#15 0x00005584273abbed llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3c83bed)\r\n#16 0x0000558424f079e6 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+0x17df9e6)\r\n#17 0x00005584273a9cf1 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+0x3c81cf1)\r\n#18 0x0000558427cc6c29 (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 0x0000558427cc9d83 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+0x45a1d83)\r\n#20 0x000055842836a0fa clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c420fa)\r\n#21 0x000055842a1af38c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6a8738c)\r\n#22 0x000055842836a598 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c42598)\r\n#23 0x0000558428604c59 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4edcc59)\r\n#24 0x00005584285863be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4e5e3be)\r\n#25 0x00005584286f1886 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4fc9886)\r\n#26 0x0000558424adbdd5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b3dd5)\r\n#27 0x0000558424ad4e7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x0000558424ad884e clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b084e)\r\n#29 0x00005584249c91bb main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x12a11bb)\r\n#30 0x00007fa32f122083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x0000558424ad490e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13ac90e)\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 410f751144e8b2e9574f03e0d0fb8560fe3cb797)\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-aeee73.c\r\nclangtk: note: diagnostic msg: /tmp/small-aeee73.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[538] % \r\n[538] % cat small.c\r\nint a[1], *d, e, f[1];\r\nstatic int b, c, *volatile g = &c;\r\nvoid h(int i) { b = b >> 1 ^ a[b ^ i & 1]; }\r\nvoid j(long i) {\r\n b = b >> 1 ^ b;\r\n b = b >> 1 ^ a[b ^ 1];\r\n h(i >> 1);\r\n h(i >> 3);\r\n h(i >> 2);\r\n h(i >> 4);\r\n h(i >> 5);\r\n}\r\nstatic void m() {\r\n int l;\r\n while (e) {\r\n c = 0;\r\n for (; c < 5; c++) {\r\n l = 0;\r\n for (; l < 7; l++)\r\n if (*d)\r\n j(f[c * l]);\r\n }\r\n }\r\n}\r\nint main() {\r\n if (e) {\r\n m();\r\n g;\r\n }\r\n return 0;\r\n}\r\n```\r\n" }, { "author": "fhahn", "body": "@zhendongsu thanks for the report, it was the same issue as the test case @sjoerdmeijer shared at https://github.com/llvm/llvm-project/issues/100591, which was a different underlying issue to the one for this issue.\r\n\r\nBoth should be fixed now, please let me know if you find any other instances of this triggering." }, { "author": "zhendongsu", "body": "Hi @fhahn, here is another related instance that still triggers:\r\n```\r\n[512] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git f22b1da8791edd557ce34c87190e329df2e1c892)\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 -Os small.c\r\nclang-20: /local/suz-local/software/clangbuild/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\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/20240825-clangtk-m64-Os-Wall-Wextra-pipe-fPIC-build-043108/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240825-clangtk-m64-Os-Wall-Wextra-pipe-fPIC-build-043108/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 -Os -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-d7ba19.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-use-loop-info;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x0000564ef7a4babf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x42ddabf)\r\n #1 0x0000564ef7a49004 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f89634f9420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f8962f3000b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f8962f0f859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f8962f0f729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f8962f0f729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f8962f20fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000564ef9358b42 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5beab42)\r\n #9 0x0000564ef937504a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c0704a)\r\n#10 0x0000564ef9377c81 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c09c81)\r\n#11 0x0000564ef9378333 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c0a333)\r\n#12 0x0000564ef8f026e6 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+0x57946e6)\r\n#13 0x0000564ef73e68d1 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+0x3c788d1)\r\n#14 0x0000564ef4f4ff46 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+0x17e1f46)\r\n#15 0x0000564ef73e521d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3c7721d)\r\n#16 0x0000564ef4f4ee46 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+0x17e0e46)\r\n#17 0x0000564ef73e3321 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+0x3c75321)\r\n#18 0x0000564ef7d04bb1 (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 0x0000564ef7d07d73 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+0x4599d73)\r\n#20 0x0000564ef83a840c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c3a40c)\r\n#21 0x0000564efa1f004c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6a8204c)\r\n#22 0x0000564ef83a8828 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c3a828)\r\n#23 0x0000564ef8643cb9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4ed5cb9)\r\n#24 0x0000564ef85c543e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4e5743e)\r\n#25 0x0000564ef8730876 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4fc2876)\r\n#26 0x0000564ef4b21e55 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b3e55)\r\n#27 0x0000564ef4b1aefa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x0000564ef4b1e8ce clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b08ce)\r\n#29 0x0000564ef4a0f1bb main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x12a11bb)\r\n#30 0x00007f8962f11083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x0000564ef4b1a98e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13ac98e)\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 f22b1da8791edd557ce34c87190e329df2e1c892)\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-6fc973.c\r\nclangtk: note: diagnostic msg: /tmp/small-6fc973.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[514] % \r\n[514] % cat small.c\r\nint a, d;\r\nstatic int b = 1, c;\r\nvoid e() {\r\n while (a)\r\n b--;\r\n}\r\nint main() {\r\n for (d = 0; d < 3; d++)\r\n if (a)\r\n for (c = 0; c < 2; c++)\r\n if (b)\r\n break;\r\n return 0;\r\n}\r\n```\r\n\r\nCompiler Explorer: https://godbolt.org/z/zanjboPYo" }, { "author": "zhendongsu", "body": "Hi @fhahn, another reproducer that triggers at -O{s,2,3}:\r\n```\r\n[520] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 7e6b1504c7cf6976ac8e9012c4513ffa258bd8eb)\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[521] % \r\n[521] % clangtk -O3 small.c\r\nclang-20: /local/suz-local/software/clangbuild/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\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/20240826-clangtk-m64-Os-build-191303/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240826-clangtk-m64-Os-build-191303/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 -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-bd6e8d.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,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 \"small.c\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x0000561e24237f5f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x42f4f5f)\r\n #1 0x0000561e242354a4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7461dc8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007f74617ff00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f74617de859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f74617de729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f74617de729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f74617effd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x0000561e25b45232 llvm::LoopVectorizationPlanner::computeBestVF() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c02232)\r\n #9 0x0000561e25b616ca llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c1e6ca)\r\n#10 0x0000561e25b64301 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c21301)\r\n#11 0x0000561e25b649b3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5c219b3)\r\n#12 0x0000561e256ef0a6 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+0x57ac0a6)\r\n#13 0x0000561e23bd2da1 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+0x3c8fda1)\r\n#14 0x0000561e21724f86 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+0x17e1f86)\r\n#15 0x0000561e23bd16ed llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3c8e6ed)\r\n#16 0x0000561e21723e86 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+0x17e0e86)\r\n#17 0x0000561e23bcf7f1 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+0x3c8c7f1)\r\n#18 0x0000561e244f0f41 (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 0x0000561e244f4103 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+0x45b1103)\r\n#20 0x0000561e24b9480c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c5180c)\r\n#21 0x0000561e269dcc5c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6a99c5c)\r\n#22 0x0000561e24b94c28 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4c51c28)\r\n#23 0x0000561e24e30189 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4eed189)\r\n#24 0x0000561e24db162e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4e6e62e)\r\n#25 0x0000561e24f1cde6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4fd9de6)\r\n#26 0x0000561e212f6ed5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b3ed5)\r\n#27 0x0000561e212eff7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#28 0x0000561e212f394e clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13b094e)\r\n#29 0x0000561e211e41eb main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x12a11eb)\r\n#30 0x00007f74617e0083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#31 0x0000561e212efa0e _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x13aca0e)\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 7e6b1504c7cf6976ac8e9012c4513ffa258bd8eb)\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-796071.c\r\nclangtk: note: diagnostic msg: /tmp/small-796071.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[522] % \r\n[522] % cat small.c\r\nchar a;\r\nstatic char b, *c = &b, **d = &c;\r\nint e;\r\nunsigned f;\r\nchar g(int h) { return a << h; }\r\nint main() {\r\n char ***i[2] = {&d, &d};\r\n int *j;\r\n for (; f < 3; f++) {\r\n j = &e;\r\n *j = g(**d);\r\n }\r\n return 0;\r\n}\r\n```\r\n\r\nCompiler Explorer: https://godbolt.org/z/7Y5PzTx4P" } ] }
true
null
121890
https://github.com/llvm/llvm-project/issues/121890
miscompilation
7612dcc6e8d8e7f19b364084effbb01946294720
2025-01-07T06:21:54
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "9725595f3acc0c1aaa354e15ac4ee2b1f8ff4cc9", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 834, 841 ] ], "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::foldGEPICmp" ], "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 9725595f3acc0c1aaa354e15ac4ee2b1f8ff4cc9 Author: Yingwei Zheng <[email protected]> Date: Sat Feb 1 20:41:15 2025 +0800 [InstCombine] Check nowrap flags when folding comparison of GEPs with the same base pointer (#121892) Alive2: https://alive2.llvm.org/ce/z/P5XbMx Closes https://github.com/llvm/llvm-project/issues/121890 TODO: It is still safe to perform this transform without nowrap flags if the corresponding scale factor is 1 byte: https://alive2.llvm.org/ce/z/J-JCJd diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 9e9739ac2440..a8a5cb2b20d7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -834,8 +834,9 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, return replaceInstUsesWith( I, // No comparison is needed here. ConstantInt::get(I.getType(), ICmpInst::isTrueWhenEqual(Cond))); - - else if (NumDifferences == 1 && CanFold(NW)) { + // If two GEPs only differ by an index, compare them. + // Note that nowrap flags are always needed when comparing two indices. + else if (NumDifferences == 1 && NW != GEPNoWrapFlags::none()) { Value *LHSV = GEPLHS->getOperand(DiffOperand); Value *RHSV = GEPRHS->getOperand(DiffOperand); return NewICmp(NW, LHSV, RHSV);
[ { "file": "llvm/test/Transforms/InstCombine/opaque-ptr.ll", "commands": [ "opt -S -passes='instcombine<no-verify-fixpoint>' < %s" ], "tests": [ { "test_name": "cmp_gep_same_base_same_type_nusw", "test_body": "target datalayout = \"p:8:8:8\"\ndefine i1 @cmp_gep_same_base_same_type_nusw(ptr %ptr, i8%idx1, i8%idx2) {\n %gep1 = getelementptr nusw i32, ptr %ptr, i8%idx1\n %gep2 = getelementptr nusw i32, ptr %ptr, i8%idx2\n %cmp = icmp eq ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cmp_gep_same_base_same_type_maywrap", "test_body": "target datalayout = \"p:8:8:8\"\ndefine i1 @cmp_gep_same_base_same_type_maywrap(ptr %ptr, i8%idx1, i8%idx2) {\n %gep1 = getelementptr i32, ptr %ptr, i8%idx1\n %gep2 = getelementptr i32, ptr %ptr, i8%idx2\n %cmp = icmp eq ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cmp_gep_same_base_same_type_nuw", "test_body": "target datalayout = \"p:8:8:8\"\ndefine i1 @cmp_gep_same_base_same_type_nuw(ptr %ptr, i8%idx1, i8%idx2) {\n %gep1 = getelementptr nuw i32, ptr %ptr, i8%idx1\n %gep2 = getelementptr nuw i32, ptr %ptr, i8%idx2\n %cmp = icmp eq ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cmp_gep_same_base_different_type", "test_body": "target datalayout = \"p:8:8:8\"\ndefine i1 @cmp_gep_same_base_different_type(ptr %ptr, i8%idx1, i8%idx2) {\n %gep1 = getelementptr inbounds i32, ptr %ptr, i8%idx1\n %gep2 = getelementptr inbounds i64, ptr %ptr, i8%idx2\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "cmp_gep_same_base_same_type", "test_body": "target datalayout = \"p:8:8:8\"\ndefine i1 @cmp_gep_same_base_same_type(ptr %ptr, i8%idx1, i8%idx2) {\n %gep1 = getelementptr inbounds i32, ptr %ptr, i8%idx1\n %gep2 = getelementptr inbounds i32, ptr %ptr, i8%idx2\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Missing flag check when folding comparison of geps with the same base pointer", "body": "Alive2: https://alive2.llvm.org/ce/z/P5XbMx\n```\n\n----------------------------------------\ndefine i1 @src(ptr %ptr, i8 %idx1, i8 %idx2) {\n#0:\n %gep1 = gep ptr %ptr, 4 x i8 %idx1\n %gep2 = gep ptr %ptr, 4 x i8 %idx2\n %cmp = icmp eq ptr %gep1, %gep2, offsetonly\n ret i1 %cmp\n}\n=>\ndefine i1 @tgt(ptr %ptr, i8 %idx1, i8 %idx2) {\n#0:\n %cmp = icmp eq i8 %idx1, %idx2\n ret i1 %cmp\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\nptr %ptr = null\ni8 %idx1 = #x00 (0)\ni8 %idx2 = #x40 (64)\n\nSource:\nptr %gep1 = null\nptr %gep2 = null\ni1 %cmp = #x1 (1)\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 1\n\nTarget:\ni1 %cmp = #x0 (0)\nSource value: #x1 (1)\nTarget value: #x0 (0)\n\n\n----------------------------------------\ndefine i1 @src1(ptr %ptr, i8 %idx1, i8 %idx2) {\n#0:\n %gep1 = gep nuw ptr %ptr, 4 x i8 %idx1\n %gep2 = gep nuw ptr %ptr, 4 x i8 %idx2\n %cmp = icmp eq ptr %gep1, %gep2, offsetonly\n ret i1 %cmp\n}\n=>\ndefine i1 @tgt1(ptr %ptr, i8 %idx1, i8 %idx2) {\n#0:\n %cmp = icmp eq i8 %idx1, %idx2\n ret i1 %cmp\n}\nTransformation seems to be correct!\n\n\n----------------------------------------\ndefine i1 @src2(ptr %ptr, i8 %idx1, i8 %idx2) {\n#0:\n %gep1 = gep nusw ptr %ptr, 4 x i8 %idx1\n %gep2 = gep nusw ptr %ptr, 4 x i8 %idx2\n %cmp = icmp eq ptr %gep1, %gep2, offsetonly\n ret i1 %cmp\n}\n=>\ndefine i1 @tgt2(ptr %ptr, i8 %idx1, i8 %idx2) {\n#0:\n %cmp = icmp eq i8 %idx1, %idx2\n ret i1 %cmp\n}\nTransformation seems to be correct!\n\nSummary:\n 2 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine", "generated by fuzzer" ], "comments": [] }
true
null
122583
https://github.com/llvm/llvm-project/issues/122583
miscompilation
16e45b8fac797c6d4ba161228b54665492204a9d
2025-01-11T07:48:51
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "066b88879ab5c195e7e14609e546cc238c2f3bf3", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 2441, 2446 ] ], "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": [ "appendOperandsOfVL" ], "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 066b88879ab5c195e7e14609e546cc238c2f3bf3 Author: Alexey Bataev <[email protected]> Date: Mon Jan 13 10:51:26 2025 -0800 [SLP]Correctly set vector operand for extracts with poisons When extracts are vectorized and it has some poison values instead of instructions, need to correctly set the vectorized operand not as poison, but as a main vector operand of the main extract instruction. Fixes #122583 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4b0ed5b30179..2742c3777c1e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2441,6 +2441,17 @@ public: // operations or alternating sequences (e.g., +, -), we can safely // tell the inverse operations by checking commutativity. if (isa<PoisonValue>(VL[Lane])) { + if (auto *EI = dyn_cast<ExtractElementInst>(VL0)) { + if (OpIdx == 0) { + OpsVec[OpIdx][Lane] = {EI->getVectorOperand(), true, false}; + continue; + } + } else if (auto *EV = dyn_cast<ExtractValueInst>(VL0)) { + if (OpIdx == 0) { + OpsVec[OpIdx][Lane] = {EV->getAggregateOperand(), true, false}; + continue; + } + } OpsVec[OpIdx][Lane] = { PoisonValue::get(VL0->getOperand(OpIdx)->getType()), true, false};
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/extractelemets-extended-by-poison.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@j = global [4 x i64] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.pre.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 24), align 8\n %.pre50.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 16), align 16\n %.pre51.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 8), align 8\n %.pre52.i = load i64, ptr @j, align 16\n %0 = or i64 %.pre51.i, 0\n %1 = trunc i64 %.pre.i to i32\n %2 = add i32 %1, 0\n %3 = trunc i64 %.pre50.i to i32\n %4 = add i32 %3, 0\n %5 = trunc i64 %.pre51.i to i32\n %6 = add i32 %5, 0\n %7 = trunc i64 0 to i32\n %8 = add i32 %5, 0\n %9 = add i32 %7, 0\n %10 = add i32 %1, 0\n %11 = add i32 %3, 0\n %12 = add i32 %5, 0\n %13 = add i32 %7, 0\n %14 = trunc i64 %.pre.i to i32\n %15 = add i32 %14, 0\n %16 = trunc i64 %.pre50.i to i32\n %17 = add i32 %16, 0\n %18 = trunc i64 %.pre51.i to i32\n %19 = add i32 %18, 0\n %20 = trunc i64 %.pre52.i to i32\n %conv14.1.i = or i32 %9, %13\n %21 = or i32 %conv14.1.i, %6\n %22 = or i32 %21, %8\n %23 = or i32 %22, %12\n %24 = or i32 %23, %4\n %25 = or i32 %24, %11\n %26 = or i32 %25, %2\n %27 = or i32 %26, %10\n %28 = or i32 %27, %15\n %29 = or i32 %28, %17\n %30 = or i32 %29, %19\n %31 = add i32 %14, 0\n %32 = add i32 %16, 0\n %33 = add i32 %18, 0\n %34 = add i32 %20, 0\n %35 = add i32 %14, 0\n %36 = add i32 %16, 0\n %37 = add i32 %18, 0\n %38 = add i32 %20, 0\n %39 = add i32 %14, 0\n %40 = add i32 %16, 0\n %41 = add i32 %18, 0\n %42 = add i32 %20, 0\n %inc.3.3.i.1 = or i64 %.pre52.i, 0\n %conv14.i.1 = or i32 %38, %34\n %conv14.1.i.1 = or i32 %conv14.i.1, %42\n %conv14.3.i.1 = or i32 %conv14.1.i.1, %33\n %conv14.145.i.1 = or i32 %conv14.3.i.1, %37\n %conv14.1.1.i.1 = or i32 %conv14.145.i.1, %41\n %conv14.3.1.i.1 = or i32 %conv14.1.1.i.1, %32\n %conv14.247.i.1 = or i32 %conv14.3.1.i.1, %36\n %conv14.1.2.i.1 = or i32 %conv14.247.i.1, %40\n %conv14.3.2.i.1 = or i32 %conv14.1.2.i.1, %31\n %conv14.349.i.1 = or i32 %conv14.3.2.i.1, %35\n %conv14.1.3.i.1 = or i32 %conv14.349.i.1, %39\n %conv14.3.3.i.1 = or i32 %conv14.1.3.i.1, %30\n ret i32 %conv14.3.3.i.1\n}\n", "lli_expected_out": "", "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Miscompilation", "body": "Reproducer: https://godbolt.org/z/7eEEeeKoo\nSorry, I cannot provide alive2 link since `llvm.vector.insert.v8i64.v4i64` is not supported.\n```\n; bin/opt -passes=slp-vectorizer reduced.ll -S -o opt.ll\n\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@j = global [4 x i64] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.pre.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 24), align 8\n %.pre50.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 16), align 16\n %.pre51.i = load i64, ptr getelementptr inbounds nuw (i8, ptr @j, i64 8), align 8\n %.pre52.i = load i64, ptr @j, align 16\n %0 = or i64 %.pre51.i, 0\n %1 = trunc i64 %.pre.i to i32\n %2 = add i32 %1, 0\n %3 = trunc i64 %.pre50.i to i32\n %4 = add i32 %3, 0\n %5 = trunc i64 %.pre51.i to i32\n %6 = add i32 %5, 0\n %7 = trunc i64 0 to i32\n %8 = add i32 %5, 0\n %9 = add i32 %7, 0\n %10 = add i32 %1, 0\n %11 = add i32 %3, 0\n %12 = add i32 %5, 0\n %13 = add i32 %7, 0\n %14 = trunc i64 %.pre.i to i32\n %15 = add i32 %14, 0\n %16 = trunc i64 %.pre50.i to i32\n %17 = add i32 %16, 0\n %18 = trunc i64 %.pre51.i to i32\n %19 = add i32 %18, 0\n %20 = trunc i64 %.pre52.i to i32\n %conv14.1.i = or i32 %9, %13\n %21 = or i32 %conv14.1.i, %6\n %22 = or i32 %21, %8\n %23 = or i32 %22, %12\n %24 = or i32 %23, %4\n %25 = or i32 %24, %11\n %26 = or i32 %25, %2\n %27 = or i32 %26, %10\n %28 = or i32 %27, %15\n %29 = or i32 %28, %17\n %30 = or i32 %29, %19\n %31 = add i32 %14, 0\n %32 = add i32 %16, 0\n %33 = add i32 %18, 0\n %34 = add i32 %20, 0\n %35 = add i32 %14, 0\n %36 = add i32 %16, 0\n %37 = add i32 %18, 0\n %38 = add i32 %20, 0\n %39 = add i32 %14, 0\n %40 = add i32 %16, 0\n %41 = add i32 %18, 0\n %42 = add i32 %20, 0\n %inc.3.3.i.1 = or i64 %.pre52.i, 0\n %conv14.i.1 = or i32 %38, %34\n %conv14.1.i.1 = or i32 %conv14.i.1, %42\n %conv14.3.i.1 = or i32 %conv14.1.i.1, %33\n %conv14.145.i.1 = or i32 %conv14.3.i.1, %37\n %conv14.1.1.i.1 = or i32 %conv14.145.i.1, %41\n %conv14.3.1.i.1 = or i32 %conv14.1.1.i.1, %32\n %conv14.247.i.1 = or i32 %conv14.3.1.i.1, %36\n %conv14.1.2.i.1 = or i32 %conv14.247.i.1, %40\n %conv14.3.2.i.1 = or i32 %conv14.1.2.i.1, %31\n %conv14.349.i.1 = or i32 %conv14.3.2.i.1, %35\n %conv14.1.3.i.1 = or i32 %conv14.349.i.1, %39\n %conv14.3.3.i.1 = or i32 %conv14.1.3.i.1, %30\n ret i32 %conv14.3.3.i.1\n}\n```\nOutput:\n```\nsource_filename = \"/app/example.ll\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main() {\n %0 = load <4 x i64>, ptr @j, align 16\n %1 = or i64 poison, 0\n %2 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 1, i32 poison, i32 poison>\n %3 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison>\n %4 = shufflevector <8 x i64> %3, <8 x i64> <i64 poison, i64 poison, i64 poison, i64 poison, i64 0, i64 poison, i64 poison, i64 poison>, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 12, i32 1, i32 poison, i32 poison>\n %5 = call <8 x i64> @llvm.vector.insert.v8i64.v4i64(<8 x i64> %4, <4 x i64> %0, i64 0)\n %6 = trunc <8 x i64> %5 to <8 x i32>\n %7 = shufflevector <8 x i32> %6, <8 x i32> poison, <16 x i32> <i32 0, i32 0, i32 0, i32 1, i32 1, i32 1, i32 2, i32 2, i32 2, i32 3, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5>\n %8 = add <16 x i32> %7, zeroinitializer\n %9 = extractelement <4 x i64> %0, i32 0\n %inc.3.3.i.1 = or i64 %9, 0\n %10 = call i32 @llvm.vector.reduce.or.v16i32(<16 x i32> %8)\n %11 = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> poison)\n %op.rdx = or i32 %10, %11\n ret i32 %op.rdx\n}\n\ndeclare <8 x i64> @llvm.vector.insert.v8i64.v4i64(<8 x i64>, <4 x i64>, i64 immarg) #0\n\ndeclare i32 @llvm.vector.reduce.or.v16i32(<16 x i32>) #0\n\ndeclare i32 @llvm.vector.reduce.or.v8i32(<8 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```\nlli output:\n```\n> bin/lli reduced.ll\n> echo $?\n0\n> bin/lli opt.ll\n> echo $?\n255\n```\n[llubi](https://github.com/dtcxzyw/llvm-ub-aware-interpreter) output:\nBefore:\n```\n> ./llubi reduced.ll --verbose\nEntering function main\n %0 = getelementptr inbounds nuw i8, ptr @j, i64 24 -> Ptr 40[@j + 24]\n %.pre.i = load i64, ptr %0, align 8 -> i64 0\n %1 = getelementptr inbounds nuw i8, ptr @j, i64 16 -> Ptr 32[@j + 16]\n %.pre50.i = load i64, ptr %1, align 16 -> i64 0\n %2 = getelementptr inbounds nuw i8, ptr @j, i64 8 -> Ptr 24[@j + 8]\n %.pre51.i = load i64, ptr %2, align 8 -> i64 0\n %.pre52.i = load i64, ptr @j, align 16 -> i64 0\n %3 = or i64 %.pre51.i, 0 -> i64 0\n %4 = trunc i64 %.pre.i to i32 -> i32 0\n %5 = add i32 %4, 0 -> i32 0\n %6 = trunc i64 %.pre50.i to i32 -> i32 0\n %7 = add i32 %6, 0 -> i32 0\n %8 = trunc i64 %.pre51.i to i32 -> i32 0\n %9 = add i32 %8, 0 -> i32 0\n %10 = trunc i64 0 to i32 -> i32 0\n %11 = add i32 %8, 0 -> i32 0\n %12 = add i32 %10, 0 -> i32 0\n %13 = add i32 %4, 0 -> i32 0\n %14 = add i32 %6, 0 -> i32 0\n %15 = add i32 %8, 0 -> i32 0\n %16 = add i32 %10, 0 -> i32 0\n %17 = trunc i64 %.pre.i to i32 -> i32 0\n %18 = add i32 %17, 0 -> i32 0\n %19 = trunc i64 %.pre50.i to i32 -> i32 0\n %20 = add i32 %19, 0 -> i32 0\n %21 = trunc i64 %.pre51.i to i32 -> i32 0\n %22 = add i32 %21, 0 -> i32 0\n %23 = trunc i64 %.pre52.i to i32 -> i32 0\n %conv14.1.i = or i32 %12, %16 -> i32 0\n %24 = or i32 %conv14.1.i, %9 -> i32 0\n %25 = or i32 %24, %11 -> i32 0\n %26 = or i32 %25, %15 -> i32 0\n %27 = or i32 %26, %7 -> i32 0\n %28 = or i32 %27, %14 -> i32 0\n %29 = or i32 %28, %5 -> i32 0\n %30 = or i32 %29, %13 -> i32 0\n %31 = or i32 %30, %18 -> i32 0\n %32 = or i32 %31, %20 -> i32 0\n %33 = or i32 %32, %22 -> i32 0\n %34 = add i32 %17, 0 -> i32 0\n %35 = add i32 %19, 0 -> i32 0\n %36 = add i32 %21, 0 -> i32 0\n %37 = add i32 %23, 0 -> i32 0\n %38 = add i32 %17, 0 -> i32 0\n %39 = add i32 %19, 0 -> i32 0\n %40 = add i32 %21, 0 -> i32 0\n %41 = add i32 %23, 0 -> i32 0\n %42 = add i32 %17, 0 -> i32 0\n %43 = add i32 %19, 0 -> i32 0\n %44 = add i32 %21, 0 -> i32 0\n %45 = add i32 %23, 0 -> i32 0\n %inc.3.3.i.1 = or i64 %.pre52.i, 0 -> i64 0\n %conv14.i.1 = or i32 %41, %37 -> i32 0\n %conv14.1.i.1 = or i32 %conv14.i.1, %45 -> i32 0\n %conv14.3.i.1 = or i32 %conv14.1.i.1, %36 -> i32 0\n %conv14.145.i.1 = or i32 %conv14.3.i.1, %40 -> i32 0\n %conv14.1.1.i.1 = or i32 %conv14.145.i.1, %44 -> i32 0\n %conv14.3.1.i.1 = or i32 %conv14.1.1.i.1, %35 -> i32 0\n %conv14.247.i.1 = or i32 %conv14.3.1.i.1, %39 -> i32 0\n %conv14.1.2.i.1 = or i32 %conv14.247.i.1, %43 -> i32 0\n %conv14.3.2.i.1 = or i32 %conv14.1.2.i.1, %34 -> i32 0\n %conv14.349.i.1 = or i32 %conv14.3.2.i.1, %38 -> i32 0\n %conv14.1.3.i.1 = or i32 %conv14.349.i.1, %42 -> i32 0\n %conv14.3.3.i.1 = or i32 %conv14.1.3.i.1, %33 -> i32 0\n ret i32 %conv14.3.3.i.1\nExiting function main\n```\nAfter:\n```\n> ./llubi opt.ll --verbose\nEntering function main\n %0 = load <4 x i64>, ptr @j, align 16 -> { i64 0, i64 0, i64 0, i64 0 }\n %1 = or i64 poison, 1 -> poison\n %2 = or i64 poison, 0 -> poison\n %3 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 1, i32 poison, i32 poison> -> { poison, poison, poison, poison, poison, i64 0, poison, poison }\n %4 = shufflevector <4 x i64> %0, <4 x i64> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison> -> { i64 0, i64 0, i64 0, i64 0, poison, poison, poison, poison }\n %5 = shufflevector <8 x i64> %4, <8 x i64> <i64 poison, i64 poison, i64 poison, i64 poison, i64 0, i64 poison, i64 poison, i64 poison>, <8 x i32> <i32 poison, i32 poison, i32 poison, i32 poison, i32 12, i32 1, i32 poison, i32 poison> -> { poison, poison, poison, poison, i64 0, i64 0, poison, poison }\n %6 = call <8 x i64> @llvm.vector.insert.v8i64.v4i64(<8 x i64> %5, <4 x i64> %0, i64 0) -> { i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, poison, poison }\n %7 = trunc <8 x i64> %6 to <8 x i32> -> { i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, poison, poison }\n %8 = shufflevector <8 x i32> %7, <8 x i32> poison, <16 x i32> <i32 0, i32 0, i32 0, i32 1, i32 1, i32 1, i32 2, i32 2, i32 2, i32 3, i32 3, i32 3, i32 4, i32 4, i32 5, i32 5> -> { i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }\n %9 = add <16 x i32> %8, zeroinitializer -> { i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }\n %10 = extractelement <4 x i64> %0, i32 0 -> i64 0\n %inc.3.3.i.1 = or i64 %10, 0 -> i64 0\n %11 = call i32 @llvm.vector.reduce.or.v16i32(<16 x i32> %9) -> i32 0\n %12 = call i32 @llvm.vector.reduce.or.v8i32(<8 x i32> poison) -> poison\n %op.rdx = or i32 %11, %12 -> poison\n ret i32 %op.rdx\nExiting function main\n\nUB triggered: Return a poison value\nExited with immediate UB.\nStacktrace:\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:SLPVectorizer", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "llvm version: 6329355860e9b66bc7ed68b46c166763e408d4cc" } ] }
true
null
111042
https://github.com/llvm/llvm-project/issues/111042
crash
67c0846357bcd6faca713315380f9981a805a6e5
2024-10-03T18:44:33
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "68210c7c269b7b7325dedaea7cea9fe9d979fab5", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 2185, 2190 ] ], "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": [ "VPPredInstPHIRecipe::execute" ], "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 68210c7c269b7b7325dedaea7cea9fe9d979fab5 Author: Florian Hahn <[email protected]> Date: Sat Oct 5 19:15:05 2024 +0100 [VPlan] Only generate first lane for VPPredInstPHI if no others used. IF only the first lane of the result is used, only generate the first lane. Fixes https://github.com/llvm/llvm-project/issues/111042. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 0d092b9c10ac..376b3d33be76 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2185,6 +2185,9 @@ void VPPredInstPHIRecipe::execute(VPTransformState &State) { // predicated iteration inserts its generated value in the correct vector. State.reset(getOperand(0), VPhi); } else { + if (vputils::onlyFirstLaneUsed(this) && !State.Lane->isFirstLane()) + return; + Type *PredInstType = getOperand(0)->getUnderlyingValue()->getType(); PHINode *Phi = State.Builder.CreatePHI(PredInstType, 2); Phi->addIncoming(PoisonValue::get(ScalarPredInst->getType()),
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/divs-with-tail-folding.ll", "commands": [ "opt -p loop-vectorize -mtriple x86_64 -prefer-predicate-over-epilogue=predicate-dont-vectorize -mcpu=skylake-avx512 -S %s" ], "tests": [ { "test_name": "sdiv_feeding_gep_predicated", "test_body": "define void @sdiv_feeding_gep_predicated(ptr %dst, i32 %x, i64 %M, i64 %conv6, i64 %N) {\nentry:\n %conv61 = zext i32 %x to i64\n br label %loop\n\nloop: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c = icmp ule i64 %iv, %M\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop\n %div18 = sdiv i64 %M, %conv6\n %conv20 = trunc i64 %div18 to i32\n %mul30 = mul i64 %div18, %conv61\n %sub31 = sub i64 %iv, %mul30\n %conv34 = trunc i64 %sub31 to i32\n %mul35 = mul i32 %x, %conv20\n %add36 = add i32 %mul35, %conv34\n %idxprom = sext i32 %add36 to i64\n %gep = getelementptr double, ptr %dst, i64 %idxprom\n store double 0.000000e+00, ptr %gep, align 8\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "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": "pr70590_recipe_without_underlying_instr", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc-linux-gnu\"\n\n@c = external global [5 x i8]\n\ndefine void @pr70590_recipe_without_underlying_instr(i64 %n, ptr noalias %dst) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %inc, %loop.latch ]\n %cmp = icmp eq i64 %iv, %n\n br i1 %cmp, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %rem = srem i64 3, 0\n %add3 = add i64 %rem, -3\n %add5 = add i64 %iv, %add3\n %gep = getelementptr [5 x i8], ptr @c, i64 0, i64 %add5\n %l = load i8, ptr %gep, align 1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %sr = phi i8 [ 0, %loop.header ], [ %l, %then ]\n %gep.dst = getelementptr i8, ptr %dst, i64 %iv\n store i8 %sr, ptr %gep.dst, align 4\n %inc = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %inc, 4\n br i1 %exitcond.not, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/X86/replicate-recipe-with-only-first-lane-used.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s" ], "tests": [ { "test_name": "replicate_udiv_with_only_first_lane_used", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @replicate_udiv_with_only_first_lane_used(i32 %x, ptr %dst, i64 %d) {\nentry:\n %c = icmp eq i32 %x, 10\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 true, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %div.i = udiv i64 99, %d\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %retval.0.i = phi i64 [ %div.i, %else ], [ 0, %loop.header ]\n %gep = getelementptr i16, ptr %dst, i64 %retval.0.i\n store i16 0, ptr %gep, align 2\n %iv.next = add i64 %iv, 1\n %cmp = icmp ult i64 %iv.next, 101\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Assertion failed in VPlan.cpp:258", "body": "When I compiled the code with -O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\nstatic uint8_t c[] = {1};\r\nvoid a();\r\nlong b(int h) {\r\n long d = 0;\r\n if (h < 0)\r\n return -1;\r\n int e = 0;\r\n for (int f = 0; f <= h; f++) {\r\n e++;\r\n d += f;\r\n }\r\n long a = d / e;\r\n return a;\r\n}\r\nvoid g();\r\nuint8_t i() {\r\n uint16_t k[4];\r\n int f;\r\n for (; g + f < 4; f++)\r\n k[b(c[0] - 1)] = 5;\r\n for (; f; a(k))\r\n ;\r\n uint8_t *l[3][3], j;\r\n l[0][j] = c;\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:258: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def) || !vputils::onlyFirstLaneUsed(Def) || (hasScalarValue(Def, VPLane(0)) && Data.VPV2Scalars[Def].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/fTrKKha5E", "author": "cardigan1008", "labels": [ "vectorizers", "crash", "regression:19" ], "comments": [ { "author": "shafik", "body": "Looks like a clang-19 regression: https://godbolt.org/z/6d3edKn86" } ] }
true
null
112350
https://github.com/llvm/llvm-project/issues/112350
miscompilation
35e937b4de1890186347a382f7727ba86441dbda
2024-10-15T12:03:18
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "aad3a1630e385a6834f92a5f1d6045451ba21e4e", "components": [ "ValueTracking" ], "bug_location_lineno": { "llvm/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": [ [ 8522, 8527 ], [ 8530, 8535 ] ], "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::isKnownInversion" ], "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 aad3a1630e385a6834f92a5f1d6045451ba21e4e Author: Yingwei Zheng <[email protected]> Date: Thu Oct 17 00:27:21 2024 +0800 [ValueTracking] Respect `samesign` flag in `isKnownInversion` (#112390) In https://github.com/llvm/llvm-project/pull/93591 we introduced `isKnownInversion` and assumes `X` is poison implies `Y` is poison because they share common operands. But after introducing `samesign` this assumption no longer hold if `X` is an icmp has `samesign` flag. Alive2 link: https://alive2.llvm.org/ce/z/rj3EwQ (Please run it locally with this patch and https://github.com/AliveToolkit/alive2/pull/1098). This approach is the most conservative way in my mind to address this problem. If `X` has `samesign` flag, it will check if `Y` also has this flag and make sure constant RHS operands have the same sign. Fixes https://github.com/llvm/llvm-project/issues/112350. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index eb8d17044a17..e9ed8b3c862b 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8522,6 +8522,10 @@ bool llvm::isKnownInversion(const Value *X, const Value *Y) { !match(Y, m_c_ICmp(Pred2, m_Specific(A), m_Value(C)))) return false; + // They must both have samesign flag or not. + if (cast<ICmpInst>(X)->hasSameSign() != cast<ICmpInst>(Y)->hasSameSign()) + return false; + if (B == C) return Pred1 == ICmpInst::getInversePredicate(Pred2); @@ -8530,6 +8534,11 @@ bool llvm::isKnownInversion(const Value *X, const Value *Y) { if (!match(B, m_APInt(RHSC1)) || !match(C, m_APInt(RHSC2))) return false; + // Sign bits of two RHSCs should match. + if (cast<ICmpInst>(X)->hasSameSign() && + RHSC1->isNonNegative() != RHSC2->isNonNegative()) + return false; + const auto CR1 = ConstantRange::makeExactICmpRegion(Pred1, *RHSC1); const auto CR2 = ConstantRange::makeExactICmpRegion(Pred2, *RHSC2);
[ { "file": "llvm/test/Transforms/InstCombine/select-cmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_select_inverse_nonconst4", "test_body": "define i1 @test_select_inverse_nonconst4(i64 %x, i64 %y, i64 %z, i1 %cond) {\n %cmp1 = icmp ult i64 %x, %y\n %cmp2 = icmp uge i64 %z, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_both", "test_body": "define i1 @test_select_inverse_samesign_both(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, %y\n %cmp2 = icmp samesign uge i64 %x, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_false_arm_rhsc_same_sign", "test_body": "define i1 @test_select_inverse_samesign_false_arm_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp ult i64 %x, 11\n %cmp2 = icmp samesign ugt i64 %x, 10\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_true_arm", "test_body": "define i1 @test_select_inverse_samesign_true_arm(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, %y\n %cmp2 = icmp uge i64 %x, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_true_arm_rhsc_same_sign", "test_body": "define i1 @test_select_inverse_samesign_true_arm_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, 11\n %cmp2 = icmp ugt i64 %x, 10\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_both_rhsc_diff_sign", "test_body": "define i1 @test_select_inverse_samesign_both_rhsc_diff_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign slt i64 %x, 0\n %cmp2 = icmp samesign sgt i64 %x, -1\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_both_rhsc_same_sign", "test_body": "define i1 @test_select_inverse_samesign_both_rhsc_same_sign(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp samesign ult i64 %x, 11\n %cmp2 = icmp samesign ugt i64 %x, 10\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_select_inverse_samesign_false_arm", "test_body": "define i1 @test_select_inverse_samesign_false_arm(i64 %x, i64 %y, i1 %cond) {\n %cmp1 = icmp ult i64 %x, %y\n %cmp2 = icmp samesign uge i64 %x, %y\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\n ret i1 %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sel_icmp_two_cmp", "test_body": "define i1 @sel_icmp_two_cmp(i1 %c, i32 %a1, i32 %a2, i32 %a3, i32 %a4) {\n %v1 = call i8 @llvm.ucmp.i8.i32(i32 %a1, i32 %a2)\n %v2 = call i8 @llvm.scmp.i8.i32(i32 %a3, i32 %a4)\n %sel = select i1 %c, i8 %v1, i8 %v2\n %cmp = icmp sle i8 %sel, 0\n ret i1 %cmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.scmp.i8.i32(i32, i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.ucmp.i8.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped", "body": "Reproducer:\r\n```\r\ndefine i1 @src(i64 %x, i64 %y, i1 %cond) {\r\n %cmp1 = icmp ult i64 %x, %y\r\n %cmp2 = icmp samesign uge i64 %x, %y\r\n %sel = select i1 %cond, i1 %cmp1, i1 %cmp2\r\n ret i1 %sel\r\n}\r\n\r\ndefine i1 @tgt(i64 %x, i64 %y, i1 %cond) {\r\n %cmp2 = icmp samesign uge i64 %x, %y\r\n %sel = xor i1 %cond, %cmp2\r\n ret i1 %sel\r\n}\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [ { "author": "antoniofrighetto", "body": "Don't we miss checking the flag in `hasPoisonGeneratingFlags`?" }, { "author": "dtcxzyw", "body": "> Don't we miss checking the flag in `hasPoisonGeneratingFlags`?\r\n\r\nYeah. I am preparing a patch.\r\n" }, { "author": "dtcxzyw", "body": "But adding support in `hasPoisonGeneratingFlags` doesn't address this issue :(\r\n" }, { "author": "antoniofrighetto", "body": "> But adding support in `hasPoisonGeneratingFlags` doesn't address this issue :(\r\n\r\nI assume we may need to `dropPoisonGeneratingFlags` in InstCombineCompares, where needed?" } ] }
true
null
124267
https://github.com/llvm/llvm-project/issues/124267
miscompilation
9cf52fe1f94fdcd8e27c76f7d33a80eeb2075833
2025-01-24T13:05:38
[ "llvm/test/Analysis/ValueTracking" ]
{ "fix_commit": "c546b5317c518987a5f45dd4c4d25321a955c758", "components": [ "ValueTracking" ], "bug_location_lineno": { "llvm/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": [ [ 9494, 9500 ], [ 9504, 9510 ] ], "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": [ "isImpliedCondICmps" ], "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 c546b5317c518987a5f45dd4c4d25321a955c758 Author: DianQK <[email protected]> Date: Fri Jan 24 23:02:50 2025 +0800 [ValueTracking] Pass changed predicate `SignedLPred` to `isImpliedByMatchingCmp` (#124271) Fixes #124267. Since we are using the new predicate, we should also update the parameters of `isImpliedByMatchingCmp`. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 264fedd6b66b..eba728c7c8c3 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -9494,7 +9494,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0, SignedLPred == ICmpInst::ICMP_SGE) && match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) { if (match(R1, m_NonPositive()) && - ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == false) + ICmpInst::isImpliedByMatchingCmp(SignedLPred, RPred) == false) return false; } @@ -9504,7 +9504,7 @@ isImpliedCondICmps(const ICmpInst *LHS, CmpPredicate RPred, const Value *R0, SignedLPred == ICmpInst::ICMP_SLE) && match(R0, m_NSWSub(m_Specific(L0), m_Specific(L1)))) { if (match(R1, m_NonNegative()) && - ICmpInst::isImpliedByMatchingCmp(LPred, RPred) == true) + ICmpInst::isImpliedByMatchingCmp(SignedLPred, RPred) == true) return true; }
[ { "file": "llvm/test/Analysis/ValueTracking/implied-condition-samesign.ll", "commands": [ "opt -passes=instsimplify -S %s" ], "tests": [ { "test_name": "gt_sub_nsw_ult", "test_body": "define i1 @gt_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {\n %LHS = icmp samesign ugt i8 %L0, %L1\n br i1 %LHS, label %LHS_true, label %LHS_false\n\nLHS_true: ; preds = %0\n %R0 = sub nsw i8 %L0, %L1\n %RHS = icmp ult i8 %R0, -1\n ret i1 %RHS\n\nLHS_false: ; preds = %0\n ret i1 %V\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "lt_sub_nsw_ult", "test_body": "define i1 @lt_sub_nsw_ult(i8 %L0, i8 %L1, i1 %V) {\n %LHS = icmp samesign ult i8 %L0, %L1\n br i1 %LHS, label %LHS_true, label %LHS_false\n\nLHS_true: ; preds = %0\n %R0 = sub nsw i8 %L0, %L1\n %RHS = icmp ult i8 %R0, 1\n ret i1 %RHS\n\nLHS_false: ; preds = %0\n ret i1 %V\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[ValueTracking] miscompile in samesign compare", "body": "#122590 and #122700 miscompile the following code:\n\n```llvm\ndefine i1 @src(i8 %L0, i8 %L1, i1 %V) {\n %LHS = icmp samesign ugt i8 %L0, %L1\n %R0 = sub nsw i8 %L0, %L1\n %RHS = icmp ult i8 %R0, -1\n br i1 %LHS, label %LHS_true, label %LHS_false\n\nLHS_true:\n br label %EXIT\n\nLHS_false:\n br label %EXIT\n\nEXIT:\n %RET = phi i1 [ %RHS, %LHS_true ], [ %V, %LHS_false ]\n ret i1 %RET\n}\n```\n\n`%RHS` should be 1: https://alive2.llvm.org/ce/z/RscAzy.", "author": "DianQK", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [] }
true
null
107171
https://github.com/llvm/llvm-project/issues/107171
crash
34f2c9a9ce73a61b27d75dab7e1eed256491afcc
2024-09-04T00:23:05
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "3fe6a064f15cd854fd497594cc20e8b680cd2133", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 6606, 6614 ] ], "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 3fe6a064f15cd854fd497594cc20e8b680cd2133 Author: Florian Hahn <[email protected]> Date: Wed Sep 4 20:50:05 2024 +0100 [LV] Check if compare is truncated directly in getInstructionCost. The current check for truncated compares in getInstructionCost misses cases where either the first or both operands are constants. Check directly if the compare is marked for truncation. In that case, the minimum bitwidth is that of the operands. The patch also adds asserts to ensure that. This fixes a divergence between legacy and VPlan-based cost model, where the legacy cost model incorrectly estimated the cost of compares with truncated operands. Fixes https://github.com/llvm/llvm-project/issues/107171. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0200525a718d..0ccf442dac99 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6606,9 +6606,20 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, case Instruction::ICmp: case Instruction::FCmp: { Type *ValTy = I->getOperand(0)->getType(); + Instruction *Op0AsInstruction = dyn_cast<Instruction>(I->getOperand(0)); - if (canTruncateToMinimalBitwidth(Op0AsInstruction, VF)) - ValTy = IntegerType::get(ValTy->getContext(), MinBWs[Op0AsInstruction]); + (void)Op0AsInstruction; + assert((!canTruncateToMinimalBitwidth(Op0AsInstruction, VF) || + canTruncateToMinimalBitwidth(I, VF)) && + "truncating Op0 must imply truncating the compare"); + if (canTruncateToMinimalBitwidth(I, VF)) { + assert(!canTruncateToMinimalBitwidth(Op0AsInstruction, VF) || + MinBWs[I] == MinBWs[Op0AsInstruction] && + "if both the operand and the compare are marked for " + "truncation, they must have the same bitwidth"); + ValTy = IntegerType::get(ValTy->getContext(), MinBWs[I]); + } + VectorTy = ToVectorTy(ValTy, VF); return TTI.getCmpSelInstrCost(I->getOpcode(), VectorTy, nullptr, cast<CmpInst>(I)->getPredicate(), CostKind,
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll", "commands": [ "opt -p loop-vectorize -mattr=+v -S %s" ], "tests": [ { "test_name": "test_pr98413_zext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_zext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = zext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "truncate_to_i1_used_by_branch", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @truncate_to_i1_used_by_branch(i8 %x, ptr %dst) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %f.039 = phi i8 [ 0, %entry ], [ %add, %loop.latch ]\n %0 = or i8 23, %x\n %extract.t = trunc i8 %0 to i1\n br i1 %extract.t, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n store i8 0, ptr %dst, align 1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %add = add i8 %f.039, 1\n %conv = sext i8 %f.039 to i32\n %cmp = icmp slt i32 %conv, 1\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl256b\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_ops_narrowed_to_i1", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine i8 @icmp_ops_narrowed_to_i1() #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop ]\n %c = icmp eq i8 0, 0\n %ext = zext i1 %c to i64\n %shr = lshr i64 %ext, 1\n %trunc = trunc i64 %shr to i8\n %iv.next = add i16 %iv, 1\n %ec = icmp eq i16 %iv.next, 100\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i8 %trunc\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_pr98413_sext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_sext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = sext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Testing using 3bd161e98d89d31696002994771b7761f1c74859\r\n\r\nC testcase:\r\n```c\r\nchar a;\r\nunsigned b = 221;\r\nshort c = 35;\r\nchar d[6];\r\nint main() {\r\n d[0] = 4079751220931503459;\r\n for (short e = 3; e; e += 3)\r\n for (short f = 0; f < 1; f += -1832)\r\n for (long g = ({\r\n __typeof__(0) h = !d[f * 1];\r\n h;\r\n });\r\n g < c - 3; g += b - 219)\r\n a -= 8;\r\n}\r\n```\r\n`/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -I/scratch/tc-testing/compiler-fuzz-ci/csmith-build/include -fsigned-char -fno-strict-aliasing -fwrapv -march=rv64gcv -flto -O3 -fuse-ld=lld red.c -o rv64gcv.out -w`\r\n\r\nLLVM IR:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main() #0 {\r\nentry:\r\n br label %for.body14.preheader48\r\n\r\nfor.cond.cleanup: ; preds = %for.body14.preheader48\r\n store i8 %1, ptr null, align 1\r\n ret i32 0\r\n\r\nfor.body14.preheader48: ; preds = %for.body14.preheader48, %entry\r\n %e.047 = phi i16 [ 0, %entry ], [ %add27, %for.body14.preheader48 ]\r\n %tobool6.not = icmp eq i8 0, 0\r\n %conv7 = zext i1 %tobool6.not to i64\r\n %0 = lshr i64 %conv7, 1\r\n %1 = trunc i64 %0 to i8\r\n %add27 = add i16 %e.047, 1\r\n %tobool.not = icmp eq i16 %add27, 0\r\n br i1 %tobool.not, label %for.cond.cleanup, label %for.body14.preheader48\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7389: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000061eac73d9f50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3010f50)\r\n #1 0x000061eac73d735f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300e35f)\r\n #2 0x000061eac73d74b5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007496e1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007496e12969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007496e12969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007496e12969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007496e1242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007496e12287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007496e122871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007496e1239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000061eac63ad810 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe4810)\r\n#12 0x000061eac63c45bb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffb5bb)\r\n#13 0x000061eac63c75d1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffe5d1)\r\n#14 0x000061eac63c7c47 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffec47)\r\n#15 0x000061eac5222626 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe59626)\r\n#16 0x000061eac71e5cef llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1ccef)\r\n#17 0x000061eac52257b6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5c7b6)\r\n#18 0x000061eac71e4a6b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1ba6b)\r\n#19 0x000061eac5221a56 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe58a56)\r\n#20 0x000061eac71e2aad llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e19aad)\r\n#21 0x000061eac4a4fde6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x686de6)\r\n#22 0x000061eac4a41b71 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x678b71)\r\n#23 0x00007496e1229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007496e1229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007496e1229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x000061eac4a37f25 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66ef25)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/x316voG8q\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/106780\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
116691
https://github.com/llvm/llvm-project/issues/116691
crash
a4e1a3dc8bc9bb971d8a38130254b4570f8b7a03
2024-11-18T20:36:44
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "ad9c0b369e86e75d56e229f294782a4eaf527226", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 6815, 6830 ], [ 6861, 6866 ], [ 6903, 6909 ] ], "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::tryToVectorizeGatheredLoads" ], "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 ad9c0b369e86e75d56e229f294782a4eaf527226 Author: Alexey Bataev <[email protected]> Date: Mon Nov 18 13:49:04 2024 -0800 [SLP]Check if the gathered loads form full vector before attempting build it Need to check that the number of gathered loads in the slice forms the build vector to avoid compiler crash. Fixes #116691 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 918d7663548f..dc0dffd9fcbf 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6815,16 +6815,7 @@ void BoUpSLP::tryToVectorizeGatheredLoads( // Check if it is profitable to try vectorizing gathered loads. It is // profitable if we have more than 3 consecutive loads or if we have // less but all users are vectorized or deleted. - bool AllowToVectorize = - NumElts >= 3 || - any_of(ValueToGatherNodes.at(Slice.front()), - [=](const TreeEntry *TE) { - return TE->Scalars.size() == 2 && - ((TE->Scalars.front() == Slice.front() && - TE->Scalars.back() == Slice.back()) || - (TE->Scalars.front() == Slice.back() && - TE->Scalars.back() == Slice.front())); - }); + bool AllowToVectorize = false; // Check if it is profitable to vectorize 2-elements loads. if (NumElts == 2) { bool IsLegalBroadcastLoad = TTI->isLegalBroadcastLoad( @@ -6861,6 +6852,19 @@ void BoUpSLP::tryToVectorizeGatheredLoads( return true; }; AllowToVectorize = CheckIfAllowed(Slice); + } else { + AllowToVectorize = + (NumElts >= 3 || + any_of(ValueToGatherNodes.at(Slice.front()), + [=](const TreeEntry *TE) { + return TE->Scalars.size() == 2 && + ((TE->Scalars.front() == Slice.front() && + TE->Scalars.back() == Slice.back()) || + (TE->Scalars.front() == Slice.back() && + TE->Scalars.back() == Slice.front())); + })) && + hasFullVectorsOrPowerOf2(*TTI, Slice.front()->getType(), + Slice.size()); } if (AllowToVectorize) { SmallVector<Value *> PointerOps; @@ -6903,7 +6907,8 @@ void BoUpSLP::tryToVectorizeGatheredLoads( } // Mark masked gathers candidates as vectorized, if any. for (unsigned Cnt : MaskedGatherVectorized) { - ArrayRef<LoadInst *> Slice = ArrayRef(Loads).slice(Cnt, NumElts); + ArrayRef<LoadInst *> Slice = ArrayRef(Loads).slice( + Cnt, std::min<unsigned>(NumElts, Loads.size() - Cnt)); ArrayRef<Value *> Values( reinterpret_cast<Value *const *>(Slice.begin()), Slice.size()); Results.emplace_back(Values, LoadsState::ScatterVectorize);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/gathered-loads-non-full-reg.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux -mcpu=cascadelake < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@solid_ = external global [608 x i8]\n\ndefine void @test(ptr noalias %0) {\n;\n.lr.ph1019:\n %1 = getelementptr i8, ptr %0, i64 8\n %2 = getelementptr i8, ptr %0, i64 32\n %3 = getelementptr i8, ptr %0, i64 128\n %4 = getelementptr i8, ptr %0, i64 200\n %5 = getelementptr i8, ptr %0, i64 208\n %6 = getelementptr i8, ptr %0, i64 232\n %7 = getelementptr i8, ptr %0, i64 288\n %8 = getelementptr i8, ptr %0, i64 320\n %9 = getelementptr i8, ptr %0, i64 304\n %10 = getelementptr i8, ptr %0, i64 424\n %11 = getelementptr i8, ptr %0, i64 480\n %12 = getelementptr i8, ptr %0, i64 504\n %13 = getelementptr i8, ptr %0, i64 632\n %14 = getelementptr i8, ptr %0, i64 720\n %15 = load double, ptr %1, align 8\n %16 = load double, ptr %2, align 8\n %17 = fadd double %16, %15\n %18 = load double, ptr %3, align 8\n %19 = load double, ptr %4, align 8\n %20 = load double, ptr %5, align 8\n %21 = load double, ptr %6, align 8\n %22 = fadd double %21, %20\n %23 = load double, ptr %7, align 8\n %24 = load double, ptr %8, align 8\n %25 = load double, ptr %9, align 8\n %26 = load double, ptr %10, align 8\n %27 = load double, ptr %11, align 8\n %28 = load double, ptr %12, align 8\n %29 = fadd double %28, %27\n %30 = fmul double %22, %18\n %31 = fmul double %30, 0.000000e+00\n %32 = fsub double 0.000000e+00, %25\n %33 = fmul double %32, 0.000000e+00\n %34 = fadd double %33, 0.000000e+00\n %35 = fmul double %34, 0.000000e+00\n %36 = fmul double %29, %26\n %37 = fmul double %36, 0.000000e+00\n %38 = fadd double %37, 0.000000e+00\n %39 = fsub double %17, %19\n %40 = fmul double %39, %23\n %41 = fmul double %40, 0.000000e+00\n %42 = load double, ptr %0, align 8\n %43 = load double, ptr %13, align 8\n %44 = fmul double %43, %31\n %45 = load double, ptr %14, align 8\n %46 = fmul double %35, 0.000000e+00\n %47 = fadd double %44, 0.000000e+00\n %48 = fmul double %45, %38\n %49 = fmul double %45, %41\n store double %46, ptr getelementptr inbounds (i8, ptr @solid_, i64 384), align 8\n store double %47, ptr getelementptr inbounds (i8, ptr @solid_, i64 408), align 8\n store double %48, ptr getelementptr inbounds (i8, ptr @solid_, i64 392), align 8\n store double %49, ptr getelementptr inbounds (i8, ptr @solid_, i64 400), align 8\n %.neg965 = fmul double %48, %24\n %reass.add993 = fadd double %.neg965, 0.000000e+00\n %50 = fadd double %42, %reass.add993\n %51 = fsub double 0.000000e+00, %50\n store double %51, ptr getelementptr inbounds (i8, ptr @solid_, i64 296), align 8\n %.neg969 = fmul double %49, 0.000000e+00\n %reass.add996 = fadd double %.neg969, 0.000000e+00\n %52 = fadd double %45, %reass.add996\n %53 = fsub double 0.000000e+00, %52\n store double %53, ptr getelementptr inbounds (i8, ptr @solid_, i64 304), align 8\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Crash in SLPVectorizer.cpp", "body": "I'm seeing a problem that shows up in the flang compiler when compiling a large, proprietary benchmark. Since the benchmark is proprietary, I can't include the source code in this bug report.\r\n\r\nThe problem happens in in the file `.../llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp` in the function `BoUpSLP::tryToVectorizeGatheredLoads`.\r\n\r\nIn the code around line 6906, is the statement:\r\n\r\n```\r\nArrayRef<LoadInst *> Slice = ArrayRef(Loads).slice(Cnt, NumElts);\r\n```\r\n\r\nThe code for `slice()` is in `llvm-project/llvm/include/llvm/ADT/ArrayRef.h`. It contains the line:\r\n\r\n```\r\nassert(N+M <= size() && \"Invalid specifier\");\r\n```\r\n\r\nThis assertion fails, and the compiler crashes.\r\n\r\nI added debug code to `SLPVectorizer.cpp` to trace how the variables `Cnt` and `NumElts` got their values leading up to the point of failure. I've included the output of running the compiler on the test case in the file `log` along with the source code of the modified version of `SLPVectorizer.cpp` in the attached zip file.\r\n\r\nAt the point of failure, the value of `N` (which corresponds to `Cnt`) is 8. The value of `M` (passed from `NumElts`) is also 8. The call to `size()` returns 14. Since 8 + 8 is not less than or equal to 14, the assert fails and the compiler crashes.\r\n\r\nI captured the LLVM IR of the original test case and included it below in the file `x13.f90.ll` in the attached zip file.\r\n\r\nIf you run this command after downloading `x13.f90.ll`, you'll see the error:\r\n\r\n```\r\n#!/bin/bash\r\n../bin/clang -c -O3 -march=native -mllvm -locally-hot-callsite-threshold=4500 x13.f90.ll\r\n```\r\n\r\nI also ran the `x13.f90.ll` file through `llvm-reduce` using the following command:\r\n\r\n```\r\nllvm-reduce --test pcrash.sh x13.f90.ll\r\n```\r\n\r\nThis produced a file called `reduced.ll` that I've included in the attached zip file. I've also included the log file `reduced.log` that shows what happend when you run the command:\r\n\r\n```\r\n#!/bin/bash\r\n../bin/clang -c -O3 -march=native -mllvm -locally-hot-callsite-threshold=4500 reduced.ll\r\n```\r\n\r\n@alexey-bataev, please let me know if someone else should look at this or if I can help out by adding additional debug information.\r\n\r\n[Archive.zip](https://github.com/user-attachments/files/17805978/Archive.zip)\r\n", "author": "psteinfeld", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
100464
https://github.com/llvm/llvm-project/issues/100464
crash
ba461f8c6278a7b2fd7695454c1f184c38897ecd
2024-07-24T20:37:49
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "b72689a5cbd8645c183476cd87e32948308c5b64", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 6678, 6683 ], [ 6693, 6700 ], [ 6727, 6742 ] ], "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 b72689a5cbd8645c183476cd87e32948308c5b64 Author: Florian Hahn <[email protected]> Date: Thu Jul 25 11:16:09 2024 +0100 [LV] Ignore live-out users in cost model if scalar epilogue is required. Follow-up to ba8126b6fef79. If a scalar epilogue is required, users outside the loop won't use live-outs from the vector loop but from the scalar epilogue. Ignore them if that is the case. This fixes another case where the VPlan-based cost-model more accurately computes cost. Fixes https://github.com/llvm/llvm-project/issues/100464. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index b709ccc3c35a..224d98d5c4f9 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6678,6 +6678,15 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { SmallVector<Value *, 4> DeadInterleavePointerOps; SmallVector<Value *, 4> DeadOps; + + // If a scalar epilogue is required, users outside the loop won't use + // live-outs from the vector loop but from the scalar epilogue. Ignore them if + // that is the case. + bool RequiresScalarEpilogue = requiresScalarEpilogue(true); + auto IsLiveOutDead = [this, RequiresScalarEpilogue](User *U) { + return RequiresScalarEpilogue && + !TheLoop->contains(cast<Instruction>(U)->getParent()); + }; for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { // Find all stores to invariant variables. Since they are going to sink @@ -6693,8 +6702,9 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { // Add instructions that would be trivially dead and are only used by // values already ignored to DeadOps to seed worklist. if (wouldInstructionBeTriviallyDead(&I, TLI) && - all_of(I.users(), [this](User *U) { - return VecValuesToIgnore.contains(U) || ValuesToIgnore.contains(U); + all_of(I.users(), [this, IsLiveOutDead](User *U) { + return VecValuesToIgnore.contains(U) || + ValuesToIgnore.contains(U) || IsLiveOutDead(U); })) DeadOps.push_back(&I); @@ -6727,16 +6737,22 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { // Mark ops that would be trivially dead and are only used by ignored // instructions as free. + BasicBlock *Header = TheLoop->getHeader(); for (unsigned I = 0; I != DeadOps.size(); ++I) { auto *Op = dyn_cast<Instruction>(DeadOps[I]); // Skip any op that shouldn't be considered dead. if (!Op || !TheLoop->contains(Op) || + (isa<PHINode>(Op) && Op->getParent() == Header) || !wouldInstructionBeTriviallyDead(Op, TLI) || - any_of(Op->users(), [this](User *U) { - return !VecValuesToIgnore.contains(U) && !ValuesToIgnore.contains(U); + any_of(Op->users(), [this, IsLiveOutDead](User *U) { + return !VecValuesToIgnore.contains(U) && ValuesToIgnore.contains(U) && + !IsLiveOutDead(U); })) continue; + if (!TheLoop->contains(Op->getParent())) + continue; + // If all of Op's users are in ValuesToIgnore, add it to ValuesToIgnore // which applies for both scalar and vector versions. Otherwise it is only // dead in vector versions, so only add it to VecValuesToIgnore.
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll", "commands": [ "opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s" ], "tests": [ { "test_name": "dead_live_out_due_to_scalar_epilogue_required", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i8 @dead_live_out_due_to_scalar_epilogue_required(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %idxprom = sext i32 %iv to i64\n %gep.src = getelementptr i8, ptr %src, i64 %idxprom\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %idxprom\n store i8 0, ptr %gep.dst, align 1\n %iv.next = add i32 %iv, 4\n %cmp = icmp ult i32 %iv, 1001\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n %r = phi i8 [ %l, %loop ]\n ret i8 %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "dead_load", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/RISCV/riscv-vector-reverse.ll", "commands": [ "opt -passes=loop-vectorize,dce,instcombine -mtriple riscv64-linux-gnu -mattr=+v -debug-only=loop-vectorize -scalable-vectorization=on -riscv-v-vector-bits-min=128 -disable-output < %s 2>&1" ], "tests": [ { "test_name": "vector_reverse_i64", "test_body": "define void @vector_reverse_i64(ptr nocapture noundef writeonly %A, ptr nocapture noundef readonly %B, i32 noundef signext %n) {\nentry:\n %cmp7 = icmp sgt i32 %n, 0\n br i1 %cmp7, label %for.body.preheader, label %for.cond.cleanup\n\nfor.body.preheader: ; preds = %entry\n %0 = zext i32 %n to i64\n br label %for.body\n\nfor.cond.cleanup: ; preds = %for.body, %entry\n ret void\n\nfor.body: ; preds = %for.body, %for.body.preheader\n %indvars.iv = phi i64 [ %0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %i.0.in8 = phi i32 [ %n, %for.body.preheader ], [ %i.0, %for.body ]\n %i.0 = add nsw i32 %i.0.in8, -1\n %idxprom = zext i32 %i.0 to i64\n %arrayidx = getelementptr inbounds i32, ptr %B, i64 %idxprom\n %1 = load i32, ptr %arrayidx, align 4\n %add9 = add i32 %1, 1\n %arrayidx3 = getelementptr inbounds i32, ptr %A, i64 %idxprom\n store i32 %add9, ptr %arrayidx3, align 4\n %cmp = icmp ugt i64 %indvars.iv, 1\n %indvars.iv.next = add nsw i64 %indvars.iv, -1\n br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0\n}\n\n!0 = distinct !{!0, !1, !2, !3, !4}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.width\", i32 4}\n!3 = !{!\"llvm.loop.vectorize.scalable.enable\", i1 true}\n!4 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "vector_reverse_f32", "test_body": "define void @vector_reverse_f32(ptr nocapture noundef writeonly %A, ptr nocapture noundef readonly %B, i32 noundef signext %n) {\nentry:\n %cmp7 = icmp sgt i32 %n, 0\n br i1 %cmp7, label %for.body.preheader, label %for.cond.cleanup\n\nfor.body.preheader: ; preds = %entry\n %0 = zext i32 %n to i64\n br label %for.body\n\nfor.cond.cleanup: ; preds = %for.body, %entry\n ret void\n\nfor.body: ; preds = %for.body, %for.body.preheader\n %indvars.iv = phi i64 [ %0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %i.0.in8 = phi i32 [ %n, %for.body.preheader ], [ %i.0, %for.body ]\n %i.0 = add nsw i32 %i.0.in8, -1\n %idxprom = zext i32 %i.0 to i64\n %arrayidx = getelementptr inbounds float, ptr %B, i64 %idxprom\n %1 = load float, ptr %arrayidx, align 4\n %conv1 = fadd float %1, 1.000000e+00\n %arrayidx3 = getelementptr inbounds float, ptr %A, i64 %idxprom\n store float %conv1, ptr %arrayidx3, align 4\n %cmp = icmp ugt i64 %indvars.iv, 1\n %indvars.iv.next = add nsw i64 %indvars.iv, -1\n br i1 %cmp, label %for.body, label %for.cond.cleanup, !llvm.loop !0\n}\n\n!0 = distinct !{!0, !1, !2, !3, !4}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.width\", i32 4}\n!3 = !{!\"llvm.loop.vectorize.scalable.enable\", i1 true}\n!4 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] VPlan cost model and legacy cost model disagreed", "body": "Related: #99701, #92555. @fhahn Please let me know if you'd prefer these assert triggering testcases to be all in the same issue or prefer a new issue when a new testcase is found.\r\n\r\nTested using llvm f719a339a89b\r\n\r\nTestcase:\r\n```llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main(ptr %0) #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %.lcssa = phi i8 [ %1, %for.body ]\r\n ret i32 0\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %l.011 = phi i32 [ 0, %entry ], [ %add, %for.body ]\r\n %idxprom = sext i32 %l.011 to i64\r\n %arrayidx1 = getelementptr [15 x i8], ptr %0, i64 0, i64 %idxprom\r\n %1 = load i8, ptr %arrayidx1, align 1\r\n %arrayidx3 = getelementptr [0 x i8], ptr null, i64 0, i64 %idxprom\r\n store i8 0, ptr %arrayidx3, align 1\r\n %add = add i32 %l.011, 4\r\n %cmp = icmp ult i32 %l.011, -9\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10098: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x0000647de5790dd0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f1ddd0)\r\n #1 0x0000647de578e1ef llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f1b1ef)\r\n #2 0x0000647de578e345 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007b2a02842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007b2a028969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007b2a028969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007b2a028969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007b2a02842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007b2a028287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007b2a0282871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007b2a02839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000647de47acc98 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f39c98)\r\n#12 0x0000647de47af851 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f3c851)\r\n#13 0x0000647de47affd0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f3cfd0)\r\n#14 0x0000647de3621ff6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xdaeff6)\r\n#15 0x0000647de55a8e7e llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d35e7e)\r\n#16 0x0000647de3625186 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xdb2186)\r\n#17 0x0000647de55a7c0b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d34c0b)\r\n#18 0x0000647de36214d6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xdae4d6)\r\n#19 0x0000647de55a5d5d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d32d5d)\r\n#20 0x0000647de2e6b5d6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5f85d6)\r\n#21 0x0000647de2e5d211 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5ea211)\r\n#22 0x00007b2a02829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x00007b2a02829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x00007b2a02829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x0000647de2e530a5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e00a5)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/z7ee8hWWP", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "@patrick-rivos thanks for the report. I think it would be best to keep filing separate issues, as the underlying issues usually are different. Although the fuzzers may generate many instances of the same issue as was the case for https://github.com/llvm/llvm-project/issues/99701. Not sure if there's an easy way to catch that other than waiting for a day or so after filing the first issue." } ] }
true
null
109510
https://github.com/llvm/llvm-project/issues/109510
crash
eb6e7e8f89a3d5c1cbc9856774ca00208753fb12
2024-09-21T04:01:16
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "bd8fe9972e3f17776e4e05e69e13ab8271d34132", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 1158, 1164 ], [ 1166, 1171 ] ], "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::optimize" ], "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 bd8fe9972e3f17776e4e05e69e13ab8271d34132 Author: Florian Hahn <[email protected]> Date: Sat Sep 21 12:45:36 2024 +0100 [VPlan] Mov licm to end of VPlan optimizations. This moves licm after expanding replicate regions. This fixes a crash when trying to hoist a predicated VPReplicateRecipes which later get expanded to replicate regions. Hoisting replicate regions out was not intended (see the discussion and at the review and comment on shallow traversal in licm()). Fixes https://github.com/llvm/llvm-project/issues/109510. diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 06ac15f52fe1..fd6090affbbf 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -1158,7 +1158,6 @@ void VPlanTransforms::optimize(VPlan &Plan) { removeRedundantInductionCasts(Plan); simplifyRecipes(Plan); - licm(Plan); legalizeAndOptimizeInductions(Plan); removeDeadRecipes(Plan); @@ -1166,6 +1165,7 @@ void VPlanTransforms::optimize(VPlan &Plan) { removeRedundantExpandSCEVRecipes(Plan); mergeBlocksIntoPredecessors(Plan); + licm(Plan); } // Add a VPActiveLaneMaskPHIRecipe and related recipes to \p Plan and replace
[ { "file": "llvm/test/Transforms/LoopVectorize/invariant-replicate-region.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "test_invariant_replicate_region", "test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128-Fn32\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\ndefine i32 @test_invariant_replicate_region(i32 %x, i1 %c) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %rem.1 = urem i32 10, %x\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %res = phi i32 [ 0, %loop.header ], [ %rem.1, %then ]\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 99\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "A/F: verifyVPlanIsValid(*Plan) && \"VPlan is invalid\" after a861ed411a", "body": "We have an internal test that recently started to hit an assertion failure which I bisected back to commit a861ed411a359b7cb2b58d642e4a7f2fdcf92057. \r\n\r\nConsider the following code:\r\n```c\r\nint g_78, g_659, func_32_l_1852;\r\nlong g_128;\r\nunsigned func_32_p_33;\r\nvoid func_32() {\r\n int *l_1145 = &g_659;\r\n *l_1145 = 0;\r\n short __trans_tmp_11;\r\n for (; g_78; g_78 += 1) {\r\n func_32_l_1852 = 0;\r\n for (; func_32_l_1852 <= 3; func_32_l_1852 += 1) {\r\n int *l_1863 = &g_659;\r\n __trans_tmp_11 = *l_1863;\r\n if (10 % ((__trans_tmp_11 >= 0) - func_32_p_33))\r\n break;\r\n ++g_128;\r\n *l_1863 = func_32_p_33 <= --g_128;\r\n }\r\n }\r\n}\r\n```\r\n\r\nIf compiled with optimizations and a compiler built from a861ed411a359b7cb2b58d642e4a7f2fdcf92057 you can see it hits an assertion failure:\r\n```\r\n$ ~/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang -c -O2 repro.c\r\nVPIRBasicBlock can only be used as pre-header or a successor of middle-block at the moment!\r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:8594: void llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount): Assertion `verifyVPlanIsValid(*Plan) && \"VPlan is invalid\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang -c -O2 repro.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"repro.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"func_32\"\r\n #0 0x00005572973a049f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x233549f)\r\n #1 0x000055729739dfec llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2332fec)\r\n #2 0x00005572972f0418 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f5d2a347420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #4 0x00007f5d29e1400b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #5 0x00007f5d29df3859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #6 0x00007f5d29df3729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #7 0x00007f5d29df3729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #8 0x00007f5d29e04fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #9 0x0000557298e08438 llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3d9d438)\r\n#10 0x0000557298e0878f llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3d9d78f)\r\n#11 0x0000557298e0a62e llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3d9f62e)\r\n#12 0x0000557298e0d501 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3da2501)\r\n#13 0x0000557298e0db73 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3da2b73)\r\n#14 0x0000557298836146 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x37cb146)\r\n#15 0x0000557296e5bd41 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x1df0d41)\r\n#16 0x0000557295f84cc6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xf19cc6)\r\n#17 0x0000557296e5a6ad llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x1def6ad)\r\n#18 0x0000557295f85686 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xf1a686)\r\n#19 0x0000557296e5a0e1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x1def0e1)\r\n#20 0x0000557297636863 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#21 0x0000557297639dbd clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x25cedbd)\r\n#22 0x0000557297d17c5c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cacc5c)\r\n#23 0x0000557299c7aa8c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x4c0fa8c)\r\n#24 0x0000557297d18078 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cad078)\r\n#25 0x0000557297fdf129 clang::FrontendAction::Execute() (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2f74129)\r\n#26 0x0000557297f5b6fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2ef06fe)\r\n#27 0x00005572980cba26 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x3060a26)\r\n#28 0x0000557295f09185 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xe9e185)\r\n#29 0x0000557295f00f0a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#30 0x0000557297d5e0cd void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#31 0x00005572972f0920 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2285920)\r\n#32 0x0000557297d5e6ef clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#33 0x0000557297d22274 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cb7274)\r\n#34 0x0000557297d2338d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cb838d)\r\n#35 0x0000557297d2b4a5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0x2cc04a5)\r\n#36 0x0000557295f0611b clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xe9b11b)\r\n#37 0x0000557295e3609b main (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xdcb09b)\r\n#38 0x00007f5d29df5083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#39 0x0000557295f0099e _start (/home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin/clang+0xe9599e)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 20.0.0 (https://github.com/llvm/llvm-project.git a861ed411a359b7cb2b58d642e4a7f2fdcf92057)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/a861ed411a359b7cb2b58d642e4a7f2fdcf92057-linux/bin\r\nBuild config: +assertions\r\n```\r\n\r\nBuilding with a compiler built from the commit that immediately preceded this one (37e5319a12ba47c18049728804d3d1e1b10c4eb4), you can see that the compilation succeeds.\r\n```\r\n$ ~/src/upstream/37e5319a12ba47c18049728804d3d1e1b10c4eb4-linux/bin/clang -c -O2 repro.c\r\n$\r\n```", "author": "dyung", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
58e05779b483bb3d9f734bd09f5cb2241431a0b7
113520
https://github.com/llvm/llvm-project/issues/113520
miscompilation
907c13638819b36ecc5154775217068b1a1f4cfc
2024-10-24T04:03:39
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e914421d7fbf22059ea2180233add0c914ec80f0", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 12068, 12075 ], [ 15784, 15791 ] ], "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::getTreeCost", "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 e914421d7fbf22059ea2180233add0c914ec80f0 Author: Alexey Bataev <[email protected]> Date: Thu Oct 24 08:57:07 2024 -0700 [SLP]Do correct signedness analysis for externally used scalars If the scalars is used externally is in the root node, it may have incorrect signedness info because of the conflict with the demanded bits analysis. Need to perform exact signedness analysis and compute it rather than rely on the precomputed value, which might be incorrect for alternate zext/sext nodes. Fixes #113520 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 012d85353f08..2afd02dae3a8 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -12068,8 +12068,9 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { auto It = MinBWs.find(Entry); if (It != MinBWs.end()) { auto *MinTy = IntegerType::get(F->getContext(), It->second.first); - unsigned Extend = - It->second.second ? Instruction::SExt : Instruction::ZExt; + unsigned Extend = isKnownNonNegative(EU.Scalar, SimplifyQuery(*DL)) + ? Instruction::ZExt + : Instruction::SExt; VecTy = getWidenedType(MinTy, BundleWidth); ExtraCost = TTI->getExtractWithExtendCost(Extend, EU.Scalar->getType(), VecTy, EU.Lane); @@ -15784,8 +15785,9 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, // to the larger type. ExV = Ex; if (Scalar->getType() != Ex->getType()) - ExV = Builder.CreateIntCast(Ex, Scalar->getType(), - MinBWs.find(E)->second.second); + ExV = Builder.CreateIntCast( + Ex, Scalar->getType(), + !isKnownNonNegative(Scalar, SimplifyQuery(*DL))); auto *I = dyn_cast<Instruction>(Ex); ScalarToEEs[Scalar].try_emplace(I ? I->getParent() : &F->getEntryBlock(),
[ { "file": "<issue>", "commands": [ "opt -S --passes=slp-vectorizer < %s" ], "tests": [ { "test_name": "add3_i96", "test_body": "@0 = external global i1\n\ndefine <3 x i32> @add3_i96.2(<3 x i32> %0, <3 x i32> %1) {\n %4 = extractelement <3 x i32> %0, i64 0\n %5 = sext i32 %4 to i64\n %6 = extractelement <3 x i32> %1, i64 0\n %7 = zext i32 %6 to i64\n %8 = add nuw nsw i64 %7, %5\n %9 = extractelement <3 x i32> %0, i64 1\n %10 = zext i32 %9 to i64\n %11 = extractelement <3 x i32> %1, i64 1\n %12 = zext i32 %11 to i64\n %13 = add nuw nsw i64 %12, %10\n %14 = lshr i64 %8, 32\n %15 = add nuw nsw i64 %13, %14\n %16 = extractelement <3 x i32> %0, i64 2\n %17 = extractelement <3 x i32> %1, i64 2\n %18 = add i32 %17, %16\n %19 = or i64 %15, 32\n %20 = trunc i64 %19 to i32\n %21 = add i32 %18, %17\n %22 = trunc i64 %8 to i32\n %23 = insertelement <3 x i32> %1, i32 %22, i32 0\n ret <3 x i32> %23\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "`slp-vectorizer` miscompilation", "body": "Alive2 report: https://alive2.llvm.org/ce/z/FmxNvP\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <3 x i32> @add3_i96.2(<3 x i32> %#0, <3 x i32> %#1) {\r\n#2:\r\n %#3 = extractelement <3 x i32> %#0, i64 0\r\n %#4 = sext i32 %#3 to i64\r\n %#5 = extractelement <3 x i32> %#1, i64 0\r\n %#6 = zext i32 %#5 to i64\r\n %#7 = add nsw nuw i64 %#6, %#4\r\n %#21 = trunc i64 %#7 to i32\r\n %#22 = insertelement <3 x i32> %#1, i32 %#21, i32 0\r\n ret <3 x i32> %#22\r\n}\r\n=>\r\ndefine <3 x i32> @add3_i96.2(<3 x i32> %#0, <3 x i32> %#1) {\r\n#2:\r\n %#3 = shufflevector <3 x i32> %#1, <3 x i32> %#0, 0, 3\r\n %#4 = extractelement <2 x i32> %#3, i32 0\r\n %#5 = sext i32 %#4 to i64\r\n %#6 = extractelement <2 x i32> %#3, i32 1\r\n %#7 = sext i32 %#6 to i64\r\n %#8 = add nsw nuw i64 %#5, %#7\r\n %#22 = trunc i64 %#8 to i32\r\n %#23 = insertelement <3 x i32> %#1, i32 %#22, i32 0\r\n ret <3 x i32> %#23\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<3 x i32> %#0 = < #x00000008 (8), #x00000000 (0), #x00000000 (0) >\r\n<3 x i32> %#1 = < #xfffffff9 (4294967289, -7), #x00000000 (0), #x00000000 (0) >\r\n\r\nSource:\r\ni32 %#3 = #x00000008 (8)\r\ni64 %#4 = #x0000000000000008 (8)\r\ni32 %#5 = #xfffffff9 (4294967289, -7)\r\ni64 %#6 = #x00000000fffffff9 (4294967289)\r\ni64 %#7 = #x0000000100000001 (4294967297)\r\ni32 %#21 = #x00000001 (1)\r\n<3 x i32> %#22 = < #x00000001 (1), #x00000000 (0), #x00000000 (0) >\r\n\r\nTarget:\r\n<2 x i32> %#3 = < #xfffffff9 (4294967289, -7), #x00000008 (8) >\r\ni32 %#4 = #xfffffff9 (4294967289, -7)\r\ni64 %#5 = #xfffffffffffffff9 (18446744073709551609, -7)\r\ni32 %#6 = #x00000008 (8)\r\ni64 %#7 = #x0000000000000008 (8)\r\ni64 %#8 = poison\r\ni32 %#22 = poison\r\n<3 x i32> %#23 = < poison, #x00000000 (0), #x00000000 (0) >\r\nSource value: < #x00000001 (1), #x00000000 (0), #x00000000 (0) >\r\nTarget value: < poison, #x00000000 (0), #x00000000 (0) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:SLPVectorizer" ], "comments": [] }
true
null
97586
https://github.com/llvm/llvm-project/issues/97586
crash
be7239e5a60927f5b4932f995dc4b57423ea8534
2024-07-03T14:47:17
[ "llvm/test/Transforms/LoopUnroll" ]
{ "fix_commit": "cff8d716bdf017a2af8eb8623257fd33ee43f30e", "components": [ "ScalarEvolution" ], "bug_location_lineno": { "llvm/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": [ [ 8412, 8418 ] ], "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::visitAndClearUsers" ], "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 cff8d716bdf017a2af8eb8623257fd33ee43f30e Author: v01dXYZ <[email protected]> Date: Tue Jul 9 09:14:33 2024 +0200 [SCEV] forgetValue: support (with-overflow-inst op0, op1) (#98015) The use-def walk in forgetValue() was skipping instructions with non-SCEVable types. However, SCEV may look past with.overflow intrinsics returning aggregates. Fixes #97586. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 430e1c6d8f8c..51cffac80876 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -8412,7 +8412,7 @@ void ScalarEvolution::visitAndClearUsers( SmallVectorImpl<const SCEV *> &ToForget) { while (!Worklist.empty()) { Instruction *I = Worklist.pop_back_val(); - if (!isSCEVable(I->getType())) + if (!isSCEVable(I->getType()) && !isa<WithOverflowInst>(I)) continue; ValueExprMapType::iterator It =
[ { "file": "llvm/test/Transforms/LoopUnroll/peel-loop-scev-invalidate-with-overflow-inst.ll", "commands": [ "opt < %s -S -passes='print<scalar-evolution>,loop-unroll<peeling;full-unroll-max=0>,print<scalar-evolution>' 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": ";\n; This test ensures that (extractvalue 0 (with-overflow-inst op0, op1))\n; is invalidated by LoopPeel when the operands of with-overflow-inst\n; are changed.\n;\n; In the following case, LoopPeel modifies the CFG into another one\n; with %bb7 not dominating %bb2 and %bb3 although %extractvalue is\n; still the step for the %bb3 loop. %call has been modified and uses\n; different operands but the SCEV value for %extractvalue has not been\n; invalidated and still refers to %load in its SCEV operands\n; (SCEV(%extractvalue) := -2 + -2 * %load).\n;\n; When LoopUnroll tries to compute the SCEV for the %bb3 Phi, the\n; stale data for %extractvalue is used whereas %load is not available\n; in %bb3 which is wrong.\n;\n; for more details and nice pictures: https://github.com/llvm/llvm-project/issues/97586\n;\n; Although the reason for the bug was in forgetValue, it is still relevant to\n; test if LoopPeel invalidates %extractvalue after changing %call.\n;\n; forgetValue only walks the users, so calling it on the IV Phis does not\n; invalidate %extractvalue (thus forgetLoop does not invalidate it too).\n; It has to be done by LoopPeel itself.\n\n\ndefine void @loop_peeling_smul_with_overflow() {\n; before loop-unroll\n; after loop-unroll\n;\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %phi = phi i32 [ 0, %bb ], [ %phi4, %bb3 ]\n br label %bb5\n\nbb2: ; preds = %bb7\n %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8, i32 -2)\n %extractvalue = extractvalue { i32, i1 } %call, 0\n br label %bb3\n\nbb3: ; preds = %bb3, %bb2\n %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]\n %add = add i32 %extractvalue, %phi4\n br i1 false, label %bb3, label %bb1\n\nbb5: ; preds = %bb7, %bb1\n %phi6 = phi i32 [ 1, %bb1 ], [ 0, %bb7 ]\n %icmp = icmp eq i32 %phi, 0\n br i1 %icmp, label %bb9, label %bb7\n\nbb7: ; preds = %bb5\n %load = load i32, ptr addrspace(1) null, align 4\n %add8 = add i32 %load, 1\n br i1 false, label %bb2, label %bb5\n\nbb9: ; preds = %bb5\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion Failure in `getSCEV` during loop unroll", "body": "```\r\n; ModuleID = '<stdin>'\r\nsource_filename = \"<stdin>\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @ham() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb3, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %phi4, %bb3 ]\r\n br label %bb5\r\n\r\nbb2: ; preds = %bb7\r\n %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8, i32 -2)\r\n %extractvalue = extractvalue { i32, i1 } %call, 0\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb3, %bb2\r\n %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]\r\n %add = add i32 %extractvalue, %phi4\r\n br i1 false, label %bb3, label %bb1\r\n\r\nbb5: ; preds = %bb7, %bb1\r\n %phi6 = phi i32 [ 1, %bb1 ], [ 0, %bb7 ]\r\n %icmp = icmp eq i32 %phi, 0\r\n br i1 %icmp, label %bb9, label %bb7\r\n\r\nbb7: ; preds = %bb5\r\n %load = load i32, ptr addrspace(1) null, align 4\r\n %add8 = add i32 %load, 1\r\n br i1 false, label %bb2, label %bb5\r\n\r\nbb9: ; preds = %bb5\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\ncrashes with the below backtrace when run with `opt --passes=\"print<scalar-evolution>,loop-unroll<no-partial;peeling;no-runtime;no-upperbound;no-profile-peeling;full-unroll-max=0;O3> <filename.ll>\"` \r\n```\r\nopt: /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:3678: const llvm::SCEV* llvm::ScalarEvolution::getAddRecExpr(llvm::SmallVectorImpl<const llvm::SCEV*>&, const llvm::Loop*, llvm::SCEV::NoWrapFlags): Assertion `isAvailableAtLoopEntry(Operands[i], L) && \"SCEVAddRecExpr operand is not available at loop entry!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /home/manishkh/Workspace7/orcaInstall/installDA/bin/opt --passes=print<scalar-evolution>,loop-unroll<no-partial;peeling;no-runtime;no-upperbound;no-profile-peeling;full-unroll-max=0;O3> reduced2.ll -disable-output\r\n #0 0x00007f272f49aa72 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/manishkh/Workspace7/orca/llvm/lib/Support/Unix/Signals.inc:723:0\r\n #1 0x00007f272f49aeaf PrintStackTraceSignalHandler(void*) /home/manishkh/Workspace7/orca/llvm/lib/Support/Unix/Signals.inc:798:0\r\n #2 0x00007f272f498793 llvm::sys::RunSignalHandlers() /home/manishkh/Workspace7/orca/llvm/lib/Support/Signals.cpp:105:0\r\n #3 0x00007f272f49a459 SignalHandler(int) /home/manishkh/Workspace7/orca/llvm/lib/Support/Unix/Signals.inc:413:0\r\n #4 0x00007f2738fd7630 __restore_rt sigaction.c:0:0\r\n #5 0x00007f272b893387 raise (/lib64/libc.so.6+0x36387)\r\n #6 0x00007f272b894a78 abort (/lib64/libc.so.6+0x37a78)\r\n #7 0x00007f272b88c1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)\r\n #8 0x00007f272b88c252 (/lib64/libc.so.6+0x2f252)\r\n #9 0x00007f2732031da6 llvm::ScalarEvolution::getAddRecExpr(llvm::SmallVectorImpl<llvm::SCEV const*>&, llvm::Loop const*, llvm::SCEV::NoWrapFlags) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:3677:0\r\n#10 0x00007f2732031b29 llvm::ScalarEvolution::getAddRecExpr(llvm::SCEV const*, llvm::SCEV const*, llvm::Loop const*, llvm::SCEV::NoWrapFlags) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:3660:0\r\n#11 0x00007f2732039c11 llvm::ScalarEvolution::createSimpleAffineAddRec(llvm::PHINode*, llvm::Value*, llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:5776:0\r\n#12 0x00007f2732039f65 llvm::ScalarEvolution::createAddRecFromPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:5831:0\r\n#13 0x00007f273203aadf llvm::ScalarEvolution::createNodeForPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:6025:0\r\n#14 0x00007f273204562a llvm::ScalarEvolution::createSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8069:0\r\n#15 0x00007f2732042338 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:7447:0\r\n#16 0x00007f2732035a05 llvm::ScalarEvolution::getSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:4572:0\r\n#17 0x00007f273203ab71 llvm::ScalarEvolution::createNodeForPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:6029:0\r\n#18 0x00007f273204562a llvm::ScalarEvolution::createSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8069:0\r\n#19 0x00007f2732042338 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:7447:0\r\n#20 0x00007f2732035a05 llvm::ScalarEvolution::getSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:4572:0\r\n#21 0x00007f2732039fcf llvm::ScalarEvolution::createAddRecFromPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:5840:0\r\n#22 0x00007f273203aadf llvm::ScalarEvolution::createNodeForPHI(llvm::PHINode*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:6025:0\r\n#23 0x00007f273204562a llvm::ScalarEvolution::createSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8069:0\r\n#24 0x00007f2732042338 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:7447:0\r\n#25 0x00007f2732035a05 llvm::ScalarEvolution::getSCEV(llvm::Value*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:4572:0\r\n#26 0x00007f273204a26a llvm::ScalarEvolution::computeExitLimitFromICmp(llvm::Loop const*, llvm::ICmpInst*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:9117:0\r\n#27 0x00007f273204971e llvm::ScalarEvolution::computeExitLimitFromCondImpl(llvm::ScalarEvolution::ExitLimitCache&, llvm::Loop const*, llvm::Value*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8975:0\r\n#28 0x00007f273204955b llvm::ScalarEvolution::computeExitLimitFromCondCached(llvm::ScalarEvolution::ExitLimitCache&, llvm::Loop const*, llvm::Value*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8958:0\r\n#29 0x00007f27320491a4 llvm::ScalarEvolution::computeExitLimitFromCond(llvm::Loop const*, llvm::Value*, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8914:0\r\n#30 0x00007f2732048f49 llvm::ScalarEvolution::computeExitLimit(llvm::Loop const*, llvm::BasicBlock*, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8888:0\r\n#31 0x00007f27320488db llvm::ScalarEvolution::computeBackedgeTakenCount(llvm::Loop const*, bool) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8797:0\r\n#32 0x00007f27320469fb llvm::ScalarEvolution::getBackedgeTakenInfo(llvm::Loop const*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8358:0\r\n#33 0x00007f27320464ab llvm::ScalarEvolution::getExitCount(llvm::Loop const*, llvm::BasicBlock const*, llvm::ScalarEvolution::ExitCountKind) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8270:0\r\n#34 0x00007f27320460c6 llvm::ScalarEvolution::getSmallConstantTripCount(llvm::Loop const*, llvm::BasicBlock const*) /home/manishkh/Workspace7/orca/llvm/lib/Analysis/ScalarEvolution.cpp:8203:0\r\n#35 0x00007f273146141a tryToUnrollLoop(llvm::Loop*, llvm::DominatorTree&, llvm::LoopInfo*, llvm::ScalarEvolution&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, bool, int, bool, bool, bool, std::optional<unsigned int>, std::optional<unsigned int>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<bool>, std::optional<unsigned int>, llvm::AAResults*) /home/manishkh/Workspace7/orca/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp:1259:0\r\n#36 0x00007f2731462e2c llvm::LoopUnrollPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp:1658:0\r\n#37 0x00007f27339727ac llvm::detail::PassModel<llvm::Function, llvm::LoopUnrollPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManagerInternal.h:91:0\r\n#38 0x00007f272f831f82 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManager.h:228:0\r\n#39 0x00007f27331d1e32 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManagerInternal.h:91:0\r\n#40 0x00007f272f830d12 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/manishkh/Workspace7/orca/llvm/lib/IR/PassManager.cpp:128:0\r\n#41 0x00007f27331d1d96 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManagerInternal.h:91:0\r\n#42 0x00007f272f831c5a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/manishkh/Workspace7/orca/llvm/include/llvm/IR/PassManager.h:228:0\r\n#43 0x00000000004acc3e llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /home/manishkh/Workspace7/orca/llvm/tools/opt/NewPMDriver.cpp:559:0\r\n#44 0x0000000000477a33 optMain /home/manishkh/Workspace7/orca/llvm/tools/opt/optdriver.cpp:756:0\r\n#45 0x000000000047540f main /home/manishkh/Workspace7/orca/llvm/tools/opt/opt.cpp:25:0\r\n#46 0x00007f272b87f555 __libc_start_main (/lib64/libc.so.6+0x22555)\r\n#47 0x00000000004752c9 _start (/home/manishkh/Workspace7/orcaInstall/installDA/bin/opt+0x4752c9)\r\n```\r\n\r\nas demonstrated by this godbolt example: https://godbolt.org/z/be3a4Yr9e", "author": "Nirhar", "labels": [ "llvm:crash", "llvm:SCEV" ], "comments": [ { "author": "Nirhar", "body": "I did some preliminary analysis on this bug, and here is what I found:\r\nThe IR at the point of crash looks like this:\r\n```\r\ndefine zing void @ham() {\r\nbb:\r\n br label %bb1\r\n\r\nbb1.loopexit: ; preds = %bb3\r\n %phi4.lcssa = phi i32 [ %phi4, %bb3 ]\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1.loopexit, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %phi4.lcssa, %bb1.loopexit ]\r\n br label %bb5.peel.begin\r\n\r\nbb5.peel.begin: ; preds = %bb1\r\n br label %bb5.peel\r\n\r\nbb5.peel: ; preds = %bb5.peel.begin, exiting\r\n %icmp.peel = icmp eq i32 %phi, 0\r\n br i1 %icmp.peel, label %bb9.loopexit2, label %bb7.peel\r\n\r\nbb7.peel: ; preds = %bb5.peel\r\n %load.peel = load i32, ptr addrspace(1) null, align 4\r\n %add8.peel = add i32 %load.peel, 1\r\n br i1 false, label %bb2, label %bb5.peel.next\r\n\r\nbb5.peel.next: ; preds = %bb7.peel\r\n br label %bb5.peel.next1\r\n\r\nbb5.peel.next1: ; preds = %bb5.peel.next\r\n br label %bb1.peel.newph\r\n\r\nbb1.peel.newph: ; preds = %bb5.peel.next1\r\n br label %bb5\r\n\r\nbb2.loopexit: ; preds = %bb7\r\n %add8.lcssa.ph = phi i32 [ %add8, %bb7 ]\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb2.loopexit, %bb7.peel\r\n %add8.lcssa = phi i32 [ %add8.peel, %bb7.peel ], [ %add8.lcssa.ph, %bb2.loopexit ]\r\n %call = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %add8.lcssa, i32 -2)\r\n %extractvalue = extractvalue { i32, i1 } %call, 0\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb3, %bb2\r\n %phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]\r\n %add = add i32 %extractvalue, %phi4\r\n br i1 false, label %bb3, label %bb1.loopexit\r\n\r\nbb5: ; preds = %bb7, %bb1.peel.newph, exiting\r\n br i1 false, label %bb9.loopexit, label %bb7\r\n\r\nbb7: ; preds = %bb5\r\n %load = load i32, ptr addrspace(1) null, align 4 \r\n %add8 = add i32 %load, 1\r\n br i1 false, label %bb2.loopexit, label %bb5, !llvm.loop !0\r\n\r\nbb9.loopexit: ; preds = %bb5\r\n br label %bb9\r\n\r\nbb9.loopexit2: ; preds = %bb5.peel\r\n br label %bb9\r\n\r\nbb9: ; preds = %bb9.loopexit2, %bb9.loopexit\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\nWe have 3 loops in this this IR(1 outer and 2 inner, out of which the bb5-bb7 loop has been peeled.):\r\n```\r\nLoop at depth 1 containing: %bb1<header>,%bb5<exiting>,%bb7,%bb2,%bb3,%bb1.loopexit<latch>,%bb5.peel.begin,%bb5.peel.next,%bb1.peel.newph,%bb5.peel<exiting>,%bb7.peel,%bb5.peel.next1\r\n Loop at depth 2 containing: %bb5<header><exiting>,%bb7<latch><exiting>\r\n Loop at depth 2 containing: %bb3<header><latch><exiting>\r\n``` \r\nHere is the CFG for this IR:\r\n![Screenshot 2024-07-03 at 8 24 52 PM](https://github.com/llvm/llvm-project/assets/46352931/02e57740-9ef6-4945-868e-62a645325552)\r\n\r\nThe assertion fails because SCEV expects bb7 to properly dominate bb3, which it does in the old IR, but after peeling, it does not. This seems to arise from the fact that SCEVs in %bb2 have not been invalidated after the peeling. I see that the SCEV for `%extractvalue` comes from the ValueExprMap instead of being recomputed, following the peel, and the use of this invalid SCEV is what I think is causing the problem.\r\n\r\n\r\n" }, { "author": "Nirhar", "body": "Perhaps these updates to SE are not enough?\r\nhttps://github.com/llvm/llvm-project/blob/86d456ad8f2aef6edcc36d44d26119025331981e/llvm/lib/Transforms/Utils/LoopPeel.cpp#L1088-L1090" }, { "author": "Nirhar", "body": "@nikic @fhahn @RKSimon is `forgetTopmostLoop` supposed to forget SCEV of all SSA values inside the loop(ie, header, latch and other blocks) ? I see that its implementation does not do that currently." }, { "author": "nikic", "body": "@Nirhar Generally no. It forgets information about induction variables (things based on loop header phis), as well as information pertaining to the loop (such as BECounts, exit values etc), but not of literally everything defined in the loop." }, { "author": "nikic", "body": "From a super quick look, the issue here might be that the exit phi forgetValue() calls don't invalidate enough values due to the condition at https://github.com/llvm/llvm-project/blob/e55585fd7bddf5bb3824a53cbe2971206d3c20c6/llvm/lib/Analysis/ScalarEvolution.cpp#L8415, which means that we will stop at the aggregate results of with.overflow intrinsics, even though SCEV can look through them. It might be that they need special handling." }, { "author": "v01dXYZ", "body": "When replacing the `smul.with.overflow + extractvalue` by a `mul`, it doesn't abort.\r\nWhen removing the SCEVable check, it doesn't abort.\r\n\r\nThe function that allows to traverse unSCEVable when creating the SCEV is `MatchBinaryOp` (cf `createSimpleAffineRec`). We could make this function returns a subset of the use-def to SCEVable or have another function that do the reverse with a def-use matching." }, { "author": "Nirhar", "body": "I think that the issue might be something else. From my analysis, here is how the control flow goes:\r\n1. When we hit `forgetTopmostLoop`, we try to forget the SCEV values of the loop:\r\n```\r\nLoop at depth 1 containing: %bb1<header>,%bb5<exiting>,%bb7,%bb2,%bb3,%bb1.loopexit<latch>,%bb5.peel.begin,%bb5.peel.next,%bb1.peel.newph,%bb5.peel<exiting>,%bb7.peel,%bb5.peel.next1\r\n Loop at depth 2 containing: %bb5<header><exiting>,%bb7<latch><exiting>\r\n Loop at depth 2 containing: %bb3<header><latch><exiting>\r\n```\r\nWe first take the phi node in the header `%phi = phi i32 [ 0, %bb ], [ %phi4.lcssa, %bb1.loopexit ]` and start the DFS from there. From here, we go to the following nodes:(` %icmp.peel = icmp eq i32 %phi, 0` , ` br i1 %icmp.peel, label %bb9.loopexit2, label %bb7.peel` and now non existent `%icmp = icmp eq i32 %phi, 0` , `br i1 %icmp, label %bb9, label %bb7`. The DFS for the outer loop ends here.\r\n\r\n2. Next we traverse the inner loop:\r\n```\r\nLoop at depth 2 containing: %bb3<header><latch><exiting>\r\n```\r\nHere we start with phi node in the header `%phi4 = phi i32 [ %add, %bb3 ], [ 0, %bb2 ]` and then traverse through the nodes: `%add = add i32 %extractvalue, %phi4` and `%phi4.lcssa = phi i32 [ %phi4, %bb3 ]`, after which we quit traversal.\r\n\r\n3. Finally we visit the inner loop:\r\n```\r\nLoop at depth 2 containing: %bb5<header><exiting>,%bb7<latch><exiting>\r\n```\r\nWe start and end DFS at (now non-existent)`%phi6 = phi i32 [ 0, %bb1.peel.newph ], [ 0, %bb7 ]`.\r\n\r\n**_TLDR_**; Throughout the entire traversal, we never visit the basic block bb2, and never invalidate its SCEV values. We don't even visit smul intrinsic call to forget its SCEV. Perhaps one needs to consider use-def chains to forget SCEV values, similar to the now considered def-use chain.\r\n\r\nNote: The IR at the point of crash is slightly different from the IR after the previous loop-peel. I've used the term `now non-existent` to mean that that node is not present in the IR at the crash point." }, { "author": "nikic", "body": "@Nirhar The forgetTopmostLoop() call is not what is responsible for the invalidation here, it's the forgetValue() call on the LCSSA phis in https://github.com/llvm/llvm-project/blob/27ccc8835e5163484234549fa6128eeb00d7432d/llvm/lib/Transforms/Utils/LoopPeel.cpp#L862" }, { "author": "Nirhar", "body": "Aah sorry, I missed that. Thanks for pointing it out!" } ] }
true
null
114860
https://github.com/llvm/llvm-project/issues/114860
crash
7dffc96a54f90569d6226dd5713c80fc8f30c76f
2024-11-04T20:12:18
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "144bdf3eb7128518ed162c5a168e3ec90922cd9e", "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": [ [ 7521, 7526 ] ], "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::computeBestVF" ], "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 144bdf3eb7128518ed162c5a168e3ec90922cd9e Author: Florian Hahn <[email protected]> Date: Fri Nov 8 20:53:03 2024 +0000 [VPlan] Also check if plan for best legacy VF contains simplifications. The plan for the VF chosen by the legacy cost model could also contain additional simplifications that cause cost differences. Also check if it contains simplifications. Fixes https://github.com/llvm/llvm-project/issues/114860. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index c07af8519049..82d85b112397 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7521,6 +7521,8 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() { precomputeCosts(BestPlan, BestFactor.Width, CostCtx); assert((BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), + CostCtx, OrigLoop) || + planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width), CostCtx, OrigLoop)) && " VPlan cost model and legacy cost model disagreed"); assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) &&
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/select-invariant-cond-cost.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "test_invariant_cond_for_select", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_invariant_cond_for_select(ptr %dst, i8 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %c.1 = icmp eq i8 %x, 0\n %c.2 = icmp sgt i64 %iv, 0\n %c.2.ext = zext i1 %c.2 to i64\n %sel = select i1 %c.1, i64 %c.2.ext, i64 0\n %sel.trunc = trunc i64 %sel to i8\n %gep = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %sel.trunc, ptr %gep, align 1\n %iv.next = add i64 %iv, 4\n %ec = icmp ult i64 %iv, 14\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Testcase:\r\n```c\r\nextern char a[];\r\nchar *b;\r\nint c = 40502824327348188;\r\nlong d[9][9];\r\nint main() {\r\n for (long e = 0; e < 9; ++e)\r\n for (long f = 0; f < 9; ++f)\r\n d[e][f] = 6032102684657866;\r\n for (unsigned char f = b[4]; f < 18; f += c - 216)\r\n a[f] = f % 2 ? d[f][f] : d[f][f] + 2036854775807 > 0;\r\n}\r\n```\r\n```\r\n/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -I/scratch/tc-testing/compiler-fuzz-ci/csmith-build/include -fsigned-char -fno-strict-aliasing -fwrapv -march=rv64gcv -flto -O3 -fuse-ld=lld red.c -o rv64gcv.out\r\n```\r\n\r\n\r\nReduced 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 i32 @main() #0 {\r\nentry:\r\n br label %for.body15\r\n\r\nfor.cond.cleanup14.loopexit: ; preds = %for.body15\r\n ret i32 0\r\n\r\nfor.body15: ; preds = %for.body15, %entry\r\n %indvars.iv1 = phi i64 [ %indvars.iv.next, %for.body15 ], [ 0, %entry ]\r\n %tobool.not = icmp eq i8 0, 0\r\n %cmp24 = icmp sgt i64 %indvars.iv1, 0\r\n %conv26 = zext i1 %cmp24 to i64\r\n %cond = select i1 %tobool.not, i64 %conv26, i64 0\r\n %conv27 = trunc i64 %cond to i8\r\n store i8 %conv27, ptr null, align 1\r\n %indvars.iv.next = add i64 %indvars.iv1, 4\r\n %cmp12 = icmp ult i64 %indvars.iv1, 14\r\n br i1 %cmp12, label %for.body15, label %for.cond.cleanup14.loopexit\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-ssctr,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zacas,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\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 -f\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/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.\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 -f\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 0x00005f3d9fc9dc00 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3169c00)\r\n #1 0x00005f3d9fc9b00f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x316700f)\r\n #2 0x00005f3d9fc9b165 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007abb28242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007abb282969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007abb282969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007abb282969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007abb28242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007abb282287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007abb2822871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007abb28239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005f3d9ebfb878 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20c7878)\r\n#12 0x00005f3d9ec12dec llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20dedec)\r\n#13 0x00005f3d9ec15f01 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20e1f01)\r\n#14 0x00005f3d9ec16577 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20e2577)\r\n#15 0x00005f3d9da0cba6 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+0xed8ba6)\r\n#16 0x00005f3d9faa518f 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+0x2f7118f)\r\n#17 0x00005f3d9da0fdd6 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+0xedbdd6)\r\n#18 0x00005f3d9faa351b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f6f51b)\r\n#19 0x00005f3d9da0bc66 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+0xed7c66)\r\n#20 0x00005f3d9faa407d 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+0x2f7007d)\r\n#21 0x00005f3d9d20ca8d 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+0x6d8a8d)\r\n#22 0x00005f3d9d1fe911 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6ca911)\r\n#23 0x00007abb28229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007abb28229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007abb28229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005f3d9d1f4e65 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6c0e65)\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 on Oct 24th\r\n\r\nGodbolt: https://godbolt.org/z/zhseEjTso\r\n\r\ncc @fhahn ", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
81415
https://github.com/llvm/llvm-project/issues/81415
crash
0ea64ad88abcbb939547a92000d98efb2b00d95f
2024-02-11T14:16:02
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "0dacba3ad1b5214ca35eda14987c0b76568a070e", "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": [ [ 977, 985 ], [ 990, 1000 ] ], "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 0dacba3ad1b5214ca35eda14987c0b76568a070e Author: Florian Hahn <[email protected]> Date: Fri Feb 16 12:58:39 2024 +0000 [VPlan] Handle truncating ICMPs in truncateToMinimalBWs. Update truncateToMinimalBitwidths to handle truncating ICMPs. For ICMPs, the new target type will be the same as the original type. In that case, only truncate the operands, but skip the extend. This is in line with what the original truncateToMinimalBitwidths did for compares. Fixes https://github.com/llvm/llvm-project/issues/81415. diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 16855a9227a1..99198cfa9955 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -977,9 +977,6 @@ void VPlanTransforms::truncateToMinimalBitwidths( Type *OldResTy = TypeInfo.inferScalarType(ResultVPV); unsigned OldResSizeInBits = OldResTy->getScalarSizeInBits(); assert(OldResTy->isIntegerTy() && "only integer types supported"); - if (OldResSizeInBits == NewResSizeInBits) - continue; - assert(OldResSizeInBits > NewResSizeInBits && "Nothing to shrink?"); (void)OldResSizeInBits; auto *NewResTy = IntegerType::get(Ctx, NewResSizeInBits); @@ -990,11 +987,17 @@ void VPlanTransforms::truncateToMinimalBitwidths( 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 (OldResSizeInBits != NewResSizeInBits) { + // Extend result to original width. + auto *Ext = + new VPWidenCastRecipe(Instruction::ZExt, ResultVPV, OldResTy); + Ext->insertAfter(&R); + ResultVPV->replaceAllUsesWith(Ext); + 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."); if (isa<VPWidenMemoryInstructionRecipe>(&R)) { assert(!cast<VPWidenMemoryInstructionRecipe>(&R)->isStore() && "stores cannot be narrowed");
[ { "file": "llvm/test/Transforms/LoopVectorize/trunc-reductions.ll", "commands": [ "opt -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=8 -S < %s" ], "tests": [ { "test_name": "reduction_and_or", "test_body": "define i32 @reduction_and_or(i16 %a, i32 %b, ptr %src) {\nentry:\n %ext1 = zext i16 %a to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %or67 = phi i32 [ 10, %entry ], [ %or, %loop ]\n %t = trunc i32 %b to i16\n %ext = sext i16 %t to i32\n %cmp = icmp sgt i32 %ext, %ext1\n %ext2 = zext i1 %cmp to i32\n %cmp3 = icmp sge i32 %iv, %ext2\n %ext4 = zext i1 %cmp3 to i32\n %div = sdiv i32 %ext4, %b\n %and = and i32 %div, 0\n %gep = getelementptr inbounds i32, ptr %src, i32 %iv\n %l = load i32, ptr %gep, align 4\n %add = add i32 %and, %l\n %or = or i32 %or67, %add\n %iv.next = add nsw i32 %iv, 1\n %tobool.not = icmp eq i32 %iv.next, 999\n br i1 %tobool.not, label %exit, label %loop\n\nexit: ; preds = %loop\n %or.lcssa = phi i32 [ %or, %loop ]\n ret i32 %or.lcssa\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "clang crashes at -O{s,2,3} on x86_64-linux-gnu: Assertion `MinBWs.size() == NumProcessedRecipes && \"some entries in MinBWs haven't been processed\"' failed", "body": "It appears to be a recent regression as it does not reproduce with 17.0.1 and earlier versions.\r\n\r\nCompiler Explorer: https://godbolt.org/z/vGGoa684a\r\n\r\n```\r\n[511] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 5932fcc47855fdd209784f38820422d2369b84b2)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/opfuzz/bin\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[512] % \r\n[512] % clangtk -Os small.c\r\nclang-19: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:1038: static void llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan&, const llvm::MapVector<llvm::Instruction*, long unsigned int>&, 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, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-19 -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/20240211-clangtk-m64-Os-Weverything-pipe-fPIC-build-024130/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20240211-clangtk-m64-Os-Weverything-pipe-fPIC-build-024130/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/19 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-d74fff.o -x c small.c\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n #0 0x000055fb61397fcf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3f04fcf)\r\n #1 0x000055fb613954f4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fdd88b17420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007fdd8851e00b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007fdd884fd859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007fdd884fd729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007fdd884fd729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007fdd8850efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x000055fb62c44895 llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan&, llvm::MapVector<llvm::Instruction*, unsigned long, llvm::DenseMap<llvm::Instruction*, unsigned int, llvm::DenseMapInfo<llvm::Instruction*, void>, llvm::detail::DenseMapPair<llvm::Instruction*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Instruction*, unsigned long>, 0u>> const&, llvm::LLVMContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x57b1895)\r\n #9 0x000055fb62b2644a llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x569344a)\r\n#10 0x000055fb62b2d861 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x569a861)\r\n#11 0x000055fb62b30a1f llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x569da1f)\r\n#12 0x000055fb62b33acd 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*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56a0acd)\r\n#13 0x000055fb62b34d20 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56a1d20)\r\n#14 0x000055fb62717536 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-19+0x5284536)\r\n#15 0x000055fb5ea6d61d 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-19+0x15da61d)\r\n#16 0x000055fb60d5cb3d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x38c9b3d)\r\n#17 0x000055fb5ea509a6 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-19+0x15bd9a6)\r\n#18 0x000055fb60d5aa6d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x38c7a6d)\r\n#19 0x000055fb6161dc90 (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 0x000055fb61620f60 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#21 0x000055fb616215cb 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-19+0x418e5cb)\r\n#22 0x000055fb61c5730a clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x47c430a)\r\n#23 0x000055fb63944ee9 clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x64b1ee9)\r\n#24 0x000055fb61c566a8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x47c36a8)\r\n#25 0x000055fb61ed4429 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4a41429)\r\n#26 0x000055fb61e508de clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x49bd8de)\r\n#27 0x000055fb61fb8d46 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4b25d46)\r\n#28 0x000055fb5e655986 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x11c2986)\r\n#29 0x000055fb5e64cfba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#30 0x000055fb5e652434 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x11bf434)\r\n#31 0x000055fb5e564aab main (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x10d1aab)\r\n#32 0x00007fdd884ff083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#33 0x000055fb5e64ca7e _start (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x11b9a7e)\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 19.0.0git (https://github.com/llvm/llvm-project.git 5932fcc47855fdd209784f38820422d2369b84b2)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/opfuzz/bin\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-ca7a0b.c\r\nclangtk: note: diagnostic msg: /tmp/small-ca7a0b.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[513] % \r\n[513] % cat small.c\r\nstatic int *a, **b = &a, f = 1;\r\nint c, d, h;\r\nshort e, g;\r\nint main() {\r\n int **i[9] = {&a, &a, &a, &a, &a, &a, &a, &a, &a};\r\n for (; d; d++)\r\n if ((**b < e) | f) {\r\n int *j = &f, k;\r\n c = h;\r\n k = g > ((long)j == 1);\r\n }\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "zhendongsu", "body": "Another related test that reproduces the crash only at -Os.\r\n\r\n```\r\n[513] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git e769fb8699e3fa8e40623764f7713bfc783b0330)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/opfuzz/bin\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[514] % \r\n[514] % clangtk -Os small.c\r\nclang-19: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp:1038: static void llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan&, const llvm::MapVector<llvm::Instruction*, long unsigned int>&, 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, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-19 -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/DUP/20240215-clangtk-m64-Os-Weverything-pipe-fPIC-build-144944/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/DUP/20240215-clangtk-m64-Os-Weverything-pipe-fPIC-build-144944/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/19 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Os -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-a3d3db.o -x c small.c\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n #0 0x000055bf09b51e2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x3f38e2f)\r\n #1 0x000055bf09b4f354 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fdb52bbc420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007fdb525c300b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007fdb525a2859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007fdb525a2729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007fdb525a2729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007fdb525b3fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x000055bf0b405565 llvm::VPlanTransforms::truncateToMinimalBitwidths(llvm::VPlan&, llvm::MapVector<llvm::Instruction*, unsigned long, llvm::DenseMap<llvm::Instruction*, unsigned int, llvm::DenseMapInfo<llvm::Instruction*, void>, llvm::detail::DenseMapPair<llvm::Instruction*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Instruction*, unsigned long>, 0u>> const&, llvm::LLVMContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x57ec565)\r\n #9 0x000055bf0b2e62ba llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56cd2ba)\r\n#10 0x000055bf0b2ed661 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56d4661)\r\n#11 0x000055bf0b2f081f llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56d781f)\r\n#12 0x000055bf0b2f38cd 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*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56da8cd)\r\n#13 0x000055bf0b2f4b20 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x56dbb20)\r\n#14 0x000055bf0aed6086 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-19+0x52bd086)\r\n#15 0x000055bf0721ff8d 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-19+0x1606f8d)\r\n#16 0x000055bf0951611d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x38fd11d)\r\n#17 0x000055bf072032e6 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-19+0x15ea2e6)\r\n#18 0x000055bf0951404d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x38fb04d)\r\n#19 0x000055bf09dd88c0 (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 0x000055bf09ddbb80 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#21 0x000055bf09ddc1eb 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-19+0x41c31eb)\r\n#22 0x000055bf0a41298a clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x47f998a)\r\n#23 0x000055bf0c10e439 clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x64f5439)\r\n#24 0x000055bf0a411d18 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x47f8d18)\r\n#25 0x000055bf0a6903e9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4a773e9)\r\n#26 0x000055bf0a60d21e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x49f421e)\r\n#27 0x000055bf0a776736 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x4b5d736)\r\n#28 0x000055bf06e06b76 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x11edb76)\r\n#29 0x000055bf06dfe1aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#30 0x000055bf06e03624 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x11ea624)\r\n#31 0x000055bf06d15abb main (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x10fcabb)\r\n#32 0x00007fdb525a4083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#33 0x000055bf06dfdc6e _start (/local/suz-local/software/local/clang-trunk/bin/clang-19+0x11e4c6e)\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 19.0.0git (https://github.com/llvm/llvm-project.git e769fb8699e3fa8e40623764f7713bfc783b0330)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/opfuzz/bin\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-585ede.c\r\nclangtk: note: diagnostic msg: /tmp/small-585ede.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[515] % \r\n[515] % cat small.c\r\nint a = 1, b, c, d;\r\nshort e() { return a == 1 ? a : a % b; }\r\nstatic int f;\r\nshort g;\r\nunsigned short h;\r\nint main() {\r\n int *i[10] = {&f};\r\n for (c = -2; c; c++) {\r\n g = e();\r\n d |= f & ((b >= (g > h)) / a);\r\n }\r\n return 0;\r\n}\r\n```" }, { "author": "fhahn", "body": "Thanks for the test case, should be fixed! \r\n\r\nIt looks like this only gets triggered when the resulting truncated compare is dead. Please let me know if you see any issues with similar cases where the resulting loop/compares in the loop aren't dead." } ] }
true
null
97600
https://github.com/llvm/llvm-project/issues/97600
miscompilation
97a2bd8415dc6792b99ec0f091ad7570673c3f37
2024-07-03T16:13:45
[ "llvm/test/Analysis/BasicAA" ]
{ "fix_commit": "ebab105670a409e426ddcb0278578711a622b1b2", "components": [ "IR", "ValueTracking" ], "bug_location_lineno": { "llvm/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": [ [ 6403, 6411 ] ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": [ [ 652, 660 ] ], "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::getUnderlyingObject" ], "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Value.cpp": [ "stripPointerCastsAndOffsets" ], "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 ebab105670a409e426ddcb0278578711a622b1b2 Author: Nikita Popov <[email protected]> Date: Thu Jul 4 09:43:16 2024 +0200 [IR] Don't strip through pointer to vector of pointer bitcasts When using stripPointerCasts() and getUnderlyingObject(), don't strip through a bitcast from ptr to <1 x ptr>, which is not a no-op pointer cast. Calling code is generally not prepared to handle that situation, resulting in incorrect alias analysis results for example. Fixes https://github.com/llvm/llvm-project/issues/97600. diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 5476dc5d8518..258576f0cdff 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6403,9 +6403,10 @@ const Value *llvm::getUnderlyingObject(const Value *V, unsigned MaxLookup) { V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast || Operator::getOpcode(V) == Instruction::AddrSpaceCast) { - V = cast<Operator>(V)->getOperand(0); - if (!V->getType()->isPointerTy()) + Value *NewV = cast<Operator>(V)->getOperand(0); + if (!NewV->getType()->isPointerTy()) return V; + V = NewV; } else if (auto *GA = dyn_cast<GlobalAlias>(V)) { if (GA->isInterposable()) return V; diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 8522747ccf12..b2ee75811fbb 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -652,9 +652,10 @@ static const Value *stripPointerCastsAndOffsets( } V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast) { - V = cast<Operator>(V)->getOperand(0); - if (!V->getType()->isPointerTy()) + Value *NewV = cast<Operator>(V)->getOperand(0); + if (!NewV->getType()->isPointerTy()) return V; + V = NewV; } else if (StripKind != PSK_ZeroIndicesSameRepresentation && Operator::getOpcode(V) == Instruction::AddrSpaceCast) { // TODO: If we know an address space cast will not change the
[ { "file": "llvm/test/Analysis/BasicAA/ptr-vector.ll", "commands": [ "opt -S -passes=licm < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "@c = dso_local global i32 0, align 4\n@d = dso_local local_unnamed_addr global ptr @c, align 8\n\ndefine i32 @main() {\nentry:\n br label %for.cond\n\nfor.cond: ; preds = %f.exit.split, %entry\n %b.0 = phi i32 [ 0, %entry ], [ %inc6, %f.exit.split ]\n %cmp = icmp ult i32 %b.0, 2\n br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup\n\nfor.cond1.preheader: ; preds = %for.cond\n br label %for.cond1\n\nfor.cond.cleanup: ; preds = %for.cond\n %0 = load i32, ptr @c, align 4, !tbaa !13\n %retval = xor i32 %0, 7\n ret i32 %retval\n\nfor.cond1: ; preds = %for.cond1, %for.cond1.preheader\n %i.0 = phi i32 [ %inc, %for.cond1 ], [ 0, %for.cond1.preheader ]\n %cmp2 = icmp ult i32 %i.0, 2\n %inc = add nuw nsw i32 %i.0, 1\n br i1 %cmp2, label %for.cond1, label %for.body.i.preheader, !llvm.loop !17\n\nfor.body.i.preheader: ; preds = %for.cond1\n %cmp2.lcssa = phi i1 [ %cmp2, %for.cond1 ]\n %1 = xor i1 %cmp2.lcssa, true\n %2 = bitcast i1 %1 to <1 x i1>\n %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr @d, i32 8, <1 x i1> %2, <1 x ptr> poison), !tbaa !9\n %4 = bitcast <1 x ptr> %3 to ptr\n store i32 0, ptr @c, align 4, !tbaa !13\n %5 = load i32, ptr %4, align 4, !tbaa !13\n %tobool1.not.i = icmp ne i32 %5, 0\n %tobool1.not.i.fr = freeze i1 %tobool1.not.i\n br i1 %tobool1.not.i.fr, label %f.exit.split, label %for.body.i.preheader.split\n\nfor.body.i.preheader.split: ; preds = %for.body.i.preheader\n br label %for.body.i\n\nfor.body.i: ; preds = %for.body.i.preheader.split, %for.body.i\n %n.04.i = phi i8 [ %add.i, %for.body.i ], [ -66, %for.body.i.preheader.split ]\n %add.i = add nsw i8 %n.04.i, 1\n %tobool.not.i = icmp eq i8 %add.i, 0\n br i1 %tobool.not.i, label %f.exit, label %for.body.i, !llvm.loop !15\n\nf.exit: ; preds = %for.body.i\n br label %f.exit.split\n\nf.exit.split: ; preds = %for.body.i.preheader, %f.exit\n store i32 7, ptr %4, align 4, !tbaa !13\n %inc6 = add nuw nsw i32 %b.0, 1\n br label %for.cond, !llvm.loop !18\n}\n\n!9 = !{!10, !10, i64 0}\n!10 = !{!\"any pointer\", !11, i64 0}\n!11 = !{!\"omnipotent char\", !12, i64 0}\n!12 = !{!\"Simple C/C++ TBAA\"}\n!13 = !{!14, !14, i64 0}\n!14 = !{!\"int\", !11, i64 0}\n!15 = distinct !{!15, !16}\n!16 = !{!\"llvm.loop.mustprogress\"}\n!17 = distinct !{!17, !16}\n!18 = distinct !{!18, !16}", "lli_expected_out": "", "additional_args": null } ] } ]
{ "title": "[LICM] Miscompilation caused by wrong AA result", "body": "Reproducer: https://godbolt.org/z/Y1vvbndf8\r\n```\r\n@c = dso_local global i32 0, align 4\r\n@d = dso_local local_unnamed_addr global ptr @c, align 8\r\n\r\ndefine i32 @main() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %f.exit.split, %entry\r\n %b.0 = phi i32 [ 0, %entry ], [ %inc6, %f.exit.split ]\r\n %cmp = icmp ult i32 %b.0, 2\r\n br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup\r\n\r\nfor.cond1.preheader: ; preds = %for.cond\r\n br label %for.cond1\r\n\r\nfor.cond.cleanup: ; preds = %for.cond\r\n %0 = load i32, ptr @c, align 4, !tbaa !13\r\n ret i32 %0\r\n\r\nfor.cond1: ; preds = %for.cond1, %for.cond1.preheader\r\n %i.0 = phi i32 [ %inc, %for.cond1 ], [ 0, %for.cond1.preheader ]\r\n %cmp2 = icmp ult i32 %i.0, 2\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br i1 %cmp2, label %for.cond1, label %for.body.i.preheader, !llvm.loop !17\r\n\r\nfor.body.i.preheader: ; preds = %for.cond1\r\n %cmp2.lcssa = phi i1 [ %cmp2, %for.cond1 ]\r\n %1 = xor i1 %cmp2.lcssa, true\r\n %2 = bitcast i1 %1 to <1 x i1>\r\n %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr @d, i32 8, <1 x i1> %2, <1 x ptr> poison), !tbaa !9\r\n %4 = bitcast <1 x ptr> %3 to ptr\r\n store i32 0, ptr @c, align 4, !tbaa !13\r\n %5 = load i32, ptr %4, align 4, !tbaa !13\r\n %tobool1.not.i = icmp ne i32 %5, 0\r\n %tobool1.not.i.fr = freeze i1 %tobool1.not.i\r\n br i1 %tobool1.not.i.fr, label %f.exit.split, label %for.body.i.preheader.split\r\n\r\nfor.body.i.preheader.split: ; preds = %for.body.i.preheader\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %for.body.i.preheader.split, %for.body.i\r\n %n.04.i = phi i8 [ %add.i, %for.body.i ], [ -66, %for.body.i.preheader.split ]\r\n %add.i = add nsw i8 %n.04.i, 1\r\n %tobool.not.i = icmp eq i8 %add.i, 0\r\n br i1 %tobool.not.i, label %f.exit, label %for.body.i, !llvm.loop !15\r\n\r\nf.exit: ; preds = %for.body.i\r\n br label %f.exit.split\r\n\r\nf.exit.split: ; preds = %for.body.i.preheader, %f.exit\r\n store i32 7, ptr %4, align 4, !tbaa !13\r\n %inc6 = add nuw nsw i32 %b.0, 1\r\n br label %for.cond, !llvm.loop !18\r\n}\r\n\r\n!9 = !{!10, !10, i64 0}\r\n!10 = !{!\"any pointer\", !11, i64 0}\r\n!11 = !{!\"omnipotent char\", !12, i64 0}\r\n!12 = !{!\"Simple C/C++ TBAA\"}\r\n!13 = !{!14, !14, i64 0}\r\n!14 = !{!\"int\", !11, i64 0}\r\n!15 = distinct !{!15, !16}\r\n!16 = !{!\"llvm.loop.mustprogress\"}\r\n!17 = distinct !{!17, !16}\r\n!18 = distinct !{!18, !16}\r\n```\r\nAfter LICM:\r\n```\r\nsource_filename = \"/app/example.ll\"\r\n\r\ndefine i32 @main() {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %f.exit.split, %entry\r\n %0 = phi i32 [ poison, %entry ], [ 0, %f.exit.split ]\r\n %b.0 = phi i32 [ 0, %entry ], [ %inc6, %f.exit.split ]\r\n %cmp = icmp ult i32 %b.0, 2\r\n br i1 %cmp, label %for.cond1.preheader, label %for.cond.cleanup\r\n\r\nfor.cond1.preheader: ; preds = %for.cond\r\n br label %for.cond1\r\n\r\nfor.cond.cleanup: ; preds = %for.cond\r\n %.lcssa = phi i32 [ %0, %for.cond ]\r\n store i32 %.lcssa, ptr @c, align 4, !tbaa !0\r\n %1 = load i32, ptr @c, align 4, !tbaa !0\r\n ret i32 %1\r\n\r\nfor.cond1: ; preds = %for.cond1, %for.cond1.preheader\r\n %i.0 = phi i32 [ %inc, %for.cond1 ], [ 0, %for.cond1.preheader ]\r\n %cmp2 = icmp ult i32 %i.0, 2\r\n %inc = add nuw nsw i32 %i.0, 1\r\n br i1 %cmp2, label %for.cond1, label %for.body.i.preheader, !llvm.loop !4\r\n\r\nfor.body.i.preheader: ; preds = %for.cond1\r\n %cmp2.lcssa = phi i1 [ %cmp2, %for.cond1 ]\r\n %2 = xor i1 %cmp2.lcssa, true\r\n %3 = bitcast i1 %2 to <1 x i1>\r\n %4 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr @d, i32 8, <1 x i1> %3, <1 x ptr> poison), !tbaa !6\r\n %5 = bitcast <1 x ptr> %4 to ptr\r\n %6 = load i32, ptr %5, align 4, !tbaa !0\r\n %tobool1.not.i = icmp ne i32 %6, 0\r\n %tobool1.not.i.fr = freeze i1 %tobool1.not.i\r\n br i1 %tobool1.not.i.fr, label %f.exit.split, label %for.body.i.preheader.split\r\n\r\nfor.body.i.preheader.split: ; preds = %for.body.i.preheader\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %for.body.i, %for.body.i.preheader.split\r\n %n.04.i = phi i8 [ %add.i, %for.body.i ], [ -66, %for.body.i.preheader.split ]\r\n %add.i = add nsw i8 %n.04.i, 1\r\n %tobool.not.i = icmp eq i8 %add.i, 0\r\n br i1 %tobool.not.i, label %f.exit, label %for.body.i, !llvm.loop !8\r\n\r\nf.exit: ; preds = %for.body.i\r\n br label %f.exit.split\r\n\r\nf.exit.split: ; preds = %f.exit, %for.body.i.preheader\r\n store i32 7, ptr %5, align 4, !tbaa !0\r\n %inc6 = add nuw nsw i32 %b.0, 1\r\n br label %for.cond, !llvm.loop !9\r\n}\r\n\r\ndeclare <1 x ptr> @llvm.masked.load.v1p0.p0(ptr nocapture, i32 immarg, <1 x i1>, <1 x ptr>) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: read) }\r\n\r\n!0 = !{!1, !1, i64 0}\r\n!1 = !{!\"int\", !2, i64 0}\r\n!2 = !{!\"omnipotent char\", !3, i64 0}\r\n!3 = !{!\"Simple C/C++ TBAA\"}\r\n!4 = distinct !{!4, !5}\r\n!5 = !{!\"llvm.loop.mustprogress\"}\r\n!6 = !{!7, !7, i64 0}\r\n!7 = !{!\"any pointer\", !2, i64 0}\r\n!8 = distinct !{!8, !5}\r\n!9 = distinct !{!9, !5}\r\n```\r\n```\r\n> lli test.ll\r\n> echo $?\r\n7\r\n> bin/opt -passes=licm test.ll -S -o out.ll\r\n> lli out.ll\r\n> echo $?\r\n0\r\n```\r\n`store i32 7, ptr %5, align 4, !tbaa !0` may write something to `@c`. So this transform is incorrect.\r\n\r\nRelated patch: https://github.com/llvm/llvm-project/pull/96878\r\nOriginal C code (needs x86 +cf or riscv +zicldst):\r\n```\r\n#include \"csmith.h\"\r\nuint32_t c = 0;\r\nint32_t *d = &c;\r\nvoid f(int32_t *o) {\r\n uint8_t n;\r\n for (n = 190; n; n += 1) {\r\n *o = 0;\r\n if (*d)\r\n break;\r\n }\r\n}\r\nint main() {\r\n for (int b = 0; b <= 1; b++) {\r\n uint64_t j[2];\r\n int i;\r\n for (i = 0; i < 2; i++)\r\n j[i] = 1;\r\n f(&c);\r\n safe_add_func_int32_t_s_s(0, j[1]);\r\n *d = 7;\r\n }\r\n printf(\"%d\\n\", c);\r\n return 0;\r\n}\r\n```\r\n\r\ncc @nikic @fhahn @KanRobert \r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "TBAA", "llvm:ir", "llvm:analysis" ], "comments": [ { "author": "KanRobert", "body": "Which patch supports `zicldst` for riscv? @dtcxzyw " }, { "author": "nikic", "body": "Hm, we probably have a lot of places that don't handle things like `bitcast <1 x ptr> %3 to ptr` correctly, and assume that bitcast of pointer is always a pointer to pointer cast." }, { "author": "dtcxzyw", "body": "> Which patch supports `zicldst` for riscv? @dtcxzyw\r\n\r\nWe have a prototype which is still working in progress:\r\n+ llvm support: https://github.com/llvm/llvm-project/compare/main...dtcxzyw:llvm-project:zicldst-support\r\n+ qemu support: https://github.com/qemu/qemu/compare/master...cyyself:qemu:exp_rv_zicldst\r\n" } ] }
true
null
120237
https://github.com/llvm/llvm-project/issues/120237
hang
9e333872199b1e3bf488d71e222ff4b6f0370347
2024-12-17T14:27:28
[ "llvm/test/Analysis/ScalarEvolution" ]
{ "fix_commit": "acfd26a93be3fb70013560f3fb894eb9086e7e32", "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": [ [ 15753, 15758 ], [ 15764, 15773 ] ], "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::collectFromBlock" ], "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 acfd26a93be3fb70013560f3fb894eb9086e7e32 Author: Julian Nagele <[email protected]> Date: Fri Dec 20 15:44:15 2024 +0100 [SCEV] Fix exit condition for recursive loop guard collection (#120442) When assumptions are present `Terms.size()` does not actually count the number of conditions collected from dominating branches; introduce a separate counter. Fixes https://github.com/llvm/llvm-project/issues/120237 diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index d55d09020fc1..1e4bb1d606cd 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -15753,6 +15753,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock( // predecessors that can be found that have unique successors leading to the // original header. // TODO: share this logic with isLoopEntryGuardedByCond. + unsigned NumCollectedConditions = 0; std::pair<const BasicBlock *, const BasicBlock *> Pair(Pred, Block); for (; Pair.first; Pair = SE.getPredecessorWithUniqueSuccessorForBB(Pair.first)) { @@ -15764,10 +15765,11 @@ void ScalarEvolution::LoopGuards::collectFromBlock( Terms.emplace_back(LoopEntryPredicate->getCondition(), LoopEntryPredicate->getSuccessor(0) == Pair.second); + NumCollectedConditions++; // If we are recursively collecting guards stop after 2 - // predecessors to limit compile-time impact for now. - if (Depth > 0 && Terms.size() == 2) + // conditions to limit compile-time impact for now. + if (Depth > 0 && NumCollectedConditions == 2) break; } // Finally, if we stopped climbing the predecessor chain because
[ { "file": "llvm/test/Analysis/ScalarEvolution/backedge-taken-count-guard-info-with-multiple-predecessors.ll", "commands": [ "opt < %s -disable-output \"-passes=print<scalar-evolution>\" -scalar-evolution-max-iterations=0 -scalar-evolution-classify-expressions=0 2>&1" ], "tests": [ { "test_name": "pr120442", "test_body": "; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine void @pr120442(i1 %c.1, i1 %c.2) {\nentry:\n call void @llvm.assume(i1 %c.1)\n call void @llvm.assume(i1 %c.2)\n br label %outer.header\n\nouter.header: ; preds = %bb, %entry\n %phi7 = phi i32 [ 0, %bb ], [ 0, %entry ]\n br label %inner.header\n\nbb: ; preds = %bb\n br i1 false, label %outer.header, label %bb\n\ninner.header: ; preds = %inner.header, %outer.header\n %phi = phi i32 [ %add, %inner.header ], [ 0, %outer.header ]\n %add = add i32 %phi, 1\n %icmp = icmp ugt i32 %add, 0\n br i1 %icmp, label %exit, label %inner.header\n\nexit: ; preds = %inner.header\n ret void\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Program terminated with signal: SIGKILL Compiler returned: 137", "body": "To reproduce run the following test with -passes=loop-vectorize on opt:\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.ll\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @wombat() #0 gc \"statepoint-example\" {\nbb:\n call void @llvm.assume(i1 false)\n call void @llvm.assume(i1 false)\n br label %bb6\n\nbb1: ; preds = %bb2, %bb6\n br label %bb2\n\nbb2: ; preds = %bb2, %bb1\n %phi = phi i32 [ %add4, %bb2 ], [ 0, %bb1 ]\n %phi3 = phi i32 [ 0, %bb2 ], [ 0, %bb1 ]\n %add = add i32 0, 0\n %add4 = add i32 %phi, 1\n %icmp = icmp ugt i32 %phi, 0\n br i1 %icmp, label %bb1, label %bb2\n\nbb5: ; preds = %bb5\n br i1 false, label %bb6, label %bb5\n\nbb6: ; preds = %bb5, %bb\n %phi7 = phi i32 [ 0, %bb5 ], [ 0, %bb ]\n br label %bb1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #1\n\nattributes #0 = { \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-amx-fp8,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,-movrs,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,-amx-tf32,-amx-avx512,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-amx-transpose,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-amx-movrs,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,-amx-fp8,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,-movrs,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,-amx-tf32,-amx-avx512,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-amx-transpose,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-amx-movrs,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\n```\n\nReproducer: https://godbolt.org/z/x7WrWvoxa\n\n", "author": "TatyanaDoubts", "labels": [ "llvm:SCEV", "crash" ], "comments": [ { "author": "TatyanaDoubts", "body": "The godbolt is not informative. But locally I see the following stack dump:\n```\nbin/opt -S -passes=loop-vectorize reduced-stripped.ll\nLLVM ERROR: SmallVector unable to grow. Requested capacity (4294967296) is larger than maximum value for size type (4294967295)\n0. Program arguments: bin/opt -S -passes=loop-vectorize reduced-stripped.ll\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced-stripped.ll\"\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\n #0 0x00007f945d6be47b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) llvm/lib/Support/Unix/Signals.inc:727:3\n #1 0x00007f945d6bbfbb llvm::sys::RunSignalHandlers() llvm/lib/Support/Signals.cpp:105:20\n #2 0x00007f945d6bc2fe SignalHandler(int) llvm/lib/Support/Unix/Signals.inc:413:1\n #3 0x00007f9462a89980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)\n #4 0x00007f945c0fbe87 raise (/lib/x86_64-linux-gnu/libc.so.6+0x3ee87)\n #5 0x00007f945c0fd7f1 abort (/lib/x86_64-linux-gnu/libc.so.6+0x407f1)\n #6 0x00007f945d435674 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_replace(unsigned long, unsigned long, char const*, unsigned long) gcc-13.3.0-rhel6/include/c++/13.3.0/bits/basic_string.tcc:545:21\n #7 0x00007f945d435674 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::assign(char const*) (.isra.0.cold) gcc-13.3.0-rhel6/include/c++/13.3.0/bits\n/basic_string.h:1684:19\n #8 0x00007f945d63c540 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::replace(unsigned long, unsigned long, char const*, unsigned long) gcc-13.3.0-rhel6/include/c++/13.3.0/bits/basic_string.h:2208:19\n #9 0x00007f945d63c540 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::insert(unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const\n&) gcc-13.3.0-rhel6/include/c++/13.3.0/bits/basic_string.h:1895:29\n#10 0x00007f945d63c540 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> std::operator+<char, std::char_traits<char>, std::allocator<char>>(std::__cxx11::basic_string<char, std::ch\nar_traits<char>, std::allocator<char>>&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&&) gcc-13.3.0-rhel6/include/c++/13.3.0/bits/basic_string.\nh:3666:35\n#11 0x00007f945d63c540 report_size_overflow(unsigned long, unsigned long) (.constprop.0) llvm/lib/Support/SmallVector.cpp:65:73\n#12 0x00007f945d63c79e ......\n#13 0x00007f945f6b3c9c llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>::updateInt(long, long)\nllvm/include/llvm/ADT/PointerIntPair.h:213:55\n#14 0x00007f945f6b3c9c llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>>::setPointer\nAndInt(llvm::Value*, bool) & llvm/include/llvm/ADT/PointerIntPair.h:111:11\n#15 0x00007f945f6b3c9c llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>>::PointerInt\nPair(llvm::Value*, bool) llvm/include/llvm/ADT/PointerIntPair.h:89:21\n#16 0x00007f945f6b3c9c llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>>& llvm::Smal\nlVectorTemplateBase<llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>>, true>::growAn\ndEmplaceBack<llvm::Value*, bool>(llvm::Value*&&, bool&&) llvm/include/llvm/ADT/SmallVector.h:559:14\n#17 0x00007f945f6b3c9c llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>>& llvm::Smal\nlVectorImpl<llvm::PointerIntPair<llvm::Value*, 1u, bool, llvm::PointerLikeTypeTraits<llvm::Value*>, llvm::PointerIntPairInfo<llvm::Value*, 1u, llvm::PointerLikeTypeTraits<llvm::Value*>>>>::emplace_back<llvm::V\nalue*, bool>(llvm::Value*&&, bool&&) llvm/include/llvm/ADT/SmallVector.h:946:38\n#18 0x00007f945f6b3c9c llvm::ScalarEvolution::LoopGuards::collectFromBlock(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::BasicBlock const*, llvm::BasicBlock const*, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, unsigned int) llvm/lib/Analysis/ScalarEvolution.cpp:15708:23\n#19 0x00007f945f6b51fa llvm::DenseMapIterator<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards, llvm::DenseMapInfo<llvm::BasicBlock const*, void>, llvm::detail::DenseMapPair<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards>, false>::operator->() const llvm/include/llvm/ADT/DenseMap.h:1238:5\n#20 0x00007f945f6b51fa llvm::ScalarEvolution::LoopGuards::collectFromPHI(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::PHINode const&, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, llvm::SmallDenseMap<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards, 4u, llvm::DenseMapInfo<llvm::BasicBlock const*, void>, llvm::detail::DenseMapPair<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards>>&, unsigned int)::'lambda'(unsigned int)::operator()(unsigned int) const llvm/lib/Analysis/ScalarEvolution.cpp:15285:25\n#21 0x00007f945f6b200c llvm::ScalarEvolution::LoopGuards::collectFromPHI(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::PHINode const&, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, llvm::SmallDenseMap<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards, 4u, llvm::DenseMapInfo<llvm::BasicBlock const*, void>, llvm::detail::DenseMapPair<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards>>&, unsigned int) llvm/lib/Analysis/ScalarEvolution.cpp:15317:26\n#22 0x00007f945f6b40af llvm::BasicBlock::phi_iterator_impl<llvm::PHINode const, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, true>>::operator++() llvm/include/llvm/IR/BasicBlock.h:505:7\n#23 0x00007f945f6b40af llvm::ScalarEvolution::LoopGuards::collectFromBlock(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::BasicBlock const*, llvm::BasicBlock const*, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, unsigned int) llvm/lib/Analysis/ScalarEvolution.cpp:15724:40\n#24 0x00007f945f6b534b llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() llvm/include/llvm/ADT/SmallPtrSet.h:87:5\n#25 0x00007f945f6b534b llvm::SmallPtrSetImpl<llvm::BasicBlock const*>::~SmallPtrSetImpl() llvm/include/llvm/ADT/SmallPtrSet.h:368:7\n#26 0x00007f945f6b534b llvm::SmallPtrSet<llvm::BasicBlock const*, 8u>::~SmallPtrSet() llvm/include/llvm/ADT/SmallPtrSet.h:524:7\n#27 0x00007f945f6b534b llvm::ScalarEvolution::LoopGuards::collect(llvm::Loop const*, llvm::ScalarEvolution&) llvm/lib/Analysis/ScalarEvolution.cpp:15266:1\n#28 0x00007f945f6b539a llvm::ScalarEvolution::LoopGuards::rewrite(llvm::SCEV const*) const llvm/lib/Analysis/ScalarEvolution.cpp:15892:3\n#29 0x00007f945f6b539a llvm::ScalarEvolution::applyLoopGuards(llvm::SCEV const*, llvm::ScalarEvolution::LoopGuards const&) llvm/lib/Analysis/ScalarEvolution.cpp:15905:24\n#30 0x00007f945f6b539a llvm::ScalarEvolution::applyLoopGuards(llvm::SCEV const*, llvm::Loop const*) llvm/lib/Analysis/ScalarEvolution.cpp:15900:25\n#31 0x00007f945f1e1c35 llvm::LoopVectorizationCostModel::computeMaxVF(llvm::ElementCount, unsigned int) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:4119:38\n#32 0x00007f945f1e5bfb llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7150:51\n#33 0x00007f945f1e7b71 llvm::LoopVectorizePass::processLoop(llvm::Loop*) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10095:45\n#34 0x00007f945f1eb181 llvm::LoopVectorizePass::runImpl(llvm::Function&) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10441:27\n#35 0x00007f945f1eb777 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10478:39\n#36 0x00007f94606acedd llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/include/llvm/IR/PassManagerInternal.h:91:3\n#37 0x00007f945d8d889f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/include/llvm/IR/PassManagerImpl.h:85:18\n#38 0x00007f94601642ed llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) llvm/include/llvm/IR/PassManagerInternal.h:91:3\n#39 0x00007f945d8d8dea llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm/lib/IR/PassManager.cpp:129:41\n#40 0x00007f94601646dd llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm/include/llvm/IR/PassManagerInternal.h:91:3\n#41 0x00007f945d8da12f llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) llvm/include/llvm/IR/PassManagerImpl.h:85:18\n#42 0x000000000042ccba llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() llvm/include/llvm/ADT/SmallPtrSet.h:87:5\n#43 0x000000000042ccba llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() llvm/include/llvm/ADT/SmallPtrSet.h:368:7\n#44 0x000000000042ccba llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() llvm/include/llvm/ADT/SmallPtrSet.h:524:7\n#45 0x000000000042ccba llvm::PreservedAnalyses::~PreservedAnalyses() llvm/include/llvm/IR/Analysis.h:111:7\n#46 0x000000000042ccba 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/tools/opt/NewPMDriver.cpp:553:10\n#47 0x00000000004207e3 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() gcc-13.3.0-rhel6/include/c++/13.3.0/bits/basic_string.h:804:19\n#48 0x00000000004207e3 optMain llvm/tools/opt/optdriver.cpp:765:3\n#49 0x00007f945c0dec87 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21c87)\n......\n```" }, { "author": "fhahn", "body": "@juliannagele could you take a look? Seems like a crash in `collectFromPHI` you recently added" }, { "author": "juliannagele", "body": "> [@juliannagele](https://github.com/juliannagele) could you take a look? Seems like a crash in `collectFromPHI` you recently added\n\nSure, checking!" }, { "author": "juliannagele", "body": "Thanks for the report, should be fixed here: https://github.com/llvm/llvm-project/pull/120442" } ] }
true
null
116809
https://github.com/llvm/llvm-project/issues/116809
crash
0a1795f781163a8e7b72fee492f87ab27d5e3995
2024-11-19T14:26:43
[ "llvm/test/Transforms/LICM" ]
{ "fix_commit": "18b02bbf441660683df7f3925946984203d49bab", "components": [ "LICM", "MemorySSAUpdater" ], "bug_location_lineno": { "llvm/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": [ [ 190, 196 ] ], "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ [ 1403, 1411 ] ], "llvm/lib/Transforms/Scalar/LICM.cpp": [ [ 1465, 1472 ] ], "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": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ "MemorySSAUpdater::createMemoryAccessBefore", "MemorySSAUpdater::createMemoryAccessInBB" ], "llvm/lib/Transforms/Scalar/LICM.cpp": [ "cloneInstructionInExitBlock" ], "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 18b02bbf441660683df7f3925946984203d49bab Author: DianQK <[email protected]> Date: Wed Nov 20 19:52:51 2024 +0800 [LICM] allow MemoryAccess creation failure (#116813) Fixes #116809. After running some passes (SimpleLoopUnswitch, LoopInstSimplify, etc.), MemorySSA might be outdated, and the instruction `I` may have become a non-memory touching instruction. LICM has already handled this, but it does not pass `CreationMustSucceed=false` to `createDefinedAccess`. diff --git a/llvm/include/llvm/Analysis/MemorySSAUpdater.h b/llvm/include/llvm/Analysis/MemorySSAUpdater.h index d4da3ef1146d..055feceefb05 100644 --- a/llvm/include/llvm/Analysis/MemorySSAUpdater.h +++ b/llvm/include/llvm/Analysis/MemorySSAUpdater.h @@ -190,7 +190,8 @@ public: /// inaccessible and it *must* have removeMemoryAccess called on it. MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, - MemorySSA::InsertionPlace Point); + MemorySSA::InsertionPlace Point, + bool CreationMustSucceed = true); /// Create a MemoryAccess in MemorySSA before an existing MemoryAccess. /// diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index aa550f0b6a7b..f672bd0e1e13 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -1403,9 +1403,11 @@ void MemorySSAUpdater::changeToUnreachable(const Instruction *I) { MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB( Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, - MemorySSA::InsertionPlace Point) { - MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition); - MSSA->insertIntoListsForBlock(NewAccess, BB, Point); + MemorySSA::InsertionPlace Point, bool CreationMustSucceed) { + MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess( + I, Definition, /*Template=*/nullptr, CreationMustSucceed); + if (NewAccess) + MSSA->insertIntoListsForBlock(NewAccess, BB, Point); return NewAccess; } diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index fa04ced7182d..94bfe44a847a 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1465,8 +1465,11 @@ static Instruction *cloneInstructionInExitBlock( if (MSSAU.getMemorySSA()->getMemoryAccess(&I)) { // Create a new MemoryAccess and let MemorySSA set its defining access. + // After running some passes, MemorySSA might be outdated, and the + // instruction `I` may have become a non-memory touching instruction. MemoryAccess *NewMemAcc = MSSAU.createMemoryAccessInBB( - New, nullptr, New->getParent(), MemorySSA::Beginning); + New, nullptr, New->getParent(), MemorySSA::Beginning, + /*CreationMustSucceed=*/false); if (NewMemAcc) { if (auto *MemDef = dyn_cast<MemoryDef>(NewMemAcc)) MSSAU.insertDef(MemDef, /*RenameUses=*/true);
[ { "file": "llvm/test/Transforms/LICM/PR116813-memoryssa-outdated.ll", "commands": [ "opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)' -verify-memoryssa -S < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Check that running LICM after SimpleLoopUnswitch does not result in a crash.\n\ndefine i32 @foo(i1 %arg, ptr %arg1) {\n;\nstart:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %i = select i1 %arg, ptr %arg1, ptr @bar\n %i3 = call i32 %i()\n br i1 %arg, label %loop, label %ret\n\nret: ; preds = %loop\n ret i32 %i3\n}\n\ndeclare i32 @bar() nounwind willreturn memory(none)", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SimpleLoopUnswitch][LICM] Assertion `NewAccess != nullptr && \"Tried to create a memory access for a \" \"non-memory touching instruction\"'", "body": "The following IR triggers the assertion mentioned in the title:\r\n\r\n```llvm\r\n; opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)'\r\ndefine i32 @foo(i1 %arg, ptr %arg1) {\r\nbb:\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb2, %bb\r\n %i = select i1 %arg, ptr %arg1, ptr @bar\r\n %i3 = call i32 %i()\r\n br i1 %arg, label %bb2, label %bb4\r\n\r\nbb4: ; preds = %bb2\r\n ret i32 %i3\r\n}\r\n\r\ndeclare i32 @bar() nounwind willreturn memory(none)\r\n```\r\n\r\nhttps://llvm.godbolt.org/z/bj79jxo8x", "author": "DianQK", "labels": [ "crash", "llvm:analysis", "llvm:transforms" ], "comments": [] }
true
null
116228
https://github.com/llvm/llvm-project/issues/116228
crash
fbbea8929ffd2fae57a6013912455d566b884e12
2024-11-14T13:46:57
[ "llvm/test/Analysis/MemorySSA" ]
{ "fix_commit": "46e04f7fe5c0f01ba452489bb966bdf2d560a63d", "components": [ "MemorySSAUpdater" ], "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": [ [ 260, 282 ] ], "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ [ 565, 588 ], [ 593, 602 ], [ 615, 621 ], [ 668, 675 ], [ 692, 700 ], [ 716, 728 ], [ 741, 747 ] ], "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": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ "MemorySSAUpdater::cloneUsesAndDefs", "MemorySSAUpdater::privateUpdateExitBlocksForClonedLoop", "MemorySSAUpdater::updateForClonedBlockIntoPred", "MemorySSAUpdater::updateForClonedLoop", "getNewDefiningAccessForClone", "onlySingleValue" ], "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 46e04f7fe5c0f01ba452489bb966bdf2d560a63d Author: Nikita Popov <[email protected]> Date: Mon Dec 9 12:21:49 2024 +0100 [MemorySSA] Handle MemoryDef optimized away during cloning (#117883) When determining the replacement access during cloning, we currently leave accesses for instructions that are not in the VMap alone. This is correct if the instruction is not in VMap because it hasn't been cloned, but not if it has been cloned and then removed. In that case, we should walk up to the defining access, like in other simplification cases. To distinguish the two cases, pass in a callback that queries whether the instruction is part of the cloned region. An alternative to this would be to delay removal of dead instructions in SimpleLoopUnswitch until after MSSA cloning. Fixes https://github.com/llvm/llvm-project/issues/116228. diff --git a/llvm/include/llvm/Analysis/MemorySSAUpdater.h b/llvm/include/llvm/Analysis/MemorySSAUpdater.h index 055feceefb05..b8e08f4b7842 100644 --- a/llvm/include/llvm/Analysis/MemorySSAUpdater.h +++ b/llvm/include/llvm/Analysis/MemorySSAUpdater.h @@ -260,23 +260,32 @@ private: MemoryAccess *tryRemoveTrivialPhi(MemoryPhi *Phi, RangeType &Operands); void tryRemoveTrivialPhis(ArrayRef<WeakVH> UpdatedPHIs); void fixupDefs(const SmallVectorImpl<WeakVH> &); - // Clone all uses and defs from BB to NewBB given a 1:1 map of all - // instructions and blocks cloned, and a map of MemoryPhi : Definition - // (MemoryAccess Phi or Def). VMap maps old instructions to cloned - // instructions and old blocks to cloned blocks. MPhiMap, is created in the - // caller of this private method, and maps existing MemoryPhis to new - // definitions that new MemoryAccesses must point to. These definitions may - // not necessarily be MemoryPhis themselves, they may be MemoryDefs. As such, - // the map is between MemoryPhis and MemoryAccesses, where the MemoryAccesses - // may be MemoryPhis or MemoryDefs and not MemoryUses. - // If CloneWasSimplified = true, the clone was exact. Otherwise, assume that - // the clone involved simplifications that may have: (1) turned a MemoryUse - // into an instruction that MemorySSA has no representation for, or (2) turned - // a MemoryDef into a MemoryUse or an instruction that MemorySSA has no - // representation for. No other cases are supported. + /// Clone all uses and defs from BB to NewBB given a 1:1 map of all + /// instructions and blocks cloned, and a map of MemoryPhi : Definition + /// (MemoryAccess Phi or Def). + /// + /// \param VMap Maps old instructions to cloned instructions and old blocks + /// to cloned blocks + /// \param MPhiMap, is created in the caller of this private method, and maps + /// existing MemoryPhis to new definitions that new MemoryAccesses + /// must point to. These definitions may not necessarily be MemoryPhis + /// themselves, they may be MemoryDefs. As such, the map is between + /// MemoryPhis and MemoryAccesses, where the MemoryAccesses may be + /// MemoryPhis or MemoryDefs and not MemoryUses. + /// \param IsInClonedRegion Determines whether a basic block was cloned. + /// References to accesses outside the cloned region will not be + /// remapped. + /// \param CloneWasSimplified If false, the clone was exact. Otherwise, + /// assume that the clone involved simplifications that may have: + /// (1) turned a MemoryUse into an instruction that MemorySSA has no + /// representation for, or (2) turned a MemoryDef into a MemoryUse or + /// an instruction that MemorySSA has no representation for. No other + /// cases are supported. void cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB, const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap, + function_ref<bool(BasicBlock *)> IsInClonedRegion, bool CloneWasSimplified = false); + template <typename Iter> void privateUpdateExitBlocksForClonedLoop(ArrayRef<BasicBlock *> ExitBlocks, Iter ValuesBegin, Iter ValuesEnd, diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index f672bd0e1e13..050b827388d3 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -565,24 +565,26 @@ static MemoryAccess *onlySingleValue(MemoryPhi *MP) { return MA; } -static MemoryAccess *getNewDefiningAccessForClone(MemoryAccess *MA, - const ValueToValueMapTy &VMap, - PhiToDefMap &MPhiMap, - MemorySSA *MSSA) { +static MemoryAccess *getNewDefiningAccessForClone( + MemoryAccess *MA, const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap, + MemorySSA *MSSA, function_ref<bool(BasicBlock *BB)> IsInClonedRegion) { MemoryAccess *InsnDefining = MA; if (MemoryDef *DefMUD = dyn_cast<MemoryDef>(InsnDefining)) { - if (!MSSA->isLiveOnEntryDef(DefMUD)) { - Instruction *DefMUDI = DefMUD->getMemoryInst(); - assert(DefMUDI && "Found MemoryUseOrDef with no Instruction."); - if (Instruction *NewDefMUDI = - cast_or_null<Instruction>(VMap.lookup(DefMUDI))) { - InsnDefining = MSSA->getMemoryAccess(NewDefMUDI); - if (!InsnDefining || isa<MemoryUse>(InsnDefining)) { - // The clone was simplified, it's no longer a MemoryDef, look up. - InsnDefining = getNewDefiningAccessForClone( - DefMUD->getDefiningAccess(), VMap, MPhiMap, MSSA); - } - } + if (MSSA->isLiveOnEntryDef(DefMUD)) + return DefMUD; + + // If the MemoryDef is not part of the cloned region, leave it alone. + Instruction *DefMUDI = DefMUD->getMemoryInst(); + assert(DefMUDI && "Found MemoryUseOrDef with no Instruction."); + if (!IsInClonedRegion(DefMUDI->getParent())) + return DefMUD; + + auto *NewDefMUDI = cast_or_null<Instruction>(VMap.lookup(DefMUDI)); + InsnDefining = NewDefMUDI ? MSSA->getMemoryAccess(NewDefMUDI) : nullptr; + if (!InsnDefining || isa<MemoryUse>(InsnDefining)) { + // The clone was simplified, it's no longer a MemoryDef, look up. + InsnDefining = getNewDefiningAccessForClone( + DefMUD->getDefiningAccess(), VMap, MPhiMap, MSSA, IsInClonedRegion); } } else { MemoryPhi *DefPhi = cast<MemoryPhi>(InsnDefining); @@ -593,10 +595,10 @@ static MemoryAccess *getNewDefiningAccessForClone(MemoryAccess *MA, return InsnDefining; } -void MemorySSAUpdater::cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB, - const ValueToValueMapTy &VMap, - PhiToDefMap &MPhiMap, - bool CloneWasSimplified) { +void MemorySSAUpdater::cloneUsesAndDefs( + BasicBlock *BB, BasicBlock *NewBB, const ValueToValueMapTy &VMap, + PhiToDefMap &MPhiMap, function_ref<bool(BasicBlock *)> IsInClonedRegion, + bool CloneWasSimplified) { const MemorySSA::AccessList *Acc = MSSA->getBlockAccesses(BB); if (!Acc) return; @@ -615,7 +617,7 @@ void MemorySSAUpdater::cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB, MemoryAccess *NewUseOrDef = MSSA->createDefinedAccess( NewInsn, getNewDefiningAccessForClone(MUD->getDefiningAccess(), VMap, - MPhiMap, MSSA), + MPhiMap, MSSA, IsInClonedRegion), /*Template=*/CloneWasSimplified ? nullptr : MUD, /*CreationMustSucceed=*/false); if (NewUseOrDef) @@ -668,8 +670,13 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks, ArrayRef<BasicBlock *> ExitBlocks, const ValueToValueMapTy &VMap, bool IgnoreIncomingWithNoClones) { - PhiToDefMap MPhiMap; + SmallSetVector<BasicBlock *, 16> Blocks; + for (BasicBlock *BB : concat<BasicBlock *const>(LoopBlocks, ExitBlocks)) + Blocks.insert(BB); + auto IsInClonedRegion = [&](BasicBlock *BB) { return Blocks.contains(BB); }; + + PhiToDefMap MPhiMap; auto FixPhiIncomingValues = [&](MemoryPhi *Phi, MemoryPhi *NewPhi) { assert(Phi && NewPhi && "Invalid Phi nodes."); BasicBlock *NewPhiBB = NewPhi->getBlock(); @@ -692,9 +699,10 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks, continue; // Determine incoming value and add it as incoming from IncBB. - NewPhi->addIncoming( - getNewDefiningAccessForClone(IncomingAccess, VMap, MPhiMap, MSSA), - IncBB); + NewPhi->addIncoming(getNewDefiningAccessForClone(IncomingAccess, VMap, + MPhiMap, MSSA, + IsInClonedRegion), + IncBB); } if (auto *SingleAccess = onlySingleValue(NewPhi)) { MPhiMap[Phi] = SingleAccess; @@ -716,13 +724,13 @@ void MemorySSAUpdater::updateForClonedLoop(const LoopBlocksRPO &LoopBlocks, MPhiMap[MPhi] = NewPhi; } // Update Uses and Defs. - cloneUsesAndDefs(BB, NewBlock, VMap, MPhiMap); + cloneUsesAndDefs(BB, NewBlock, VMap, MPhiMap, IsInClonedRegion); }; - for (auto *BB : llvm::concat<BasicBlock *const>(LoopBlocks, ExitBlocks)) + for (auto *BB : Blocks) ProcessBlock(BB); - for (auto *BB : llvm::concat<BasicBlock *const>(LoopBlocks, ExitBlocks)) + for (auto *BB : Blocks) if (MemoryPhi *MPhi = MSSA->getMemoryAccess(BB)) if (MemoryAccess *NewPhi = MPhiMap.lookup(MPhi)) FixPhiIncomingValues(MPhi, cast<MemoryPhi>(NewPhi)); @@ -741,7 +749,9 @@ void MemorySSAUpdater::updateForClonedBlockIntoPred( PhiToDefMap MPhiMap; if (MemoryPhi *MPhi = MSSA->getMemoryAccess(BB)) MPhiMap[MPhi] = MPhi->getIncomingValueForBlock(P1); - cloneUsesAndDefs(BB, P1, VM, MPhiMap, /*CloneWasSimplified=*/true); + cloneUsesAndDefs( + BB, P1, VM, MPhiMap, [&](BasicBlock *CheckBB) { return BB == CheckBB; }, + /*CloneWasSimplified=*/true); } template <typename Iter>
[ { "file": "llvm/test/Analysis/MemorySSA/loop-rotate-update.ll", "commands": [ "opt -disable-output -passes=\"loop-mssa(loop-rotate),print<memoryssa>\" -verify-memoryssa < %s 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": "\n\n\n\ndefine void @test(ptr %p) {\nentry:\n br label %loop\n\nloop:\n store ptr null, ptr %p\n %val1 = load ptr, ptr %p\n %cmp = icmp eq ptr %val1, null\n br i1 %cmp, label %exit, label %loop.latch\n\nloop.latch:\n %val2 = load ptr, ptr %p\n br label %loop\n\nexit:\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/MemorySSA/pr116227.ll", "commands": [ "opt -disable-output -passes=\"loop-mssa(simple-loop-unswitch<nontrivial>),print<memoryssa>\" -verify-memoryssa < %s 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": "\ndeclare ptr @malloc() allockind(\"alloc,uninitialized\")\n\n\n\n\ndefine void @test(i1 %arg) {\nentry:\n br label %for.body\n\nfor.body:\n %call.i = call ptr @malloc()\n %cmp.i = icmp ne ptr %call.i, null\n %or.cond.i = select i1 %cmp.i, i1 %arg, i1 false\n br i1 %or.cond.i, label %exit, label %for.body\n\nexit:\n ret void\n}\n\n\n\n\n\ndefine void @test_extra_defs(ptr %p, i1 %arg) {\nentry:\n store i8 1, ptr %p\n br label %for.body\n\nfor.body:\n store i8 2, ptr %p\n %call.i = call ptr @malloc()\n %cmp.i = icmp ne ptr %call.i, null\n %or.cond.i = select i1 %cmp.i, i1 %arg, i1 false\n br i1 %or.cond.i, label %exit, label %for.body\n\nexit:\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Crash at -O3: Assertion `MA->use_empty() && \"Trying to remove memory access that still has uses\"' failed", "body": "When I compiled the code with -O3, it crashed:\r\n\r\nBisected to https://github.com/llvm/llvm-project/commit/5a3e3675f6be3c49fb1a305202888cce4d916ba6, which was committed by @durin42 \r\n\r\nCompiler explorer: https://godbolt.org/z/3Wc1jdx6d\r\n\r\n```c\r\nstruct a {\r\n struct a *b\r\n};\r\nint c, g, i;\r\nvoid *malloc();\r\nint d() {\r\n struct a *e = malloc(c);\r\n if (e == 0)\r\n return 1;\r\n for (int f = 0; f < c; f++)\r\n e[f].b = 1 ? &e[1] : 0;\r\n}\r\nint h() {\r\n for (; g; g++)\r\n ;\r\n return 0;\r\n}\r\nvoid j() {\r\n for (;;)\r\n for (; h() + i; i++)\r\n d();\r\n}\r\nint main() {}\r\n```\r\nCrash is: \r\n\r\n```\r\nclang: /root/llvm-project/llvm/lib/Analysis/MemorySSA.cpp:1840: void llvm::MemorySSA::removeFromLookups(llvm::MemoryAccess*): Assertion `MA->use_empty() && \"Trying to remove memory access that still has uses\"' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 -Wall -Wextra <source>\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,argpromotion,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide)),function(invalidate<should-not-run-function-passes>),cgscc(devirt<4>())\" on module \"<source>\"\r\n4.\tRunning pass \"cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,argpromotion,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide))\" on module \"<source>\"\r\n5.\tRunning pass \"loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>)\" on function \"j\"\r\n #0 0x0000000003bfb838 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bfb838)\r\n #1 0x0000000003bf953c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bf953c)\r\n #2 0x0000000003b46b38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007afb46242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007afb462969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #5 0x00007afb46242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #6 0x00007afb462287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #7 0x00007afb4622871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #8 0x00007afb46239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #9 0x0000000002bead0a llvm::MemorySSA::removeFromLookups(llvm::MemoryAccess*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2bead0a)\r\n#10 0x0000000002c03a6c llvm::MemorySSAUpdater::removeBlocks(llvm::SmallSetVector<llvm::BasicBlock*, 8u> const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c03a6c)\r\n#11 0x00000000084e163a deleteDeadBlocksFromLoop(llvm::Loop&, llvm::SmallVectorImpl<llvm::BasicBlock*>&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::MemorySSAUpdater*, llvm::ScalarEvolution*, llvm::LPMUpdater&) SimpleLoopUnswitch.cpp:0:0\r\n#12 0x00000000084ea50d unswitchNontrivialInvariants(llvm::Loop&, llvm::Instruction&, llvm::ArrayRef<llvm::Value*>, llvm::IVConditionInfo&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::AssumptionCache&, llvm::ScalarEvolution*, llvm::MemorySSAUpdater*, llvm::LPMUpdater&, bool, bool) SimpleLoopUnswitch.cpp:0:0\r\n#13 0x00000000084ec9a8 unswitchBestCondition(llvm::Loop&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::AssumptionCache&, llvm::AAResults&, llvm::TargetTransformInfo&, llvm::ScalarEvolution*, llvm::MemorySSAUpdater*, llvm::LPMUpdater&) SimpleLoopUnswitch.cpp:0:0\r\n#14 0x00000000084f0679 llvm::SimpleLoopUnswitchPass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x84f0679)\r\n#15 0x000000000525730e llvm::detail::PassModel<llvm::Loop, llvm::SimpleLoopUnswitchPass, 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/clang+0x525730e)\r\n#16 0x0000000003a12986 std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::Loop, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a12986)\r\n#17 0x0000000003a12b4e llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a12b4e)\r\n#18 0x0000000003a13f04 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/clang+0x3a13f04)\r\n#19 0x0000000003a14bfc llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3a14bfc)\r\n#20 0x000000000112567e 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/clang+0x112567e)\r\n#21 0x00000000035b06d8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35b06d8)\r\n#22 0x0000000001125c2e 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+0x1125c2e)\r\n#23 0x0000000002ab3c12 llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2ab3c12)\r\n#24 0x000000000112607e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x112607e)\r\n#25 0x0000000002aaad52 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2aaad52)\r\n#26 0x00000000052560ce llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52560ce)\r\n#27 0x0000000002ab0666 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2ab0666)\r\n#28 0x00000000052560ee llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52560ee)\r\n#29 0x0000000002aae3f6 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2aae3f6)\r\n#30 0x00000000052560ae llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52560ae)\r\n#31 0x00000000035aeb30 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35aeb30)\r\n#32 0x0000000005476f75 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5476f75)\r\n#33 0x00000000050f42ce llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x50f42ce)\r\n#34 0x00000000035aeb30 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x35aeb30)\r\n#35 0x0000000003ea671b (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#36 0x0000000003ea9f45 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+0x3ea9f45)\r\n#37 0x0000000004575cfe clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4575cfe)\r\n#38 0x000000000673552c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x673552c)\r\n#39 0x00000000045760e8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45760e8)\r\n#40 0x00000000048312c9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48312c9)\r\n#41 0x00000000047b04be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47b04be)\r\n#42 0x000000000491c2ce clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x491c2ce)\r\n#43 0x0000000000ceb57f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xceb57f)\r\n#44 0x0000000000ce323a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#45 0x00000000045b92e9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#46 0x0000000003b46fe4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b46fe4)\r\n#47 0x00000000045b98df clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#48 0x000000000457fbcd clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x457fbcd)\r\n#49 0x0000000004580cbd 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+0x4580cbd)\r\n#50 0x0000000004588075 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4588075)\r\n#51 0x0000000000ce8419 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce8419)\r\n#52 0x0000000000bb4c14 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbb4c14)\r\n#53 0x00007afb46229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#54 0x00007afb46229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#55 0x0000000000ce2cee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce2cee)\r\n```", "author": "cardigan1008", "labels": [ "crash-on-valid", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced reproducer: https://godbolt.org/z/bK3z9nGsa\r\n```\r\n; bin/opt -passes=\"loop-mssa(licm,simple-loop-unswitch<nontrivial;trivial>)\" reduced.ll -S\r\n; ModuleID = 'reduced.bc'\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; Function Attrs: allockind(\"alloc,uninitialized\")\r\ndeclare ptr @malloc() #0\r\n\r\ndefine void @j(i1 %cmp2.i) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond1.for.cond_crit_edge, %entry\r\n br label %for.cond1\r\n\r\nfor.cond1: ; preds = %for.body.i, %for.body, %for.cond\r\n br i1 false, label %for.cond1.for.cond_crit_edge, label %for.body\r\n\r\nfor.cond1.for.cond_crit_edge: ; preds = %for.cond1\r\n br label %for.cond\r\n\r\nfor.body: ; preds = %for.cond1\r\n %call.i = call ptr @malloc()\r\n %cmp.i = icmp ne ptr %call.i, null\r\n %or.cond.i = select i1 %cmp.i, i1 %cmp2.i, i1 false\r\n br i1 %or.cond.i, label %for.body.i, label %for.cond1\r\n\r\nfor.body.i: ; preds = %for.body\r\n br label %for.cond1\r\n}\r\n\r\nattributes #0 = { allockind(\"alloc,uninitialized\") }\r\n```" }, { "author": "nikic", "body": "Can reduce this to:\n\n```llvm\n; RUN: opt -S -passes=\"loop-mssa(simple-loop-unswitch<nontrivial>)\" -verify-memoryssa < %s\ndeclare ptr @malloc() allockind(\"alloc,uninitialized\")\n\ndefine void @test(i1 %arg) {\nentry:\n br label %for.body\n\nfor.body:\n %call.i = call ptr @malloc()\n %cmp.i = icmp ne ptr %call.i, null\n %or.cond.i = select i1 %cmp.i, i1 %arg, i1 false\n br i1 %or.cond.i, label %exit, label %for.body\n\nexit:\n ret void\n}\n```\n\n> opt: /home/npopov/repos/llvm-project/llvm/lib/Analysis/MemorySSA.cpp:2068: void llvm::MemorySSA::verifyOrderingDominationAndDefUses(IterT, VerificationLevel) const [IterT = llvm::iterator_range<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, true, false, void, false, void>, false, false>>]: Assertion `dominates(MD, U) && \"Memory Def does not dominate it's uses\"' failed.\n" }, { "author": "nikic", "body": "We go from:\n```llvm\nMemorySSA for function: test\ndefine void @test(i1 %arg) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n; 2 = MemoryPhi({entry,liveOnEntry},{for.body,1})\n; 1 = MemoryDef(2)\n %call.i = call ptr @malloc()\n %cmp.i = icmp ne ptr %call.i, null\n %or.cond.i = select i1 %cmp.i, i1 %arg, i1 false\n br i1 %or.cond.i, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret void\n}\n```\nTo:\n```llvm\nMemorySSA for function: test\ndefine void @test(i1 %arg) {\nentry:\n %arg.fr = freeze i1 %arg\n br i1 %arg.fr, label %entry.split, label %entry.split.us\n\nentry.split.us: ; preds = %entry\n br label %for.body.us\n\nfor.body.us: ; preds = %for.body.us, %entry.split.us\n; 3 = MemoryPhi({entry.split.us,liveOnEntry},{for.body.us,1})\n br label %for.body.us\n\nentry.split: ; preds = %entry\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry.split\n; 2 = MemoryPhi({entry.split,liveOnEntry},{for.body,1})\n; 1 = MemoryDef(2)\n %call.i = call ptr @malloc()\n %cmp.i = icmp ne ptr %call.i, null\n %or.cond.i = select i1 %cmp.i, i1 true, i1 false\n br i1 %or.cond.i, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret void\n}\n```\n\nMemoryPhi 3 is broken.\n\nI think this is because we first delete the dead cloned instructions and then update MSSA and something gets confused in that case..." } ] }
true
null
109528
https://github.com/llvm/llvm-project/issues/109528
crash
586736226e3a25b1fd647d3257270c1388f907bf
2024-09-21T14:20:16
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "6d6eea92e36c301e34a7ec11b2a40e3080f79f53", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 8420, 8440 ] ], "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": [ "VPRecipeBuilder::tryToWidenHistogram" ], "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 6d6eea92e36c301e34a7ec11b2a40e3080f79f53 Author: Florian Hahn <[email protected]> Date: Wed Oct 2 13:45:48 2024 +0100 [LV] Use SCEV to simplify wide binop operand to constant. The legacy cost model uses SCEV to determine if the second operand of a binary op is a constant. Update the VPlan construction logic to mirror the current legacy behavior, to fix a difference in the cost models. Fixes https://github.com/llvm/llvm-project/issues/109528. Fixes https://github.com/llvm/llvm-project/issues/110440. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index e1f9f29ac6d9..de3b981a4fe3 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8420,21 +8420,28 @@ VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, case Instruction::Sub: case Instruction::Xor: case Instruction::Freeze: - if (I->getOpcode() == Instruction::Mul) { - // Simplify operands of multiplications using SCEV. This is needed at the - // moment to match the behavior of the legacy cost-model. - // TODO: Generalize to any opcode and move to VPlan transformation. - SmallVector<VPValue *> NewOps(Operands); + SmallVector<VPValue *> NewOps(Operands); + if (Instruction::isBinaryOp(I->getOpcode())) { + // The legacy cost model uses SCEV to check if some of the operands are + // constants. To match the legacy cost model's behavior, use SCEV to try + // to replace operands with constants. ScalarEvolution &SE = *PSE.getSE(); - for (unsigned I = 0; I < Operands.size(); ++I) { - Value *V = NewOps[I]->getUnderlyingValue(); - if (!isa<Constant>(V) && SE.isSCEVable(V->getType())) - if (auto *C = dyn_cast<SCEVConstant>(PSE.getSE()->getSCEV(V))) - NewOps[I] = Plan.getOrAddLiveIn(C->getValue()); - } - return new VPWidenRecipe(*I, make_range(NewOps.begin(), NewOps.end())); + auto GetConstantViaSCEV = [this, &SE](VPValue *Op) { + Value *V = Op->getUnderlyingValue(); + if (isa<Constant>(V) || !SE.isSCEVable(V->getType())) + return Op; + auto *C = dyn_cast<SCEVConstant>(SE.getSCEV(V)); + if (!C) + return Op; + return Plan.getOrAddLiveIn(C->getValue()); + }; + // For Mul, the legacy cost model checks both operands. + if (I->getOpcode() == Instruction::Mul) + NewOps[0] = GetConstantViaSCEV(NewOps[0]); + // For other binops, the legacy cost model only checks the second operand. + NewOps[1] = GetConstantViaSCEV(NewOps[1]); } - return new VPWidenRecipe(*I, make_range(Operands.begin(), Operands.end())); + return new VPWidenRecipe(*I, make_range(NewOps.begin(), NewOps.end())); }; }
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "test_foldable_live_in_via_scev", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @test_foldable_live_in_via_scev() {\nentry:\n %conv = zext i16 -6 to i64\n %add = add nsw i64 %conv, -65528\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]\n %red = phi i64 [ 1, %entry ], [ %mul, %loop ]\n %mul = mul nsw i64 %red, %add\n %iv.next = add nsw i32 %iv, 1\n %ec = icmp eq i32 %iv.next, 100\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %ret = phi i64 [ %mul, %loop ]\n ret i64 %ret\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "second_lshr_operand_zero_via_scev", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @second_lshr_operand_zero_via_scev() {\nentry:\n %ext.0 = sext i8 0 to i32\n br label %loops\n\nloops: ; preds = %loops, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loops ]\n %red = phi i64 [ 0, %entry ], [ %red.next, %loops ]\n %c = icmp eq i64 %iv, 0\n %and = and i64 %iv, 0\n %0 = trunc i64 %iv to i32\n %shr = lshr i32 %0, %ext.0\n %conv.1 = zext i32 %shr to i64\n %red.next.v = select i1 %c, i64 %and, i64 %conv.1\n %red.next = or i64 %red.next.v, %red\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 0\n br i1 %ec, label %exit, label %loops\n\nexit: ; preds = %loops\n %res = phi i64 [ %red.next, %loops ]\n ret i64 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Assertion failed in Vectorize", "body": "When I compiled this code with O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\nstatic uint64_t\r\nsafe_sub_func_uint64_t_u_u(uint64_t ui1, uint64_t ui2)\r\n{\r\n return ui1 - ui2;\r\n}\r\nlong a;\r\nstatic int8_t c;\r\nvoid b(long d, int f) {\r\n int e = 0;\r\n for (; e < 64; e++)\r\n if (e - f)\r\n a |= e >> f;\r\n else\r\n a |= d & e;\r\n}\r\nuint32_t g() {\r\n b(6, c);\r\n for (;; c = safe_sub_func_uint64_t_u_u(c, 4))\r\n ;\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7383: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/7733x1hvP", "author": "cardigan1008", "labels": [ "vectorizers", "confirmed", "crash" ], "comments": [ { "author": "shafik", "body": "This looks like a regression in trunk: https://godbolt.org/z/eo7WG1e66" }, { "author": "hiraditya", "body": "Probably a recent change caused this? cc: @ayalz @fhahn " } ] }
true
null
102934
https://github.com/llvm/llvm-project/issues/102934
crash
2913e71865dfc063a47ddfaf1e2ce07763f69614
2024-08-12T16:46:46
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2ab910c08c4ed43d6fd9eb2ef9b3ff52e0293cf9", "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": [ [ 3705, 3711 ] ], "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" ], "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 2ab910c08c4ed43d6fd9eb2ef9b3ff52e0293cf9 Author: Florian Hahn <[email protected]> Date: Tue Aug 13 09:23:44 2024 +0100 [LV] Check pointer user are in loop when checking for uniform pointers. Widening decisions are not set for users outside the loop. Avoid crashing by only calling isVectorizedMemAccessUse for users in the loop. Fixes https://github.com/llvm/llvm-project/issues/102934. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 5547116133e8..0d1262fa1872 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -3705,7 +3705,8 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) { auto *I = cast<Instruction>(V); auto UsersAreMemAccesses = llvm::all_of(I->users(), [&](User *U) -> bool { - return isVectorizedMemAccessUse(cast<Instruction>(U), V); + auto *UI = cast<Instruction>(U); + return TheLoop->contains(UI) && isVectorizedMemAccessUse(UI, V); }); if (UsersAreMemAccesses) addToWorklistIfAllowed(I);
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/gep-use-outside-loop.ll", "commands": [ "opt -p loop-vectorize -mtriple=x86_64-apple-macosx -mcpu=skylake-avx512 -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "gep_use_outside_loop", "test_body": "define void @gep_use_outside_loop(ptr noalias %dst, ptr %src) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.dst = getelementptr i16, ptr %dst, i64 %iv\n %gep.src = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 2\n %c = icmp eq i16 %l, 10\n br i1 %c, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n store i16 0, ptr %gep.dst, align 2\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 99\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n store i16 0, ptr %gep.dst, align 2\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "gep_use_in_dead_block", "test_body": "define void @gep_use_in_dead_block(ptr noalias %dst, ptr %src) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.src = getelementptr i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 2\n %c = icmp eq i16 %l, 10\n br i1 %c, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %gep.dst = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep.dst, align 2\n br label %loop.latch\n\ndead: ; preds = %dead\n store i16 0, ptr %gep.dst, align 2\n br label %dead\n\nloop.latch: ; preds = %then, %loop.header\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 99\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": "[LoopVectorize] Assertion `WideningDecision != CM_Unknown && \"Widening decision should be ready at this moment\"' failed.", "body": "Reduced LLVM IR:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main(i64 %indvars.iv.i) #0 {\r\nentry:\r\n br label %for.body6.i\r\n\r\nfor.body6.i: ; preds = %for.inc34.i, %entry\r\n %indvars.iv.i1 = phi i64 [ 0, %entry ], [ %indvars.iv.next.i, %for.inc34.i ]\r\n br i1 false, label %for.body6.i.for.inc34.i_crit_edge, label %for.cond7.preheader.i\r\n\r\nfor.body6.i.for.inc34.i_crit_edge: ; preds = %for.body6.i\r\n br label %for.inc34.i\r\n\r\nfor.cond7.preheader.i: ; preds = %for.body6.i\r\n %arrayidx30.i = getelementptr [0 x i16], ptr null, i64 0, i64 %indvars.iv.i\r\n store i16 0, ptr %arrayidx30.i, align 2\r\n br label %for.inc34.i\r\n\r\nfor.body19.1.i: ; preds = %for.body19.1.i\r\n store i16 0, ptr %arrayidx30.i, align 2\r\n br label %for.body19.1.i\r\n\r\nfor.inc34.i: ; preds = %for.cond7.preheader.i, %for.body6.i.for.inc34.i_crit_edge\r\n %indvars.iv.next.i = add i64 %indvars.iv.i1, 1\r\n %exitcond.not.i = icmp eq i64 %indvars.iv.next.i, 0\r\n br i1 %exitcond.not.i, label %q.exit, label %for.body6.i\r\n\r\nq.exit: ; preds = %for.inc34.i\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-b,-e,-experimental-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,-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\" -S reduced.ll\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3631: llvm::LoopVectorizationCostModel::collectLoopUniforms(llvm::ElementCount)::<lambda(llvm::Instruction*, llvm::ElementCount)>: Assertion `WideningDecision != CM_Unknown && \"Widening decision should be ready at this moment\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000059f80448a570 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f4f570)\r\n #1 0x000059f80448798f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f4c98f)\r\n #2 0x000059f804487ae5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000795355842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007953558969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007953558969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007953558969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000795355842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007953558287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000079535582871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000795355839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000059f80347d610 llvm::LoopVectorizationCostModel::collectLoopUniforms(llvm::ElementCount) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f42610)\r\n#12 0x000059f80348fa77 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f54a77)\r\n#13 0x000059f803491b83 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f56b83)\r\n#14 0x000059f803494de1 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+0x1f59de1)\r\n#15 0x000059f803495497 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f5a497)\r\n#16 0x000059f8022ff336 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+0xdc4336)\r\n#17 0x000059f8042a17ff 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+0x2d667ff)\r\n#18 0x000059f8023024c6 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+0xdc74c6)\r\n#19 0x000059f8042a057b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d6557b)\r\n#20 0x000059f8022fe7c6 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+0xdc37c6)\r\n#21 0x000059f80429e5dd 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+0x2d635dd)\r\n#22 0x000059f801b38c36 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+0x5fdc36)\r\n#23 0x000059f801b2a881 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5ef881)\r\n#24 0x0000795355829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#25 0x0000795355829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#26 0x0000795355829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#27 0x000059f801b206c5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e56c5)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [] }
true
null
111606
https://github.com/llvm/llvm-project/issues/111606
crash
374fffe015b48676fb3785167d363454a2f4dd1f
2024-10-08T23:44:36
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "01cbbc52dc95fe5d9e30ecbfb2ec8c7c1e0199c4", "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": [ [ 645, 652 ] ], "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": [ "VPInstruction::generate" ], "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 01cbbc52dc95fe5d9e30ecbfb2ec8c7c1e0199c4 Author: Florian Hahn <[email protected]> Date: Wed Oct 9 13:18:53 2024 +0100 [VPlan] Request lane 0 for pointer arg in PtrAdd. After 7f74651, the pointer operand may be replicated of a PtrAdd. Instead of requesting a single scalar, request lane 0, which correctly handles the case when there is a scalar-per-lane. Fixes https://github.com/llvm/llvm-project/issues/111606. diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 123eb0d8d71a..2468616be0bd 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -645,8 +645,8 @@ Value *VPInstruction::generate(VPTransformState &State) { case VPInstruction::PtrAdd: { assert(vputils::onlyFirstLaneUsed(this) && "can only generate first lane for PtrAdd"); - Value *Ptr = State.get(getOperand(0), /* IsScalar */ true); - Value *Addend = State.get(getOperand(1), /* IsScalar */ true); + Value *Ptr = State.get(getOperand(0), VPLane(0)); + Value *Addend = State.get(getOperand(1), VPLane(0)); return isInBounds() ? Builder.CreateInBoundsPtrAdd(Ptr, Addend, Name) : Builder.CreatePtrAdd(Ptr, Addend, Name); }
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/interleave-ptradd-with-replicated-operand.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "test_interleave_ptradd_with_replicated_op", "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 ptr @test_interleave_ptradd_with_replicated_op(ptr %m) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %ptr.iv = phi ptr [ %m, %entry ], [ %ptr.iv.next, %loop ]\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]\n %ptr.iv.next = getelementptr i8, ptr %ptr.iv, i64 8\n %p.4 = getelementptr i8, ptr %ptr.iv, i64 4\n %l.1 = load i32, ptr %p.4, align 4\n %p.0 = getelementptr i8, ptr %ptr.iv, i64 0\n %l.2 = load i32, ptr %p.0, align 4\n %add = add i32 %l.1, %l.2\n store i32 %add, ptr %ptr.iv, align 4\n %iv.next = add i32 %iv, 1\n %tobool.not = icmp eq i32 %iv, 100\n br i1 %tobool.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret ptr %p.4\n}\n\nattributes #0 = { \"target-cpu\"=\"znver2\" }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "A/F: \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed after 7f74651", "body": "Recently one of our internal tests started hitting an assertion failure when compiling which I bisected back to commit 7f74651. \r\n\r\nHere is a reduced repro from the crashing code:\r\n```c\r\ntypedef float a;\r\ntypedef struct {\r\n a b, c;\r\n} d;\r\ntypedef struct {\r\n d e;\r\n a f;\r\n} g;\r\n#define h() \\\r\n i = j->e.b; \\\r\n k = l->e.c; \\\r\n l->f = k;\r\na i, k;\r\nint m;\r\ng *l;\r\nvoid n() {\r\n g *j = l + 1;\r\n for (; m; ++m, ++l, ++j) {\r\n h()\r\n }\r\n}\r\n```\r\n\r\nWhen compiled with `-O2 -g -ffast-math -march=znver2` using a compiler built from 7f74651 you can see the crash:\r\n```\r\n$ ~/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang -c -O2 -g -ffast-math -march=znver2 repro.c\r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/Transforms/Vectorize/VPlan.cpp:258: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def) || !vputils::onlyFirstLaneUsed(Def) || (hasScalarValue(Def, VPLane(0)) && Data.VPV2Scalars[Def].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang -c -O2 -g -ffast-math -march=znver2 repro2.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"repro2.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"n\"\r\n #0 0x000055d0e9ad0e1f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x235be1f)\r\n #1 0x000055d0e9ace96c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x235996c)\r\n #2 0x000055d0e9a20cc8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f44c03e9420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #4 0x00007f44bfeb600b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #5 0x00007f44bfe95859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #6 0x00007f44bfe95729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #7 0x00007f44bfe95729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #8 0x00007f44bfea6fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #9 0x000055d0eb66055a llvm::VPTransformState::get(llvm::VPValue*, bool) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3eeb55a)\r\n#10 0x000055d0eb6926a9 llvm::VPInstruction::generate(llvm::VPTransformState&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3f1d6a9)\r\n#11 0x000055d0eb695d01 llvm::VPInstruction::execute(llvm::VPTransformState&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3f20d01)\r\n#12 0x000055d0eb65fb77 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3eeab77)\r\n#13 0x000055d0eb66283e llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3eed83e)\r\n#14 0x000055d0eb6645c8 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3eef5c8)\r\n#15 0x000055d0eb660b8e llvm::VPlan::execute(llvm::VPTransformState*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3eebb8e)\r\n#16 0x000055d0eb5362cb 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*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3dc12cb)\r\n#17 0x000055d0eb54baf4 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3dd6af4)\r\n#18 0x000055d0eb54dac1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3dd8ac1)\r\n#19 0x000055d0eb54e133 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3dd9133)\r\n#20 0x000055d0eaf6f396 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x37fa396)\r\n#21 0x000055d0e9589031 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x1e14031)\r\n#22 0x000055d0e86a7026 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0xf32026)\r\n#23 0x000055d0e958799d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x1e1299d)\r\n#24 0x000055d0e86a79e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0xf329e6)\r\n#25 0x000055d0e95873d1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x1e123d1)\r\n#26 0x000055d0e9d65d23 (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#27 0x000055d0e9d692f8 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x25f42f8)\r\n#28 0x000055d0ea4492ac clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2cd42ac)\r\n#29 0x000055d0ec3dbb9c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x4c66b9c)\r\n#30 0x000055d0ea4496c8 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2cd46c8)\r\n#31 0x000055d0ea7119a9 clang::FrontendAction::Execute() (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2f9c9a9)\r\n#32 0x000055d0ea68d99e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2f1899e)\r\n#33 0x000055d0ea7fe466 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x3089466)\r\n#34 0x000055d0e862a295 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0xeb5295)\r\n#35 0x000055d0e862201a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#36 0x000055d0ea48f17d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#37 0x000055d0e9a211d0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x22ac1d0)\r\n#38 0x000055d0ea48f79f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#39 0x000055d0ea4538f4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2cde8f4)\r\n#40 0x000055d0ea454a0d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2cdfa0d)\r\n#41 0x000055d0ea45cb55 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0x2ce7b55)\r\n#42 0x000055d0e862722b clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0xeb222b)\r\n#43 0x000055d0e855712b main (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0xde212b)\r\n#44 0x00007f44bfe97083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#45 0x000055d0e8621aae _start (/home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin/clang+0xeacaae)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 20.0.0 (https://github.com/llvm/llvm-project.git 7f74651837b8f95996ea4c774b2e604020446951)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/7f74651837b8f95996ea4c774b2e604020446951-linux/bin\r\nBuild config: +assertions\r\n```\r\n\r\nHere is a link to godbolt also showing the failure: https://godbolt.org/z/bnPM9qqYo", "author": "dyung", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
119393
https://github.com/llvm/llvm-project/issues/119393
crash
13539c219c49c581d6ba5270d09b19da9b1e3975
2024-12-10T15:25:03
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "a42aa8f265372a15d31a2af10b548fc239ed4b51", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13222, 13230 ] ], "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" ], "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 a42aa8f265372a15d31a2af10b548fc239ed4b51 Author: Alexey Bataev <[email protected]> Date: Tue Dec 10 09:19:48 2024 -0800 [SLP]Fix adjusting of the mask for the fully matched nodes. When checking for the poison elements in the matches node, need to consider the register number, when clearing the corresponding mask element. Fixes #119393 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c729c6cc9195..d90d7cc8f29e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13222,9 +13222,9 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( copy(CommonMask, Mask.begin()); } // Clear undef scalars. - for (int I = 0, Sz = VL.size(); I < Sz; ++I) + for (unsigned I : seq<unsigned>(VL.size())) if (isa<PoisonValue>(VL[I])) - Mask[I] = PoisonMaskElem; + Mask[Part * VL.size() + I] = PoisonMaskElem; return TargetTransformInfo::SK_PermuteSingleSrc; } // No perfect match, just shuffle, so choose the first tree node from the
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/full-match-with-poison-scalar.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-200 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test() {\nentry:\n br label %func_135.exit.i\n\nfunc_135.exit.i: ; preds = %entry\n %g_228.promoted166.i1105.i = phi i32 [ 0, %entry ]\n %cmp55.i.i1199.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.1.i.i1200.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.2.i.i1201.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.3.i.i1202.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %0 = xor i1 %cmp55.2.i.i1201.i, %cmp55.3.i.i1202.i\n %1 = xor i1 %cmp55.1.i.i1200.i, %0\n %2 = xor i1 %cmp55.i.i1199.i, %1\n %dec.i.i1204.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.1.i.i1200.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.2.i.i1201.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.3.i.i1202.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %3 = xor i1 %cmp55.2.i.i1201.1.i, %cmp55.3.i.i1202.1.i\n %4 = xor i1 %cmp55.1.i.i1200.1.i, %3\n %5 = xor i1 %cmp55.i.i1199.1.i, %4\n %6 = xor i1 %2, %5\n %dec.i.i1204.1.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.1.i.i1200.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.2.i.i1201.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.3.i.i1202.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %7 = add i32 0, 0\n %8 = icmp ult i32 %7, 0\n %9 = xor i1 %cmp55.3.i.i1202.2.i, %8\n %10 = xor i1 %cmp55.2.i.i1201.2.i, %9\n %11 = xor i1 %cmp55.1.i.i1200.2.i, %10\n %12 = xor i1 %cmp55.i.i1199.2.i, %11\n %13 = xor i1 %12, %6\n %dec.i.i1204.2.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.1.i.i1200.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.2.i.i1201.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %14 = xor i1 %cmp55.1.i.i1200.3.i, %cmp55.2.i.i1201.3.i\n %15 = xor i1 %cmp55.i.i1199.3.i, %14\n %16 = xor i1 %15, %13\n %17 = zext i1 %16 to i16\n br label %if.then.sink.split.i\n\nfor.cond7.preheader.i1132.1.i: ; No predecessors!\n br label %if.then.sink.split.i\n\nif.then.sink.split.i: ; preds = %for.cond7.preheader.i1132.1.i, %func_135.exit.i\n %xor58.5.i.i1203.3.3.sink.i = phi i16 [ 0, %for.cond7.preheader.i1132.1.i ], [ %17, %func_135.exit.i ]\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed.", "body": "Reproducer: https://godbolt.org/z/3dahr6Mb4\n```\n; bin/opt -passes=slp-vectorizer reduced.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main() {\nentry:\n br label %func_135.exit.i\n\nfunc_135.exit.i:\n %g_228.promoted166.i1105.i = phi i32 [ 0, %entry ]\n %cmp55.i.i1199.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.1.i.i1200.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.2.i.i1201.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %cmp55.3.i.i1202.i = icmp ugt i32 %g_228.promoted166.i1105.i, 0\n %0 = xor i1 %cmp55.2.i.i1201.i, %cmp55.3.i.i1202.i\n %1 = xor i1 %cmp55.1.i.i1200.i, %0\n %2 = xor i1 %cmp55.i.i1199.i, %1\n %dec.i.i1204.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.1.i.i1200.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.2.i.i1201.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %cmp55.3.i.i1202.1.i = icmp ugt i32 %dec.i.i1204.i, 0\n %3 = xor i1 %cmp55.2.i.i1201.1.i, %cmp55.3.i.i1202.1.i\n %4 = xor i1 %cmp55.1.i.i1200.1.i, %3\n %5 = xor i1 %cmp55.i.i1199.1.i, %4\n %6 = xor i1 %2, %5\n %dec.i.i1204.1.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.1.i.i1200.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.2.i.i1201.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %cmp55.3.i.i1202.2.i = icmp ugt i32 %dec.i.i1204.1.i, 0\n %7 = add i32 0, 0\n %8 = icmp ult i32 %7, 0\n %9 = xor i1 %cmp55.3.i.i1202.2.i, %8\n %10 = xor i1 %cmp55.2.i.i1201.2.i, %9\n %11 = xor i1 %cmp55.1.i.i1200.2.i, %10\n %12 = xor i1 %cmp55.i.i1199.2.i, %11\n %13 = xor i1 %12, %6\n %dec.i.i1204.2.i = add i32 %g_228.promoted166.i1105.i, 0\n %cmp55.i.i1199.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.1.i.i1200.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %cmp55.2.i.i1201.3.i = icmp ugt i32 %dec.i.i1204.2.i, 0\n %14 = xor i1 %cmp55.1.i.i1200.3.i, %cmp55.2.i.i1201.3.i\n %15 = xor i1 %cmp55.i.i1199.3.i, %14\n %16 = xor i1 %15, %13\n %17 = zext i1 %16 to i16\n br label %if.then.sink.split.i\n\nfor.cond7.preheader.i1132.1.i: ; No predecessors!\n br label %if.then.sink.split.i\n\nif.then.sink.split.i: ; preds = %for.cond7.preheader.i1132.1.i, %func_135.exit.i\n %xor58.5.i.i1203.3.3.sink.i = phi i16 [ 0, %for.cond7.preheader.i1132.1.i ], [ %17, %func_135.exit.i ]\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10913: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x00000000051c9e58 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51c9e58)\n #1 0x00000000051c785c SignalHandler(int) Signals.cpp:0:0\n #2 0x000078cea7e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000078cea7e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000078cea7e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000078cea7e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000078cea7e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000078cea7e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000041fda54 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41fda54)\n #9 0x00000000042390b0 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42390b0)\n#10 0x0000000004243fa7 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4243fa7)\n#11 0x0000000004277f91 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4277f91)\n#12 0x000000000427da60 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\n#13 0x0000000004280ea9 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4280ea9)\n#14 0x000000000428563b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#15 0x0000000004289c9f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4289c9f)\n#16 0x0000000004290786 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#17 0x00000000042912cb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42912cb)\n#18 0x0000000002fdbfee llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fdbfee)\n#19 0x0000000004fc8d00 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fc8d00)\n#20 0x0000000000e3b51e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3b51e)\n#21 0x0000000004fc761b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fc761b)\n#22 0x0000000000e3abae llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3abae)\n#23 0x0000000004fc7020 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fc7020)\n#24 0x00000000009177ca llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9177ca)\n#25 0x0000000000909e49 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x909e49)\n#26 0x000078cea7e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000078cea7e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x0000000000901705 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x901705)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
91883
https://github.com/llvm/llvm-project/issues/91883
crash
90109d444839683b09f0aafdc50b749cb4b3203b
2024-05-12T12:03:48
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "67d840b60fbd75ca1b52d77bd3353771ec853735", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 246, 252 ] ], "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": 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 67d840b60fbd75ca1b52d77bd3353771ec853735 Author: Florian Hahn <[email protected]> Date: Tue May 14 19:10:48 2024 +0100 [VPlan] Relax over-aggressive assertion in VPTransformState::get(). There are cases where a vector value has some users that demand the the single scalar value only (NeedsScalar), while other users demand the vector value (see attached test cases). In those cases, the NeedsScalar users should only demand the first lane. Fixes https://github.com/llvm/llvm-project/issues/91883. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index 999236ae8489..27f8e239b1c0 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -246,7 +246,7 @@ Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) { Value *VPTransformState::get(VPValue *Def, unsigned Part, bool NeedsScalar) { if (NeedsScalar) { - assert((VF.isScalar() || Def->isLiveIn() || + assert((VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def, Part) || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && "Trying to access a single scalar per part but has multiple scalars "
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/widened-value-used-as-scalar-and-first-lane.ll", "commands": [ "opt -S -passes=loop-vectorize -mcpu=skylake-avx512 -mtriple=x86_64-apple-macosx -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\n; Test cases based on https://github.com/llvm/llvm-project/issues/91883.\ndefine void @iv.4_used_as_vector_and_first_lane(ptr %src, ptr noalias %dst) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %g.src = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %g.src\n %iv.4 = add nuw nsw i64 %iv, 4\n %c = icmp ule i64 %l, 128\n br i1 %c, label %loop.then, label %loop.latch\n\nloop.then:\n %or = or disjoint i64 %iv.4, 1\n %g.dst = getelementptr inbounds i64, ptr %dst, i64 %or\n store i64 %iv.4, ptr %g.dst, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond = icmp eq i64 %iv.next, 32\n br i1 %exitcond, label %exit, label %loop.header\n\nexit:\n ret void\n}\n\ndefine void @iv.4_used_as_first_lane(ptr %src, ptr noalias %dst) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %g.src = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %g.src\n %iv.4 = add nuw nsw i64 %iv, 4\n %c = icmp ule i64 %l, 128\n br i1 %c, label %loop.then, label %loop.latch\n\nloop.then:\n %or = or disjoint i64 %iv.4, 1\n %g.dst = getelementptr inbounds i64, ptr %dst, i64 %or\n store i64 %l, ptr %g.dst, align 4\n br label %loop.latch\n\nloop.latch:\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond = icmp eq i64 %iv.next, 32\n br i1 %exitcond, label %exit, label %loop.header\n\nexit:\n ret void\n}\n;.\n;.", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "New LLVM vectorizer crash in assertion", "body": "@fhahn hits an assertion introduced in https://github.com/llvm/llvm-project/pull/80271\r\n\r\nInput file: https://gist.github.com/cheshire/e504c63db9bdb300fbdcc1df2e183bd8\r\n\r\nRepro:\r\n\r\n```\r\nopt -S -passes=loop-vectorize -mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-avx512pf,-tsxldtrk,-ptwrite,-widekl,-sm3,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-avx512er,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-prefetchwt1,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a -mcpu=skylake-avx512 /tmp/minimized_crash.ll\r\n```", "author": "cheshire", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
116553
https://github.com/llvm/llvm-project/issues/116553
miscompilation
c25e09e238c6f872a116d10bbefba0beff145a57
2024-11-17T18:49:16
[ "llvm/test/Transforms/ConstraintElimination" ]
{ "fix_commit": "52361d0368b79841be12156bf03cf8c1851e5df7", "components": [ "ConstraintElimination" ], "bug_location_lineno": { "llvm/lib/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": [ [ 1034, 1042 ], [ 1044, 1051 ] ], "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": [ "State::addInfoForInductions" ], "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 52361d0368b79841be12156bf03cf8c1851e5df7 Author: Yingwei Zheng <[email protected]> Date: Mon Nov 18 23:41:04 2024 +0800 [ConstraintElim] Bail out on non-dedicated exits when adding exiting conditions (#116627) This patch bails out non-dedicated exits to avoid adding exiting conditions to invalid context. Closes https://github.com/llvm/llvm-project/issues/116553. diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index d2e532d29d07..64433cb9216c 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -1034,9 +1034,9 @@ void State::addInfoForInductions(BasicBlock &BB) { DTN, CmpInst::ICMP_SLT, PN, B, ConditionTy(CmpInst::ICMP_SLE, StartValue, B))); - // Try to add condition from header to the exit blocks. When exiting either - // with EQ or NE in the header, we know that the induction value must be u<= - // B, as other exits may only exit earlier. + // Try to add condition from header to the dedicated exit blocks. When exiting + // either with EQ or NE in the header, we know that the induction value must + // be u<= B, as other exits may only exit earlier. assert(!StepOffset.isNegative() && "induction must be increasing"); assert((Pred == CmpInst::ICMP_EQ || Pred == CmpInst::ICMP_NE) && "unsupported predicate"); @@ -1044,8 +1044,11 @@ void State::addInfoForInductions(BasicBlock &BB) { SmallVector<BasicBlock *> ExitBBs; L->getExitBlocks(ExitBBs); for (BasicBlock *EB : ExitBBs) { - WorkList.emplace_back(FactOrCheck::getConditionFact( - DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond)); + // Bail out on non-dedicated exits. + if (DT.dominates(&BB, EB)) { + WorkList.emplace_back(FactOrCheck::getConditionFact( + DT.getNode(EB), CmpInst::ICMP_ULE, A, B, Precond)); + } } }
[ { "file": "llvm/test/Transforms/ConstraintElimination/induction-condition-in-loop-exit.ll", "commands": [ "opt -p constraint-elimination -S %s" ], "tests": [ { "test_name": "test_non_dedicated_exit", "test_body": "define i1 @test_non_dedicated_exit(i16 %n) {\nentry:\n %cond = icmp slt i16 %n, 1\n br i1 %cond, label %exit, label %loop.preheader\n\nloop.preheader: ; preds = %entry\n %sub = add nsw i16 %n, -1\n %ext = zext nneg i16 %sub to i32\n br label %loop\n\nloop: ; preds = %loop.latch, %loop.preheader\n %indvar = phi i32 [ %indvar.inc, %loop.latch ], [ 0, %loop.preheader ]\n %exitcond = icmp eq i32 %indvar, %ext\n br i1 %exitcond, label %exit, label %loop.latch\n\nloop.latch: ; preds = %loop\n %indvar.inc = add nuw nsw i32 %indvar, 1\n br label %loop\n\nexit: ; preds = %loop, %entry\n %cmp = icmp sgt i16 %n, 0\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Miscompile at O3 with SIGKILL", "body": "When I compiled this code with O3, it triggered SIGKILL. With O0/1/2, it returned 0.\r\n\r\nBisected to https://github.com/llvm/llvm-project/commit/5b927130b0e15a442a6ed171f43a612e6a40bbcd, which was committed by @fhahn \r\n\r\nCompiler Explorer: https://godbolt.org/z/q9j75feYG\r\n\r\nCode:\r\n```c\r\nint printf(const char *, ...);\r\nint a, c, d;\r\nint *b;\r\nchar e;\r\nshort f;\r\nint g(int i) {\r\n if (i <= 0)\r\n return 1;\r\n int h = 0;\r\n for (; h < i - 1; h++) {\r\n for (; d - h - 1;)\r\n if (c)\r\n b[d] = e = 1;\r\n if (e)\r\n break;\r\n }\r\n return 0;\r\n}\r\nvoid j() { g(f); }\r\nint main(int i, char *k[]) {\r\n j();\r\n while (0 < f)\r\n ;\r\n printf(\"%X\\n\", a);\r\n}\r\n```", "author": "cardigan1008", "labels": [ "miscompilation", "confirmed", "llvm:transforms" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/fLN5gw\r\n```\r\n; bin/opt -passes=constraint-elimination test.ll -S\r\ndefine i1 @test(i16 %n) {\r\nentry:\r\n %cond = icmp slt i16 %n, 1\r\n br i1 %cond, label %exit, label %loop.preheader\r\n\r\nloop.preheader:\r\n %sub = add nsw i16 %n, -1\r\n %ext = zext nneg i16 %sub to i32\r\n br label %loop\r\n\r\nloop:\r\n %indvar = phi i32 [ %indvar.inc, %loop.latch ], [ 0, %loop.preheader ]\r\n %12 = icmp eq i32 %indvar, %ext\r\n br i1 %12, label %exit, label %loop.latch\r\n\r\nloop.latch:\r\n %indvar.inc = add nuw nsw i32 %indvar, 1\r\n br label %loop\r\n\r\nexit:\r\n %cmp = icmp sgt i16 %n, 0\r\n ret i1 %cmp\r\n}\r\n\r\n```\r\nI will post a fix later.\r\n" } ] }
true
null
117537
https://github.com/llvm/llvm-project/issues/117537
crash
c979ec05642f292737d250c6682d85ed49bc7b6e
2024-11-25T10:47:02
[ "llvm/test/Transforms/SimpleLoopUnswitch" ]
{ "fix_commit": "fc5c89900f2a4b50e0f3a88ef7c89115d93684f4", "components": [ "SimpleLoopUnswitch" ], "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": [ [ 1248, 1255 ] ], "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": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": [ "buildClonedLoopBlocks" ], "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 fc5c89900f2a4b50e0f3a88ef7c89115d93684f4 Author: Nikita Popov <[email protected]> Date: Wed Nov 27 11:47:22 2024 +0100 [SimpleLoopUnswitch] Fix LCSSA phi node invalidation Fixes https://github.com/llvm/llvm-project/issues/117537. diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index aa3cbc5e4bdd..d8ef450eeb9a 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -1248,8 +1248,9 @@ static BasicBlock *buildClonedLoopBlocks( assert(VMap.lookup(&I) == &ClonedI && "Mismatch in the value map!"); // Forget SCEVs based on exit phis in case SCEV looked through the phi. - if (SE && isa<PHINode>(I)) - SE->forgetValue(&I); + if (SE) + if (auto *PN = dyn_cast<PHINode>(&I)) + SE->forgetLcssaPhiWithNewPredecessor(&L, PN); BasicBlock::iterator InsertPt = MergeBB->getFirstInsertionPt();
[ { "file": "llvm/test/Transforms/SimpleLoopUnswitch/pr117537.ll", "commands": [ "opt -S -passes='print<scalar-evolution>,simple-loop-unswitch<nontrivial>,print<scalar-evolution>' -verify-scev < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "define void @test(ptr %p) {\nentry:\n %check = icmp eq ptr %p, null\n br label %bb0\n\nbb0: ; preds = %loop0, %entry\n br i1 %check, label %loop0, label %latch\n\nlatch: ; preds = %bb0\n br i1 %check, label %exit0, label %loop0\n\nexit0: ; preds = %latch\n ret void\n\nloop0: ; preds = %latch, %bb0\n %v = load atomic i32, ptr %p unordered, align 8\n %add = add i32 %v, 3\n br i1 true, label %preheader, label %bb0\n\npreheader: ; preds = %loop0\n br label %loop1\n\nloop1: ; preds = %backedge, %preheader\n %iv1 = phi i32 [ %add, %preheader ], [ %iv1.next, %backedge ]\n %iv1.next = add i32 %iv1, -33\n br label %loop2\n\nbackedge: ; preds = %loop2\n br i1 true, label %exit1, label %loop1\n\nloop2: ; preds = %loop2, %loop1\n %iv0 = phi i32 [ %iv1, %loop1 ], [ %iv0.next, %loop2 ]\n %iv0.next = add nsw i32 %iv0, 1\n %cmp = icmp sgt i32 %iv0.next, 0\n br i1 %cmp, label %backedge, label %loop2\n\nexit1: ; preds = %backedge\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SCEV] Assertion `isAvailableAtLoopEntry(Op, L) && \"SCEVAddRecExpr operand is not available at loop entry!\"' failed.", "body": "Faulty IR:\n```\n; ModuleID = 'test.ll'\nsource_filename = \"/nfs/build-cache/zvm-dev-4598/jdk11/x86_64/fastdebug/lib/server/boilerplate.ll\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test(ptr addrspace(1) %p) {\nentry:\n %check = icmp eq ptr addrspace(1) %p, null\n br label %bb0\n\nbb0: ; preds = %loop0, %entry\n br i1 %check, label %loop0, label %latch\n\nlatch: ; preds = %bb0\n br i1 %check, label %exit0, label %loop0\n\nexit0: ; preds = %latch\n ret void\n\nloop0: ; preds = %latch, %bb0\n %0 = load atomic i32, ptr addrspace(1) %p unordered, align 8\n %add = add i32 %0, 3\n br i1 true, label %preheader, label %bb0\n\npreheader: ; preds = %loop0\n br label %loop1\n\nloop1: ; preds = %backedge, %preheader\n %iv1 = phi i32 [ %add, %preheader ], [ %1, %backedge ]\n %1 = add i32 %iv1, -33\n br label %loop2\n\nbackedge: ; preds = %loop2\n br i1 true, label %exit1, label %loop1\n\nloop2: ; preds = %loop2, %loop1\n %iv0 = phi i32 [ %iv1, %loop1 ], [ %2, %loop2 ]\n %2 = add nsw i32 %iv0, 1\n %3 = icmp sgt i32 %2, 0\n br i1 %3, label %backedge, label %loop2\n\nexit1: ; preds = %backedge\n ret void\n}\n```\nfails when run with `opt -passes='print<scalar-evolution>,simple-loop-unswitch<nontrivial>,print<scalar-evolution>' `\nDemo of failure: https://godbolt.org/z/qhboK5r3j\n", "author": "Nirhar", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "Nirhar", "body": "Here is the IR after simple-loop-unswitch pass:\n![res](https://github.com/user-attachments/assets/8a35df98-54f4-45f6-9e96-626fd6814e7f)\n\n\nAt the point of crash, the SCEV for Exit Value of `%iv0`(which I assume, as we crashed while printing it) is `(-4 + (-1 * %1) + %.us-phi)`, which is incorrect. The crash happens because `%1` is in a block that does not properly dominate `%iv0`. Looks like, simple-loop-unswitch is either incorrectly updating the SCEV in the pass, or is incorrectly reporting SCEV to be preserved. As of now, I'm not sure which is the case. " }, { "author": "Nirhar", "body": "@nikic @dtcxzyw @EugeneZelenko any thoughts? I'm inclined to having a patch that removes SCEV from simple-loop-unswitch 's list of preserved analyses." }, { "author": "dtcxzyw", "body": "> I'm inclined to having a patch that removes SCEV from simple-loop-unswitch 's list of preserved analyses.\n\nSome SCEVs should be invalidated in `unswitchNontrivialInvariants`. Removing SCEV from the list of preserved analyses doesn't fix the issue.\n" } ] }
true
null
110193
https://github.com/llvm/llvm-project/issues/110193
crash
7dfdca1961aadc75ca397818bfb9bd32f1879248
2024-09-27T00:54:58
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "af6354634d2cec14570108ee038ca4b18cf6856a", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 10340, 10352 ] ], "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::getEntryCost" ], "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 af6354634d2cec14570108ee038ca4b18cf6856a Author: Alexey Bataev <[email protected]> Date: Fri Sep 27 03:55:17 2024 -0700 [SLP]Look for vector user when estimating the cost Need to find the first vector node user, not the very first user node at all. The very first user might be a gather, vectorized as clustered, which may cause compiler crash. Fixes https://github.com/llvm/llvm-project/issues/110193 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 48a8627ab63e..dee0b7e1f437 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -10340,13 +10340,16 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, InstructionCost VecCost = VectorCost(CommonCost); // Check if the current node must be resized, if the parent node is not // resized. - if (!UnaryInstruction::isCast(E->getOpcode()) && E->Idx != 0 && + if (It != MinBWs.end() && !UnaryInstruction::isCast(E->getOpcode()) && + E->Idx != 0 && (E->getOpcode() != Instruction::Load || !E->UserTreeIndices.empty())) { - const EdgeInfo &EI = E->UserTreeIndices.front(); - if ((EI.UserTE->getOpcode() != Instruction::Select || - EI.EdgeIdx != 0) && - It != MinBWs.end()) { + const EdgeInfo &EI = + *find_if(E->UserTreeIndices, [](const EdgeInfo &EI) { + return !EI.UserTE->isGather() || EI.EdgeIdx != UINT_MAX; + }); + if (EI.UserTE->getOpcode() != Instruction::Select || + EI.EdgeIdx != 0) { auto UserBWIt = MinBWs.find(EI.UserTE); Type *UserScalarTy = EI.UserTE->getOperand(EI.EdgeIdx).front()->getType();
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/minbw-multiused-from-gather.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i1 @test() {\nentry:\n %c18.i308.i.i = shl i32 0, 0\n %c19.i315.i.i = shl i32 0, 0\n %and.19.i316.i.i = and i32 %c18.i308.i.i, %c19.i315.i.i\n %c20.i322.i.i = shl i32 0, 0\n %and.20.i323.i.i = and i32 %and.19.i316.i.i, %c20.i322.i.i\n %c21.i329.i.i = shl i32 0, 0\n %and.21.i330.i.i = and i32 %and.20.i323.i.i, %c21.i329.i.i\n %0 = trunc i64 0 to i32\n %conv85.22.i333.i.i = or i32 0, %0\n %cmp3.i.22.i334.i.i = icmp ugt i32 %conv85.22.i333.i.i, 0\n %shl.i111.22.i335.i.i = select i1 %cmp3.i.22.i334.i.i, i32 0, i32 0\n %c22.i336.i.i = shl i32 %conv85.22.i333.i.i, %shl.i111.22.i335.i.i\n %and.22.i337.i.i = and i32 %and.21.i330.i.i, %c22.i336.i.i\n %1 = trunc i64 0 to i32\n %conv85.23.i340.i.i = or i32 0, %1\n %cmp3.i.23.i341.i.i = icmp ugt i32 %conv85.23.i340.i.i, 0\n %shl.i111.23.i342.i.i = select i1 %cmp3.i.23.i341.i.i, i32 0, i32 0\n %c23.i343.i.i = shl i32 %conv85.23.i340.i.i, %shl.i111.23.i342.i.i\n %and.23.i344.i.i = and i32 %and.22.i337.i.i, %c23.i343.i.i\n %2 = trunc i64 0 to i32\n %conv85.24.i347.i.i = or i32 0, %2\n %cmp3.i.24.i348.i.i = icmp ugt i32 %conv85.24.i347.i.i, 0\n %shl.i111.24.i349.i.i = select i1 %cmp3.i.24.i348.i.i, i32 0, i32 0\n %c24.i350.i.i = shl i32 %conv85.24.i347.i.i, %shl.i111.24.i349.i.i\n %and.24.i351.i.i = and i32 %and.23.i344.i.i, %c24.i350.i.i\n %3 = trunc i64 0 to i32\n %conv85.25.i354.i.i = or i32 0, %3\n %cmp3.i.25.i355.i.i = icmp ugt i32 %conv85.25.i354.i.i, 0\n %shl.i111.25.i356.i.i = select i1 %cmp3.i.25.i355.i.i, i32 0, i32 0\n %c25.i357.i.i = shl i32 %conv85.25.i354.i.i, %shl.i111.25.i356.i.i\n %and.25.i358.i.i = and i32 %and.24.i351.i.i, %c25.i357.i.i\n %conv109.i.i = trunc i32 %and.25.i358.i.i to i8\n %cmp.i.i54.i = icmp eq i8 %conv109.i.i, 0\n ret i1 %cmp.i.i54.i\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.", "body": "Reproducer: https://godbolt.org/z/6GbP5f7qa\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i1 @main() {\r\nentry:\r\n %cond.i112.18.i308.i.i = shl i32 0, 0\r\n %cond.i112.19.i315.i.i = shl i32 0, 0\r\n %and.19.i316.i.i = and i32 %cond.i112.18.i308.i.i, %cond.i112.19.i315.i.i\r\n %cond.i112.20.i322.i.i = shl i32 0, 0\r\n %and.20.i323.i.i = and i32 %and.19.i316.i.i, %cond.i112.20.i322.i.i\r\n %cond.i112.21.i329.i.i = shl i32 0, 0\r\n %and.21.i330.i.i = and i32 %and.20.i323.i.i, %cond.i112.21.i329.i.i\r\n %0 = trunc i64 0 to i32\r\n %conv85.22.i333.i.i = or i32 0, %0\r\n %cmp3.i.22.i334.i.i = icmp ugt i32 %conv85.22.i333.i.i, 0\r\n %shl.i111.22.i335.i.i = select i1 %cmp3.i.22.i334.i.i, i32 0, i32 0\r\n %cond.i112.22.i336.i.i = shl i32 %conv85.22.i333.i.i, %shl.i111.22.i335.i.i\r\n %and.22.i337.i.i = and i32 %and.21.i330.i.i, %cond.i112.22.i336.i.i\r\n %1 = trunc i64 0 to i32\r\n %conv85.23.i340.i.i = or i32 0, %1\r\n %cmp3.i.23.i341.i.i = icmp ugt i32 %conv85.23.i340.i.i, 0\r\n %shl.i111.23.i342.i.i = select i1 %cmp3.i.23.i341.i.i, i32 0, i32 0\r\n %cond.i112.23.i343.i.i = shl i32 %conv85.23.i340.i.i, %shl.i111.23.i342.i.i\r\n %and.23.i344.i.i = and i32 %and.22.i337.i.i, %cond.i112.23.i343.i.i\r\n %2 = trunc i64 0 to i32\r\n %conv85.24.i347.i.i = or i32 0, %2\r\n %cmp3.i.24.i348.i.i = icmp ugt i32 %conv85.24.i347.i.i, 0\r\n %shl.i111.24.i349.i.i = select i1 %cmp3.i.24.i348.i.i, i32 0, i32 0\r\n %cond.i112.24.i350.i.i = shl i32 %conv85.24.i347.i.i, %shl.i111.24.i349.i.i\r\n %and.24.i351.i.i = and i32 %and.23.i344.i.i, %cond.i112.24.i350.i.i\r\n %3 = trunc i64 0 to i32\r\n %conv85.25.i354.i.i = or i32 0, %3\r\n %cmp3.i.25.i355.i.i = icmp ugt i32 %conv85.25.i354.i.i, 0\r\n %shl.i111.25.i356.i.i = select i1 %cmp3.i.25.i355.i.i, i32 0, i32 0\r\n %cond.i112.25.i357.i.i = shl i32 %conv85.25.i354.i.i, %shl.i111.25.i356.i.i\r\n %and.25.i358.i.i = and i32 %and.24.i351.i.i, %cond.i112.25.i357.i.i\r\n %conv109.i.i = trunc i32 %and.25.i358.i.i to i8\r\n %cmp.i.i54.i = icmp eq i8 %conv109.i.i, 0\r\n ret i1 %cmp.i.i54.i\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3247: llvm::slpvectorizer::BoUpSLP::ValueList& llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int): Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: bin/opt -passes=slp-vectorizer reduced.ll\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x000075e591a13b52 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x213b52)\r\n #1 0x000075e591a10a1f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x210a1f)\r\n #2 0x000075e591a10b65 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000075e591442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000075e5914969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000075e5914969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000075e5914969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000075e591442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000075e5914287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000075e59142871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000075e591439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000075e58c574c14 (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x174c14)\r\n#12 0x000075e58c5bcafe llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1bcafe)\r\n#13 0x000075e58c5d0eed llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1d0eed)\r\n#14 0x000075e58c5d68cc (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#15 0x000075e58c5d997a llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1d997a)\r\n#16 0x000075e58c5ddf28 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ddf28)\r\n#17 0x000075e58c5de0cb bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1de0cb)\r\n#18 0x000075e58c5e2299 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1e2299)\r\n#19 0x000075e58c5e8c0f llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1e8c0f)\r\n#20 0x000075e58c5e9876 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1e9876)\r\n#21 0x000075e58ced5195 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd5195)\r\n#22 0x000075e58a15de5d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35de5d)\r\n#23 0x000075e5904d9d05 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd9d05)\r\n#24 0x000075e58a15bf96 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35bf96)\r\n#25 0x000075e5904da6c5 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xda6c5)\r\n#26 0x000075e58a15cb1a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35cb1a)\r\n#27 0x000075e591c041c1 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2d1c1)\r\n#28 0x000075e591c0f944 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38944)\r\n#29 0x000075e591429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#30 0x000075e591429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#31 0x000075e591429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#32 0x00005b421cc0e095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\nllvm version: 2b84ef06ac55ac8de3c210d059ec3a3c96666a90", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
127128
https://github.com/llvm/llvm-project/issues/127128
crash
1ff5f328d9824694cc356ebf78adad8816a6de86
2025-02-13T20:59:01
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "ac217ee389d63124432e5e6890851a678f7a676b", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13206, 13213 ] ], "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" ], "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 ac217ee389d63124432e5e6890851a678f7a676b Author: Alexey Bataev <[email protected]> Date: Thu Feb 13 14:19:51 2025 -0800 [SLP] Check for PHI nodes (potentially cycles!) when checking dependencies When checking for dependecies for gather nodes with users with the same last instruction, cannot rely on the index order, if there is (even potential!) cycle in the graph, which may cause order not work correctly and cause compiler crash. Fixes #127128 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index fb72a112b9ac..780cafe91d6b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13206,8 +13206,16 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry( continue; // If the user instruction is used for some reason in different // vectorized nodes - make it depend on index. + // If any vector node is PHI node, this dependency might not work + // because of cycle dependencies, so disable it. if (TEUseEI.UserTE != UseEI.UserTE && - TEUseEI.UserTE->Idx < UseEI.UserTE->Idx) + (TEUseEI.UserTE->Idx < UseEI.UserTE->Idx || + any_of( + VectorizableTree, + [](const std::unique_ptr<TreeEntry> &TE) { + return TE->State == TreeEntry::Vectorize && + TE->getOpcode() == Instruction::PHI; + }))) continue; }
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/delayed-gather-emission.ll", "commands": [ "opt -passes=slp-vectorizer -mtriple=x86_64 -mattr=+avx2 -S < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nentry:\n %.pre.pre = load float, ptr poison, align 4\n br label %bb1\n\nbb1: ; preds = %bb2, %entry\n %.pre = phi float [ %.pre.pre, %entry ], [ %i2, %bb2 ]\n %foxtrot.0 = phi float [ undef, %entry ], [ %gulf.0, %bb2 ]\n br label %bb2\n\nbb2: ; preds = %bb2, %bb1\n %i = phi float [ %.pre, %bb1 ], [ %i2, %bb2 ]\n %gulf.0 = phi float [ %foxtrot.0, %bb1 ], [ %div, %bb2 ]\n %div = fdiv float %i, %gulf.0\n %i1 = load float, ptr poison, align 4\n %div1 = fdiv float %gulf.0, %i1\n %mul = fmul float %div, %div1\n tail call void @foo(float %mul)\n %i2 = load float, ptr poison, align 4\n %tobool = fcmp une float %i2, 0.000000e+00\n br i1 %tobool, label %bb1, label %bb2\n}\n\ndeclare void @foo(float)\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/SLPVectorizer/X86/phi-node-with-cycle.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mcpu=haswell < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(float %0) {\n;\n %2 = fdiv float 0.000000e+00, 0.000000e+00\n %3 = fdiv float 0.000000e+00, 0.000000e+00\n %4 = fdiv float %0, 0.000000e+00\n br label %5\n\n5:\n %6 = fmul float %4, 0.000000e+00\n %7 = fsub float 0.000000e+00, %6\n %8 = fmul float %3, 0.000000e+00\n %9 = fsub float 0.000000e+00, %8\n br label %11\n\n10:\n br label %11\n\n11:\n %12 = phi float [ %7, %5 ], [ 0.000000e+00, %10 ]\n %13 = phi float [ %9, %5 ], [ 0.000000e+00, %10 ]\n br label %14\n\n14:\n %15 = fmul float %2, 0.000000e+00\n %16 = fsub float %12, %15\n %17 = fmul float %4, 0.000000e+00\n %18 = fsub float %13, %17\n %19 = fadd float %16, %18\n %20 = call float @llvm.fabs.f32(float %19)\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "SLPVectorizer miscompilation", "body": "```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:10:11:12:13\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine swiftcc { ptr addrspace(10), i8 } @julia__dir2ori_404(float %0) {\n %2 = fdiv float 0.000000e+00, 0.000000e+00\n %3 = fdiv float 0.000000e+00, 0.000000e+00\n %4 = fdiv float %0, 0.000000e+00\n br label %5\n\n5: ; preds = %1\n %6 = fmul float %4, 0.000000e+00\n %7 = fsub float 0.000000e+00, %6\n %8 = fmul float %3, 0.000000e+00\n %9 = fsub float 0.000000e+00, %8\n br label %11\n\n10: ; No predecessors!\n br label %11\n\n11: ; preds = %10, %5\n %12 = phi float [ %7, %5 ], [ 0.000000e+00, %10 ]\n %13 = phi float [ %9, %5 ], [ 0.000000e+00, %10 ]\n br label %14\n\n14: ; preds = %11\n %15 = fmul float %2, 0.000000e+00\n %16 = fsub float %12, %15\n %17 = fmul float %4, 0.000000e+00\n %18 = fsub float %13, %17\n %19 = fadd float %16, %18\n %20 = call float @llvm.fabs.f32(float %19)\n ret { ptr addrspace(10), i8 } zeroinitializer\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.fabs.f32(float) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```\nproduces \n```\nInstruction does not dominate all uses!\n %4 = insertelement <2 x float> <float poison, float 0.000000e+00>, float %0, i32 0\n %2 = shufflevector <2 x float> %4, <2 x float> <float 0.000000e+00, float poison>, <2 x i32> <i32 2, i32 0>\nLLVM ERROR: Broken module found, compilation aborted!\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 -mcpu=haswell <source>\n1.\tRunning pass \"verify\" on module \"<source>\"\n #0 0x00000000054edec8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54edec8)\n #1 0x00000000054eb884 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007faaea842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007faaea8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007faaea842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007faaea8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000000000082790d llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\n #7 0x000000000542b6e8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x542b6e8)\n #8 0x0000000005329278 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5329278)\n #9 0x000000000095605e 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+0x95605e)\n#10 0x00000000052e7b50 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52e7b50)\n#11 0x000000000096174a 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+0x96174a)\n#12 0x0000000000953c7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x953c7c)\n#13 0x00007faaea829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#14 0x00007faaea829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#15 0x000000000094b555 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x94b555)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\non 19 and trunk.\nGodbolt: https://godbolt.org/z/qxKP6198T", "author": "Zentrik", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "Zentrik", "body": "Bisected thanks to manyclangs to 66775f8ccdcc8264ef349518e1c59d96d4227823 (8e2b2c4181506efc5b9321c203dd107bbd63392b seemed to be good) @alexey-bataev" } ] }
true
null
129242
https://github.com/llvm/llvm-project/issues/129242
crash
5faa5f848a35de13196f2f516f51aa970da942b4
2025-02-28T13:35:26
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "a36a67c79afaa1fdd0dbe0440ec852fd4eb3a532", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 11425, 11435 ] ], "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::getEntryCost" ], "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 a36a67c79afaa1fdd0dbe0440ec852fd4eb3a532 Author: Alexey Bataev <[email protected]> Date: Fri Feb 28 13:15:46 2025 -0800 [SLP]Fix the analysis of the user buildvector nodes for minbitwidth If the user node is a buildvector/gather node and it has no internal instructions state, need to check properly for this state and check the type of the node itself, not its operands. Fixes #129242 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4a68e0ee5989..4f3fd6d53909 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -11425,11 +11425,14 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, E->Idx != 0 && (E->getOpcode() != Instruction::Load || E->UserTreeIndex)) { const EdgeInfo &EI = E->UserTreeIndex; - if (EI.UserTE->getOpcode() != Instruction::Select || + if (!EI.UserTE->hasState() || + EI.UserTE->getOpcode() != Instruction::Select || EI.EdgeIdx != 0) { auto UserBWIt = MinBWs.find(EI.UserTE); Type *UserScalarTy = - EI.UserTE->getOperand(EI.EdgeIdx).front()->getType(); + EI.UserTE->isGather() + ? EI.UserTE->Scalars.front()->getType() + : EI.UserTE->getOperand(EI.EdgeIdx).front()->getType(); if (UserBWIt != MinBWs.end()) UserScalarTy = IntegerType::get(ScalarTy->getContext(), UserBWIt->second.first);
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/user-buildvector-with-minbiwidth.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(i8 %0, i32 %conv2, i1 %cmp.i, i64 %shl.i) {\n;\nentry:\n %conv21 = sext i8 %0 to i32\n %conv7 = zext i32 %conv2 to i64\n %cond.i = shl i64 %conv7, %shl.i\n %1 = and i64 %cond.i, 4294967295\n %.not = icmp eq i64 %1, 1\n %conv7.1 = zext i32 %conv2 to i64\n %cond.i.1 = shl i64 %conv7.1, %shl.i\n %2 = and i64 %cond.i.1, 4294967295\n %.not.1 = icmp eq i64 %2, 1\n %sub.2 = or i32 %conv21, 1\n %cond.2 = select i1 %cmp.i, i32 %sub.2, i32 0\n %conv7.2 = zext i32 %cond.2 to i64\n %cmp.i.2 = icmp slt i32 %cond.2, 1\n %shl.i.2 = zext i1 %cmp.i.2 to i64\n %cond.i.2 = shl i64 %conv7.2, %shl.i.2\n %3 = and i64 %cond.i.2, 4294967295\n %.not.2 = icmp eq i64 %3, 1\n %sub.3 = or i32 %conv21, 1\n %cond.3 = select i1 %cmp.i, i32 %sub.3, i32 0\n %conv7.3 = zext i32 %cond.3 to i64\n %cmp.i.3 = icmp slt i32 %cond.3, 1\n %shl.i.3 = zext i1 %cmp.i.3 to i64\n %cond.i.3 = shl i64 %conv7.3, %shl.i.3\n %4 = and i64 %cond.i.3, 4294967295\n %.not.3 = icmp eq i64 %4, 1\n %sub.4 = or i32 %conv21, 1\n %cond.4 = select i1 %cmp.i, i32 %sub.4, i32 0\n %conv7.4 = zext i32 %cond.4 to i64\n %cmp.i.4 = icmp slt i32 %cond.4, 1\n %shl.i.4 = zext i1 %cmp.i.4 to i64\n %cond.i.4 = shl i64 %conv7.4, %shl.i.4\n %5 = and i64 %cond.i.4, 4294967295\n %.not.4 = icmp eq i64 %5, 1\n %sub.5 = or i32 %conv21, 1\n %cond.5 = select i1 %cmp.i, i32 %sub.5, i32 0\n %conv7.5 = zext i32 %cond.5 to i64\n %cmp.i.5 = icmp slt i32 %cond.5, 1\n %shl.i.5 = zext i1 %cmp.i.5 to i64\n %cond.i.5 = shl i64 %conv7.5, %shl.i.5\n %6 = and i64 %cond.i.5, 4294967295\n %.not.5 = icmp eq i64 %6, 1\n %sub.6 = or i32 %conv21, 1\n %cond.6 = select i1 %cmp.i, i32 %sub.6, i32 0\n %conv7.6 = zext i32 %cond.6 to i64\n %cmp.i.6 = icmp slt i32 %cond.6, 1\n %shl.i.6 = zext i1 %cmp.i.6 to i64\n %cond.i.6 = shl i64 %conv7.6, %shl.i.6\n %7 = and i64 %cond.i.6, 4294967295\n %.not.6 = icmp eq i64 %7, 1\n %sub.7 = or i32 %conv21, 1\n %cond.7 = select i1 %cmp.i, i32 %sub.7, i32 0\n %conv7.7 = zext i32 %cond.7 to i64\n %cmp.i.7 = icmp slt i32 %cond.7, 1\n %shl.i.7 = zext i1 %cmp.i.7 to i64\n %cond.i.7 = shl i64 %conv7.7, %shl.i.7\n %8 = and i64 %cond.i.7, 4294967295\n %.not.7 = icmp eq i64 %8, 1\n %sub.8 = or i32 %conv21, 1\n %cond.8 = select i1 %cmp.i, i32 %sub.8, i32 0\n %conv7.8 = zext i32 %cond.8 to i64\n %cmp.i.8 = icmp slt i32 %cond.8, 1\n %shl.i.8 = zext i1 %cmp.i.8 to i64\n %cond.i.8 = shl i64 %conv7.8, %shl.i.8\n %9 = and i64 %cond.i.8, 4294967295\n %.not.8 = icmp eq i64 %9, 1\n %sub.9 = or i32 %conv21, 1\n %cond.9 = select i1 %cmp.i, i32 %sub.9, i32 0\n %conv7.9 = zext i32 %cond.9 to i64\n %cmp.i.9 = icmp slt i32 %cond.9, 1\n %shl.i.9 = zext i1 %cmp.i.9 to i64\n %cond.i.9 = shl i64 %conv7.9, %shl.i.9\n %10 = and i64 %cond.i.9, 4294967295\n %.not.9 = icmp eq i64 %10, 1\n br label %while.body\n\nwhile.body:\n br i1 %.not, label %for.inc, label %if.then10\n\nif.then10:\n br label %for.inc\n\nfor.inc:\n br i1 %.not.1, label %for.inc.1, label %if.then10.1\n\nif.then10.1:\n br label %for.inc.1\n\nfor.inc.1:\n br i1 %.not.2, label %for.inc.2, label %if.then10.2\n\nif.then10.2:\n br label %for.inc.2\n\nfor.inc.2:\n br i1 %.not.3, label %for.inc.3, label %if.then10.3\n\nif.then10.3:\n br label %for.inc.3\n\nfor.inc.3:\n br i1 %.not.4, label %for.inc.4, label %if.then10.4\n\nif.then10.4:\n br label %for.inc.4\n\nfor.inc.4:\n br i1 %.not.5, label %for.inc.5, label %if.then10.5\n\nif.then10.5:\n br label %for.inc.5\n\nfor.inc.5:\n br i1 %.not.6, label %for.inc.6, label %if.then10.6\n\nif.then10.6:\n br label %for.inc.6\n\nfor.inc.6:\n br i1 %.not.7, label %for.inc.7, label %if.then10.7\n\nif.then10.7:\n br label %for.inc.7\n\nfor.inc.7:\n br i1 %.not.8, label %for.inc.8, label %if.then10.8\n\nif.then10.8:\n br label %for.inc.8\n\nfor.inc.8:\n br i1 %.not.9, label %while.body, label %if.then10.9\n\nif.then10.9:\n br label %while.body\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "clang crashes on valid code at -O{2,3} on x86_64-linux-gnu: Assertion `valid() && \"InstructionsState is invalid.\"' 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/8KTq9hGv9\n\n```\n[516] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git d0edd931bcc328b9502289d346f2b2219341f853)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[517] % \n[517] % clangtk -O2 -w small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:821: llvm::Instruction* {anonymous}::InstructionsState::getMainOp() const: Assertion `valid() && \"InstructionsState is invalid.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, 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/20250227-clangtk-m64-O3-build-235136/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250227-clangtk-m64-O3-build-235136/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 -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-933a0f.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 0x00005597e9b142df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x455e2df)\n #1 0x00005597e9b11ab4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007fa06c8aa420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007fa06c2e100b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007fa06c2c0859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007fa06c2c0729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007fa06c2c0729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007fa06c2d1fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x00005597eb591745 (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5fdb745)\n #9 0x00005597eb62a4e5 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&)::'lambda0'(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>)::operator()(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>) const SLPVectorizer.cpp:0:0\n#10 0x00005597eb633034 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x607d034)\n#11 0x00005597eb668741 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60b2741)\n#12 0x00005597eb672691 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60bc691)\n#13 0x00005597eb676e5e 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+0x60c0e5e)\n#14 0x00005597eb6773db llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#15 0x00005597eb67ac20 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60c4c20)\n#16 0x00005597eb681396 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 0x00005597eb681ef3 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x60cbef3)\n#18 0x00005597eb104166 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+0x5b4e166)\n#19 0x00005597e948caf9 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+0x3ed6af9)\n#20 0x00005597e6d6c406 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+0x17b6406)\n#21 0x00005597e948b362 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x3ed5362)\n#22 0x00005597e6d6a4b6 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+0x17b44b6)\n#23 0x00005597e948ad81 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+0x3ed4d81)\n#24 0x00005597e9ddb283 (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 0x00005597e9ddf573 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+0x4829573)\n#26 0x00005597ea51bba0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f65ba0)\n#27 0x00005597ebe39acc clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6883acc)\n#28 0x00005597ea51bfc8 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4f65fc8)\n#29 0x00005597ea7f2779 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x523c779)\n#30 0x00005597ea77325e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51bd25e)\n#31 0x00005597ea8e7626 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5331626)\n#32 0x00005597e68fefb7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1348fb7)\n#33 0x00005597e68f66ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#34 0x00005597e68fa97a clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x134497a)\n#35 0x00005597e67edccb main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1237ccb)\n#36 0x00007fa06c2c2083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#37 0x00005597e68f617e _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x134017e)\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 d0edd931bcc328b9502289d346f2b2219341f853)\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-fd80bc.c\nclangtk: note: diagnostic msg: /tmp/small-fd80bc.sh\nclangtk: note: diagnostic msg: \n\n********************\n[518] % \n[518] % cat small.c\nint a[1], g;\nchar b, c;\nvolatile int d;\nlong e, f;\nlong h(long i) { return i > 1 ? i : i << 1; }\nint main() {\n if (g)\n while (1) {\n b = 0;\n for (; b < 10; b++) {\n e = c & b ? 0 : c - b;\n f = h(e);\n g = (a != 0) % (unsigned)f;\n if (g)\n d;\n }\n }\n return 0;\n}\n```\n\n", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
82230
https://github.com/llvm/llvm-project/issues/82230
crash
769c22f25b81b74e4da7871d4e552584605caef1
2024-02-19T09:37:19
[ "llvm/test/DebugInfo" ]
{ "fix_commit": "5b342e6041f8567a39354ae3c5346cf74b3bb84f", "components": [ "IR" ], "bug_location_lineno": { "llvm/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": [ [ 293, 299 ], [ 4886, 4893 ] ], "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": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": [ "DPValue::print", "PrintCallingConv", "getModuleFromDPI" ], "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 5b342e6041f8567a39354ae3c5346cf74b3bb84f Author: Stephen Tozer <[email protected]> Date: Mon Feb 19 11:38:04 2024 +0000 [RemoveDIs][DebugInfo] Check for null marker when printing DPValues (#82238) The function to print DPValues currently tries to incorporate the function it is part of, which is found through its marker; this means when we try to print a DPValue with no marker, we dereference a nullptr. We can print instructions without parents, and so the same should be true for DPValues; this patch changes DPValue::print to check for a null marker and avoid dereferencing it. Fixes issue: https://github.com/llvm/llvm-project/issues/82230 diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 0ae720e8b7ce..d3c64a57f7fd 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -293,7 +293,7 @@ static const Module *getModuleFromDPI(const DPMarker *Marker) { } static const Module *getModuleFromDPI(const DPValue *DPV) { - return getModuleFromDPI(DPV->getMarker()); + return DPV->getMarker() ? getModuleFromDPI(DPV->getMarker()) : nullptr; } static void PrintCallingConv(unsigned cc, raw_ostream &Out) { @@ -4886,8 +4886,9 @@ void DPValue::print(raw_ostream &ROS, ModuleSlotTracker &MST, if (F) MST.incorporateFunction(*F); }; - incorporateFunction(Marker->getParent() ? Marker->getParent()->getParent() - : nullptr); + incorporateFunction(Marker && Marker->getParent() + ? Marker->getParent()->getParent() + : nullptr); AssemblyWriter W(OS, SlotTable, getModuleFromDPI(this), nullptr, IsForDebug); W.printDPValue(*this); }
[ { "file": "llvm/test/DebugInfo/dpvalue-print-nocrash.ll", "commands": [ "opt -passes=\"instcombine\" -debug %s -o /dev/null 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": ";; Tests that we can debug-print DPValues that have no markers attached.\n; REQUIRES: asserts\n\n\ndefine ptr @func_10(i32 %p_11) {\nentry:\n %conv108 = zext i32 %p_11 to i64\n tail call void @llvm.dbg.value(metadata i64 %conv108, metadata !4, metadata !DIExpression()), !dbg !12\n br label %func_29.exit\n\nfunc_29.exit: ; preds = %entry\n store i64 %conv108, ptr null, align 1\n ret ptr null\n}\n\ndeclare void @llvm.dbg.value(metadata, metadata, metadata)\n\n!llvm.dbg.cu = !{!0}\n!llvm.module.flags = !{!3}\n\n!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: \"clang\", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)\n!1 = !DIFile(filename: \"csmith5961503756960.c\", directory: \"/llvm\")\n!2 = !{}\n!3 = !{i32 2, !\"Debug Info Version\", i32 3}\n!4 = !DILocalVariable(name: \"p_31\", arg: 2, scope: !5, file: !1, line: 148, type: !7)\n!5 = distinct !DISubprogram(name: \"func_29\", scope: !1, file: !1, line: 148, type: !6, scopeLine: 149, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)\n!6 = !DISubroutineType(types: !2)\n!7 = !DIDerivedType(tag: DW_TAG_typedef, name: \"uint64_t\", file: !8, line: 60, baseType: !9)\n!8 = !DIFile(filename: \"/foo/_stdint.h\", directory: \"\")\n!9 = !DIDerivedType(tag: DW_TAG_typedef, name: \"__uint64_t\", file: !10, line: 108, baseType: !11)\n!10 = !DIFile(filename: \"/foo/_default_types.h\", directory: \"\")\n!11 = !DIBasicType(name: \"unsigned long long\", size: 64, encoding: DW_ATE_unsigned)\n!12 = !DILocation(line: 0, scope: !5)", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "opt -passes=\"instcombine\" -debug crashes with non-instrinsic debug-info", "body": "llvm commit: d61864f813e3\r\nReproduce with:\r\n```\r\nopt -passes=\"instcombine\" -debug bbi-92509.ll -o /dev/null\r\n```\r\n[bbi-92509.ll.gz](https://github.com/llvm/llvm-project/files/14329283/bbi-92509.ll.gz)\r\n\r\nResult:\r\n```\r\nINSTCOMBINE ITERATION #1 on func_10\r\nADD: ret ptr null\r\nADD: store i64 %conv108, ptr null, align 1\r\nADD: br label %func_29.exit\r\nADD: %conv108 = zext i32 %p_11 to i64\r\nCLONE: PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: ../../main-github/llvm/build-all/bin/opt -passes=instcombine -debug bbi-92509.ll -o /dev/null\r\n #0 0x000055e12968f4a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x3db14a7)\r\n #1 0x000055e12968cf7e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x3daef7e)\r\n #2 0x000055e12968fe6f SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fdf33999630 __restore_rt sigaction.c:0:0\r\n #4 0x000055e12971f8e0 llvm::DPMarker::getParent() const (../../main-github/llvm/build-all/bin/opt+0x3e418e0)\r\n #5 0x000055e129761abf llvm::DPValue::print(llvm::raw_ostream&, bool) const (../../main-github/llvm/build-all/bin/opt+0x3e83abf)\r\n #6 0x000055e12a244957 llvm::InstCombinerImpl::tryToSinkInstructionDPValues(llvm::Instruction*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true>, false, false>, llvm::BasicBlock*, llvm::BasicBlock*, llvm::SmallVectorImpl<llvm::DPValue*>&) InstructionCombining.cpp:0:0\r\n #7 0x000055e12a242b0c llvm::InstCombinerImpl::tryToSinkInstruction(llvm::Instruction*, llvm::BasicBlock*) InstructionCombining.cpp:0:0\r\n #8 0x000055e12a2453fc llvm::InstCombinerImpl::run() InstructionCombining.cpp:0:0\r\n #9 0x000055e12a248c79 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, llvm::LoopInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0\r\n#10 0x000055e12a2482ea llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x496a2ea)\r\n#11 0x000055e12a95e5bd llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\r\n#12 0x000055e12989a8e4 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x3fbc8e4)\r\n#13 0x000055e12a9644dd llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) PassBuilderPipelines.cpp:0:0\r\n#14 0x000055e12989f9ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x3fc19ae)\r\n#15 0x000055e12a95dd9d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) PassBuilderPipelines.cpp:0:0\r\n#16 0x000055e129899456 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x3fbb456)\r\n#17 0x000055e12a90a42b llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (../../main-github/llvm/build-all/bin/opt+0x502c42b)\r\n#18 0x000055e129657a28 optMain (../../main-github/llvm/build-all/bin/opt+0x3d79a28)\r\n#19 0x00007fdf310cc555 __libc_start_main (/lib64/libc.so.6+0x22555)\r\n#20 0x000055e129651369 _start (../../main-github/llvm/build-all/bin/opt+0x3d73369)\r\nSegmentation fault (core dumped)\r\n```\r\n\r\nThis starts happening with a93a4ec7dd205\r\n```\r\nReapply \"[DebugInfo][RemoveDIs] Turn on non-instrinsic debug-info by default\"\r\n```\r\n", "author": "mikaelholmen", "labels": [ "debuginfo", "llvm:crash", "llvm:ir" ], "comments": [ { "author": "SLTozer", "body": "Should be fixed by: [5b342e6](https://github.com/llvm/llvm-project/commit/5b342e6041f8567a39354ae3c5346cf74b3bb84f)" }, { "author": "mikaelholmen", "body": "> Should be fixed by: [5b342e6](https://github.com/llvm/llvm-project/commit/5b342e6041f8567a39354ae3c5346cf74b3bb84f)\r\n\r\nYep, thanks!" } ] }
true
null
115732
https://github.com/llvm/llvm-project/issues/115732
crash
da78ac5d331953d3386fd56cd7979022be7400cf
2024-11-11T16:03:33
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "058ac837bc35419bbbb34f3206f5aa229c669811", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 3045, 3051 ], [ 9167, 9174 ], [ 13454, 13460 ], [ 13560, 13566 ], [ 14022, 14028 ] ], "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", "BoUpSLP::setInsertPointAfterBundle", "createFreeze", "createShuffle" ], "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 058ac837bc35419bbbb34f3206f5aa229c669811 Author: Alexey Bataev <[email protected]> Date: Mon Nov 11 10:48:15 2024 -0800 [SLP]Use generic createShuffle for buildvector Use generic createShuffle function, which know how to adjust the vectors correctly, to avoid compiler crash when trying to build a buildvector as a shuffle Fixes #115732 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index da8e0d8cc09a..1bf082d57b8b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3045,7 +3045,9 @@ private: /// \returns a vector from a collection of scalars in \p VL. if \p Root is not /// specified, the starting vector value is poison. - Value *gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy); + Value * + gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy, + function_ref<Value *(Value *, Value *, ArrayRef<int>)> CreateShuffle); /// \returns whether the VectorizableTree is fully vectorizable and will /// be beneficial even the tree height is tiny. @@ -9167,8 +9169,9 @@ protected: int VF = Mask.size(); if (auto *FTy = dyn_cast<FixedVectorType>(V1->getType())) VF = FTy->getNumElements(); - if (V2 && - !isUndefVector(V2, buildUseMask(VF, Mask, UseMask::SecondArg)).all()) { + if (V2 && !isUndefVector</*IsPoisonOnly=*/true>( + V2, buildUseMask(VF, Mask, UseMask::SecondArg)) + .all()) { // Peek through shuffles. Value *Op1 = V1; Value *Op2 = V2; @@ -13454,7 +13457,9 @@ void BoUpSLP::setInsertPointAfterBundle(const TreeEntry *E) { Builder.SetCurrentDebugLocation(Front->getDebugLoc()); } -Value *BoUpSLP::gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy) { +Value *BoUpSLP::gather( + ArrayRef<Value *> VL, Value *Root, Type *ScalarTy, + function_ref<Value *(Value *, Value *, ArrayRef<int>)> CreateShuffle) { // List of instructions/lanes from current block and/or the blocks which are // part of the current loop. These instructions will be inserted at the end to // make it possible to optimize loops and hoist invariant instructions out of @@ -13560,7 +13565,7 @@ Value *BoUpSLP::gather(ArrayRef<Value *> VL, Value *Root, Type *ScalarTy) { if (isa<PoisonValue>(Vec)) { Vec = OriginalRoot; } else { - Vec = Builder.CreateShuffleVector(Root, Vec, Mask); + Vec = CreateShuffle(Root, Vec, Mask); if (auto *OI = dyn_cast<Instruction>(OriginalRoot); OI && OI->hasNUses(0)) eraseInstruction(OI); @@ -14022,7 +14027,10 @@ public: } Value *gather(ArrayRef<Value *> VL, unsigned MaskVF = 0, Value *Root = nullptr) { - return R.gather(VL, Root, ScalarTy); + return R.gather(VL, Root, ScalarTy, + [&](Value *V1, Value *V2, ArrayRef<int> Mask) { + return createShuffle(V1, V2, Mask); + }); } Value *createFreeze(Value *V) { return Builder.CreateFreeze(V); } /// Finalize emission of the shuffles.
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-shuffle-with-root.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-99999 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test(i16 %arg) {\n;\nbb:\n %sitofp = sitofp i16 %arg to float\n %fadd = fadd float 0.000000e+00, 0.000000e+00\n %fsub = fsub float 0.000000e+00, %sitofp\n %fsub1 = fsub float 0.000000e+00, %sitofp\n %fsub2 = fsub float 0.000000e+00, %sitofp\n %sitofp3 = sitofp i16 0 to float\n %fsub4 = fsub float %fadd, %sitofp3\n store float %fsub4, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 20), align 4\n %fsub5 = fsub float %fsub, %sitofp\n store float %fsub5, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 24), align 4\n %fsub6 = fsub float %fsub1, %sitofp\n store float %fsub6, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 28), align 4\n %fsub7 = fsub float %fsub2, %sitofp\n store float %fsub7, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 32), align 4\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `isValidOperands(V1, V2, Mask) && \"Invalid shuffle vector instruction operands!\"' 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(i16 %arg) gc \"statepoint-example\" {\r\nbb:\r\n %sitofp = sitofp i16 %arg to float\r\n %fadd = fadd float 0.000000e+00, 0.000000e+00\r\n %fsub = fsub float 0.000000e+00, %sitofp\r\n %fsub1 = fsub float 0.000000e+00, %sitofp\r\n %fsub2 = fsub float 0.000000e+00, %sitofp\r\n %sitofp3 = sitofp i16 0 to float\r\n %fsub4 = fsub float %fadd, %sitofp3\r\n store float %fsub4, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 20), align 4\r\n %fsub5 = fsub float %fsub, %sitofp\r\n store float %fsub5, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 24), align 4\r\n %fsub6 = fsub float %fsub1, %sitofp\r\n store float %fsub6, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 28), align 4\r\n %fsub7 = fsub float %fsub2, %sitofp\r\n store float %fsub7, ptr addrspace(1) getelementptr inbounds (i8, ptr addrspace(1) null, i64 32), align 4\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/6h4xzhGa1\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 0x00000000051494c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51494c8)\r\n #1 0x0000000005146ebc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000072f583642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000072f5836969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000072f583642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000072f5836287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000072f58362871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000072f583639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004eb74ce llvm::ShuffleVectorInst::ShuffleVectorInst(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, llvm::Twine const&, llvm::InsertPosition) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eb74ce)\r\n #9 0x0000000000d09e93 llvm::IRBuilderBase::CreateShuffleVector(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, llvm::Twine const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xd09e93)\r\n#10 0x00000000041a0bdd llvm::slpvectorizer::BoUpSLP::gather(llvm::ArrayRef<llvm::Value*>, llvm::Value*, llvm::Type*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41a0bdd)\r\n#11 0x00000000041a13fc void llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>::callback_fn<llvm::Value* llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder, llvm::Value*, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>, llvm::slpvectorizer::BoUpSLP>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>&, llvm::slpvectorizer::BoUpSLP&)::'lambda15'(llvm::Value*&, llvm::SmallVectorImpl<int>&)>(long, llvm::Value*&, llvm::SmallVectorImpl<int>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41a13fc)\r\n#12 0x00000000041a26b9 llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::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+0x41a26b9)\r\n#13 0x00000000041d5335 llvm::Value* llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder, llvm::Value*, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>, llvm::slpvectorizer::BoUpSLP>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>&, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41d5335)\r\n#14 0x00000000041e168e llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e168e)\r\n#15 0x000000000420234a 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+0x420234a)\r\n#16 0x0000000004205c7d llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4205c7d)\r\n#17 0x0000000004224402 llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4224402)\r\n#18 0x0000000004225e6b llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::'lambda'(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&)::operator()(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&) const SLPVectorizer.cpp:0:0\r\n#19 0x0000000004227d98 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4227d98)\r\n#20 0x00000000042285e9 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42285e9)\r\n#21 0x0000000004229b35 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#22 0x000000000422a63b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422a63b)\r\n#23 0x0000000002f9948e 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+0x2f9948e)\r\n#24 0x0000000004f47488 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f47488)\r\n#25 0x0000000000e3bf3e 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+0xe3bf3e)\r\n#26 0x0000000004f45eae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f45eae)\r\n#27 0x0000000000e3b64e 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+0xe3b64e)\r\n#28 0x0000000004f458e0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f458e0)\r\n#29 0x000000000091103a 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+0x91103a)\r\n#30 0x000000000090399a optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90399a)\r\n#31 0x000072f583629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#32 0x000072f583629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#33 0x00000000008fb41e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fb41e)\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
116775
https://github.com/llvm/llvm-project/issues/116775
crash
bdf00e2216280edef1ec91ccc07987db92197b59
2024-11-19T09:53:12
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "03d8831fa8ef5b7e32172c718b550a454645faea", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 997, 1003 ] ], "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 03d8831fa8ef5b7e32172c718b550a454645faea Author: Yingwei Zheng <[email protected]> Date: Tue Nov 19 22:17:24 2024 +0800 [InstCombine] Handle constant GEP expr in `SimplifyDemandedUseBits` (#116794) Closes https://github.com/llvm/llvm-project/issues/116775. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 5eb807dcb76c..392c5c78345c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -997,7 +997,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, uint64_t MaskedGEPIndex = HighBitsGEPIndex | MaskedLowBitsGEPIndex; if (MaskedGEPIndex != GEPIndex) { - auto *GEP = cast<GetElementPtrInst>(II->getArgOperand(0)); + auto *GEP = cast<GEPOperator>(II->getArgOperand(0)); Builder.SetInsertPoint(I); Type *GEPIndexType = DL.getIndexType(GEP->getPointerOperand()->getType());
[ { "file": "llvm/test/Transforms/InstCombine/ptrmask.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "ptrmask_demandedbits_constantexpr", "test_body": "target datalayout = \"p1:64:64:64:32\"\n\n@GC_arrays = external global { i8, i8, i64 }\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare ptr @llvm.ptrmask.p0.i64(ptr, i64) #0\n\ndefine ptr @ptrmask_demandedbits_constantexpr() {\nentry:\n %aligned_result = call ptr @llvm.ptrmask.p0.i64(ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 1), i64 -8)\n ret ptr %aligned_result\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "ptrmask_is_useless_fail1", "test_body": "target datalayout = \"p1:64:64:64:32\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare ptr @llvm.ptrmask.p0.i64(ptr, i64) #0\n\ndefine ptr @ptrmask_is_useless_fail1(i64 %i, i64 %m) {\n %m0 = and i64 %m, 127\n %i0 = and i64 %i, 511\n %p0 = inttoptr i64 %i0 to ptr\n %r = call ptr @llvm.ptrmask.p0.i64(ptr %p0, i64 %m0)\n ret ptr %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Segfault when building https://github.com/ivmai/bdwgc@4fe4238", "body": "Attempting to build [https://github.com/ivmai/bdwgc@4fe4238](https://github.com/ivmai/bdwgc/tree/4fe42389509ff059bad8d4c955a570b34a6bda4b) using\r\n```shell\r\n$ ./autogen.sh\r\n$ ./configure --with-libatomic-ops --enable-cplusplus --enable-large-config\r\n$ make\r\n```\r\nresults in\r\n```text\r\nlibtool: compile: clang -std=gnu23 -DHAVE_CONFIG_H -I./include -I./include -DNDEBUG -fexceptions -DGC_VISIBILITY_HIDDEN_SET -fvisibility=hidden -Wall -Wextra -Wpedantic -Wno-long-long -O2 -march=native -Wno-frame-address -MT extra/gc.lo -MD -MP -MF extra/.deps/gc.Tpo -c extra/gc.c -fno-common -DPIC -o extra/.libs/gc.o\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: clang -std=gnu23 -DHAVE_CONFIG_H -I./include -I./include -DNDEBUG -fexceptions -DGC_VISIBILITY_HIDDEN_SET -fvisibility=hidden -Wall -Wextra -Wpedantic -Wno-long-long -O2 -march=native -Wno-frame-address -MT extra/gc.lo -MD -MP -MF extra/.deps/gc.Tpo -c extra/gc.c -fno-common -DPIC -o extra/.libs/gc.o\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide)),function(invalidate<should-not-run-function-passes>),cgscc(devirt<4>())\" on module \"extra/gc.c\"\r\n4.\tRunning pass \"cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide))\" on module \"extra/gc.c\"\r\n5.\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"GC_push_finalizer_structures\"\r\n #0 0x0000000112ecda98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x3299a98)\r\n #1 0x0000000112eccb47 llvm::sys::RunSignalHandlers() (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x3298b47)\r\n #2 0x0000000112eccde1 llvm::sys::CleanupOnSignal(unsigned long) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x3298de1)\r\n #3 0x0000000112df2644 CrashRecoverySignalHandler(int) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x31be644)\r\n #4 0x00007ff81abe4fdd (/usr/lib/system/libsystem_platform.dylib+0x7ff80046afdd)\r\n #5 0x0000000112e1d131 computeForAddCarry(llvm::KnownBits const&, llvm::KnownBits const&, bool, bool) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x31e9131)\r\n #6 0x0000000112318cdd llvm::TargetFolder::FoldGEP(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::GEPNoWrapFlags) const (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26e4cdd)\r\n #7 0x00000001102d2177 llvm::IRBuilderBase::CreateGEP(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::GEPNoWrapFlags) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x69e177)\r\n #8 0x000000011209545a llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Instruction*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x246145a)\r\n #9 0x0000000112097524 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&, llvm::KnownBits&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2463524)\r\n#10 0x0000000111ffc58b llvm::InstCombinerImpl::visitCallInst(llvm::CallInst&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x23c858b)\r\n#11 0x0000000111f85788 llvm::InstCombinerImpl::run() (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2351788)\r\n#12 0x0000000111f765e2 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x23425e2)\r\n#13 0x0000000111fc1b85 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x238db85)\r\n#14 0x0000000110596272 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x962272)\r\n#15 0x0000000112b6736a llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2f3336a)\r\n#16 0x000000011003f522 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x40b522)\r\n#17 0x00000001122fe7db llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26ca7db)\r\n#18 0x0000000110b41712 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0xf0d712)\r\n#19 0x00000001122fa573 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26c6573)\r\n#20 0x0000000110b3e332 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0xf0a332)\r\n#21 0x00000001122fcc0e llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26c8c0e)\r\n#22 0x0000000110b413a2 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0xf0d3a2)\r\n#23 0x00000001122fbe83 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x26c7e83)\r\n#24 0x0000000110b3e012 llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0xf0a012)\r\n#25 0x0000000112b65a22 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2f31a22)\r\n#26 0x0000000110d25d8b llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x10f1d8b)\r\n#27 0x0000000110594012 llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x960012)\r\n#28 0x0000000112b65a22 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x2f31a22)\r\n#29 0x000000010788b478 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>&, std::__1::unique_ptr<llvm::ToolOutputFile, std::__1::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x172d478)\r\n#30 0x0000000107883b08 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x1725b08)\r\n#31 0x0000000107d037d3 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x1ba57d3)\r\n#32 0x000000010635df1d clang::ParseAST(clang::Sema&, bool, bool) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x1fff1d)\r\n#33 0x000000010877f3d7 clang::FrontendAction::Execute() (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x26213d7)\r\n#34 0x00000001086e0500 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x2582500)\r\n#35 0x00000001087f60e9 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x26980e9)\r\n#36 0x000000010128d4f9 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/llvm-project@HEAD/bin/clang-20+0x1000084f9)\r\n#37 0x0000000101289f88 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/opt/llvm-project@HEAD/bin/clang-20+0x100004f88)\r\n#38 0x00000001082b552e void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x215752e)\r\n#39 0x0000000112df288c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/llvm-project@HEAD/lib/libLLVM.dylib+0x31be88c)\r\n#40 0x00000001082b5431 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x2157431)\r\n#41 0x0000000108262131 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x2104131)\r\n#42 0x00000001082623bf clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x21043bf)\r\n#43 0x00000001082b00c0 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/opt/llvm-project@HEAD/lib/libclang-cpp.dylib+0x21520c0)\r\n#44 0x00000001012892b3 clang_main(int, char**, llvm::ToolContext const&) (/opt/llvm-project@HEAD/bin/clang-20+0x1000042b3)\r\n#45 0x00000001012984cb main (/opt/llvm-project@HEAD/bin/clang-20+0x1000134cb)\r\n#46 0x00007ff81a82a345 \r\nclang: error: clang frontend command failed with exit code 139 (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git c25c6c32494c8d1038438b6208d42ba40f25270e)\r\nTarget: x86_64-apple-darwin23.6.0\r\nThread model: posix\r\nInstalledDir: /opt/llvm-project@HEAD/bin\r\nclang: note: diagnostic msg: \r\n********************\r\n```\r\n\r\nFind attached the preprocessed source code at [gc-add69e.c.gz](https://github.com/user-attachments/files/17813033/gc-add69e.c.gz).", "author": "d125q", "labels": [ "llvm:instcombine", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/Ts478aen6\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\n@GC_arrays = external global { i8, i8, i64 }\r\n\r\ndefine ptr @GC_push_finalizer_structures() {\r\nentry:\r\n %aligned_result.i = call ptr @llvm.ptrmask.p0.i64(ptr getelementptr inbounds (i8, ptr @GC_arrays, i64 1), i64 -8)\r\n ret ptr %aligned_result.i\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::GetElementPtrInst; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=instcombine <source>\r\n1.\tRunning pass \"function(instcombine<max-iterations=1;verify-fixpoint>)\" on module \"<source>\"\r\n2.\tRunning pass \"instcombine<max-iterations=1;verify-fixpoint>\" on function \"GC_push_finalizer_structures\"\r\n #0 0x0000000005194b38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5194b38)\r\n #1 0x000000000519252c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074b7d8442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074b7d84969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074b7d8442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074b7d84287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000074b7d842871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000074b7d8439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000040d9310 decltype(auto) llvm::cast<llvm::GetElementPtrInst, llvm::Value>(llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40d9310)\r\n #9 0x00000000040e2f9e llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Instruction*, llvm::APInt const&, llvm::KnownBits&, unsigned int, llvm::SimplifyQuery const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40e2f9e)\r\n#10 0x00000000040e6082 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&, llvm::KnownBits&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40e6082)\r\n#11 0x00000000040355a6 llvm::InstCombinerImpl::visitCallInst(llvm::CallInst&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40355a6)\r\n#12 0x0000000003fe2311 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe2311)\r\n#13 0x0000000003fe3cc6 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) (.isra.0) InstructionCombining.cpp:0:0\r\n#14 0x0000000003fe504e llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3fe504e)\r\n#15 0x0000000002c5c24e llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2c5c24e)\r\n#16 0x0000000004f949e8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f949e8)\r\n#17 0x0000000000e4027e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe4027e)\r\n#18 0x0000000004f9340e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f9340e)\r\n#19 0x0000000000e3f92e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3f92e)\r\n#20 0x0000000004f92e40 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f92e40)\r\n#21 0x0000000000909fda llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x909fda)\r\n#22 0x00000000008fc70a optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fc70a)\r\n#23 0x000074b7d8429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#24 0x000074b7d8429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#25 0x00000000008f3e9e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f3e9e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```" } ] }
true
null
96294
https://github.com/llvm/llvm-project/issues/96294
crash
5262865aac683b72f3e66de7a122e0c455ab6b9b
2024-06-21T10:15:21
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "fdb9f96fa2a926425bdf8315048db7623d63547d", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 6723, 6736 ], [ 6771, 6776 ], [ 6781, 6788 ] ], "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 fdb9f96fa2a926425bdf8315048db7623d63547d Author: Florian Hahn <[email protected]> Date: Sun Aug 4 20:54:25 2024 +0100 [LV] Consider earlier stores to invariant reduction address as dead. For invariant stores to an address of a reduction, only the latest store will be generated outside the loop. Consider earlier stores as dead. This fixes a difference between the legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/96294. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 40d10395de17..1eca9b10fad5 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6723,14 +6723,18 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { return RequiresScalarEpilogue && !TheLoop->contains(cast<Instruction>(U)->getParent()); }; + MapVector<Value *, SmallVector<Value *>> DeadInvariantStoreOps; for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { // Find all stores to invariant variables. Since they are going to sink // outside the loop we do not need calculate cost for them. StoreInst *SI; if ((SI = dyn_cast<StoreInst>(&I)) && - Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) + Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) { ValuesToIgnore.insert(&I); + auto I = DeadInvariantStoreOps.insert({SI->getPointerOperand(), {}}); + I.first->second.push_back(SI->getValueOperand()); + } if (VecValuesToIgnore.contains(&I) || ValuesToIgnore.contains(&I)) continue; @@ -6771,6 +6775,10 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { DeadInterleavePointerOps.append(Op->op_begin(), Op->op_end()); } + for (const auto &[_, Ops] : DeadInvariantStoreOps) { + for (Value *Op : ArrayRef(Ops).drop_back()) + DeadOps.push_back(Op); + } // Mark ops that would be trivially dead and are only used by ignored // instructions as free. BasicBlock *Header = TheLoop->getHeader(); @@ -6781,8 +6789,8 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { (isa<PHINode>(Op) && Op->getParent() == Header) || !wouldInstructionBeTriviallyDead(Op, TLI) || any_of(Op->users(), [this, IsLiveOutDead](User *U) { - return !VecValuesToIgnore.contains(U) && ValuesToIgnore.contains(U) && - !IsLiveOutDead(U); + return !VecValuesToIgnore.contains(U) && + !ValuesToIgnore.contains(U) && !IsLiveOutDead(U); })) continue;
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": [ "opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S" ], "tests": [ { "test_name": "reduction_store", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine void @reduction_store(ptr noalias %src, ptr %dst, i1 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %red = phi i32 [ 0, %entry ], [ %red.next, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i32, ptr %src, i32 %iv\n %l = load i32, ptr %gep.src, align 4\n %l.and = and i32 %l, 3\n store i32 %l.and, ptr %dst, align 4\n %x.ext = zext i1 %x to i64\n %lshr = lshr i64 %x.ext, 12\n %t = trunc i64 %lshr to i32\n %red.next = and i32 %red, %t\n store i32 %red.next, ptr %dst, align 4\n %iv.next = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 29\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"znver3\" }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10353: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "[calcc-0ebd65.c.gz](https://github.com/user-attachments/files/15926158/calcc-0ebd65.c.gz)\r\n[calcc-0ebd65.sh.gz](https://github.com/user-attachments/files/15926159/calcc-0ebd65.sh.gz)\r\n\r\nStack backtrace is \r\n\r\n#11 0x0000000003adfddd llvm::LoopVectorizePass::processLoop(llvm::Loop*) /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10353:9\r\n#12 0x0000000003ae347f llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10446:27\r\n#13 0x0000000003ae4382 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10486:5\r\n#14 0x00000000034fbd6d llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb40b/llvm/trunk/llvm/include/llvm/IR/PassManagerInternal.h:91:3\r\n#15 0x0000000001ae5b21 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/dcb40b/llvm/trunk/llvm/include/llvm/IR/PassManagerImpl.h:53:18\r\n", "author": "dcb314", "labels": [ "vectorizers", "crash-on-valid" ], "comments": [ { "author": "dcb314", "body": "The crash first seems to occur sometime between git hash fd88089151e66a4cb1d90aaa224e4cb4e7a748f4 from yesterday 20240620\r\nand 225d8fc8eb24fb797154c1ef6dcbe5ba033142da from today,\r\nwhich is 134 commits.\r\n" }, { "author": "fhahn", "body": "Thanks for the report, caused by https://github.com/llvm/llvm-project/pull/92555 which has been reverted for now. I'll add a reduced test based on the reproducer." }, { "author": "fhahn", "body": "https://github.com/llvm/llvm-project/pull/92555 has been recommitted with a fix. Please let me know if you see any other issues!" }, { "author": "dcb314", "body": "It has come back:\r\n\r\nclang: /home/dcb40b/llvm/trunk/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10377: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\n\r\n[in-4e39b8.sh.gz](https://github.com/user-attachments/files/16445872/in-4e39b8.sh.gz)\r\n[Uploading in-4e39b8.c.gz…]()\r\n" }, { "author": "dcb314", "body": "Seems to have come back sometime between d99efd53f5103df4db517f499fcdd26cd3b080a3\r\n(dated 20240710) and 4710e0f498cb661ca17c99cb174616102fcad923, dated 20240711.\r\n\r\n" }, { "author": "fhahn", "body": "@dcb314 it looks like there has been an issue with uploading the `.c` file. Could you re-upload it again?" }, { "author": "dcb314", "body": "My apologies for the failed upload.\r\nHere is another try:\r\n\r\n[in-4e39b8.c.gz](https://github.com/user-attachments/files/16455342/in-4e39b8.c.gz)\r\n" } ] }
true
null
112076
https://github.com/llvm/llvm-project/issues/112076
miscompilation
8c56dd3040f295874e3d5742b5dfc109adf1f728
2024-10-12T03:31:00
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "2c094ac761912eea0d7e8ccb140bc647b5378bdf", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 3466, 3472 ], [ 3501, 3506 ], [ 4148, 4154 ] ], "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", "foldBitCeil" ], "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 2c094ac761912eea0d7e8ccb140bc647b5378bdf Author: Yingwei Zheng <[email protected]> Date: Wed Nov 20 21:15:26 2024 +0800 [InstCombine] Drop range attributes in `foldBitCeil` (#116641) Closes https://github.com/llvm/llvm-project/issues/112076 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 28dbca027037..2526ce7704ab 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3466,7 +3466,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0, // Note that the select is optimized away while the shift count is masked with // 31. We handle some variations of the input operand like std::bit_ceil(X + // 1). -static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) { +static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder, + InstCombinerImpl &IC) { Type *SelType = SI.getType(); unsigned BitWidth = SelType->getScalarSizeInBits(); @@ -3501,6 +3502,10 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) { // single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth // is an integer constant. Masking with BitWidth-1 comes free on some // hardware as part of the shift instruction. + + // Drop range attributes and re-infer them in the next iteration. + cast<Instruction>(Ctlz)->dropPoisonGeneratingAnnotations(); + IC.addToWorklist(cast<Instruction>(Ctlz)); Value *Neg = Builder.CreateNeg(Ctlz); Value *Masked = Builder.CreateAnd(Neg, ConstantInt::get(SelType, BitWidth - 1)); @@ -4148,7 +4153,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { if (sinkNotIntoOtherHandOfLogicalOp(SI)) return &SI; - if (Instruction *I = foldBitCeil(SI, Builder)) + if (Instruction *I = foldBitCeil(SI, Builder, *this)) return I; if (Instruction *I = foldSelectToCmp(SI))
[ { "file": "llvm/test/Transforms/InstCombine/bit_ceil.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_drop_range_attr", "test_body": "define i32 @test_drop_range_attr(i32 %x) {\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\n %sub = sub i32 32, %ctlz\n %shl = shl i32 1, %sub\n %dec = add i32 %x, -1\n %ult = icmp ult i32 %dec, -2\n %sel = select i1 %ult, i32 %shl, i32 1\n ret i32 %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "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] `range` attribute should be dropped in `foldBitCeil`", "body": "Reproducer: https://alive2.llvm.org/ce/z/NQTmkh (Please use latest alive2 with https://github.com/AliveToolkit/alive2/pull/1097)\r\n```\r\ndefine i32 @src(i32 %x) {\r\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %sub = sub i32 32, %ctlz\r\n %shl = shl i32 1, %sub\r\n %dec = add i32 %x, -1\r\n %ult = icmp ult i32 %dec, -2\r\n %sel = select i1 %ult, i32 %shl, i32 1\r\n ret i32 %sel\r\n}\r\n\r\ndefine i32 @tgt(i32 %x) {\r\n %ctlz = call range(i32 1, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)\r\n %1 = sub nsw i32 0, %ctlz\r\n %2 = and i32 %1, 31\r\n %sel = shl nuw i32 1, %2\r\n ret i32 %sel\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i32 @src(i32 %x) {\r\n#0:\r\n %ctlz = ctlz i32 %x, 0\r\n %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33\r\n %sub = sub i32 32, %#range_0_%ctlz\r\n %shl = shl i32 1, %sub\r\n %dec = add i32 %x, 4294967295\r\n %ult = icmp ult i32 %dec, 4294967294\r\n %sel = select i1 %ult, i32 %shl, i32 1\r\n ret i32 %sel\r\n}\r\n=>\r\ndefine i32 @tgt(i32 %x) {\r\n#0:\r\n %ctlz = ctlz i32 %x, 0\r\n %#range_0_%ctlz = !range i32 %ctlz, i32 1, i32 33\r\n %#1 = sub nsw i32 0, %#range_0_%ctlz\r\n %#2 = and i32 %#1, 31\r\n %sel = shl nuw i32 1, %#2\r\n ret i32 %sel\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #xffffffff (4294967295, -1)\r\n\r\nSource:\r\ni32 %ctlz = #x00000000 (0)\r\ni32 %#range_0_%ctlz = poison\r\ni32 %sub = poison\r\ni32 %shl = poison\r\ni32 %dec = #xfffffffe (4294967294, -2)\r\ni1 %ult = #x0 (0)\r\ni32 %sel = #x00000001 (1)\r\n\r\nTarget:\r\ni32 %ctlz = #x00000000 (0)\r\ni32 %#range_0_%ctlz = poison\r\ni32 %#1 = poison\r\ni32 %#2 = poison\r\ni32 %sel = poison\r\nSource value: #x00000001 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
101213
https://github.com/llvm/llvm-project/issues/101213
crash
8364a6e108faea1a6f05f7bb53720a6fc101fed2
2024-07-30T18:00:09
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "f70f1228035c9610de38e0e376afdacb647c4ad9", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13909, 13919 ] ], "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 f70f1228035c9610de38e0e376afdacb647c4ad9 Author: Alexey Bataev <[email protected]> Date: Tue Jul 30 14:02:51 2024 -0700 [SLP]Fix PR101213: Reuse extractelement, only if its vector operand comes before new vector value. When trying to reuse extractelement instruction, need to check that it is inserted into proper position. Its original vector operand should come before new vector value, otherwise new extractelement instruction must be generated. Fixes https://github.com/llvm/llvm-project/issues/101213 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 6501a14d8778..cf87b8621027 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13909,11 +13909,16 @@ Value *BoUpSLP::vectorizeTree( } if (!Ex) { // "Reuse" the existing extract to improve final codegen. - if (auto *ES = dyn_cast<ExtractElementInst>(Scalar)) { + if (auto *ES = dyn_cast<ExtractElementInst>(Scalar); + ES && isa<Instruction>(Vec)) { Value *V = ES->getVectorOperand(); if (const TreeEntry *ETE = getTreeEntry(V)) V = ETE->VectorizedValue; - Ex = Builder.CreateExtractElement(V, ES->getIndexOperand()); + if (auto *IV = dyn_cast<Instruction>(V); + !IV || IV == Vec || IV->comesBefore(cast<Instruction>(Vec))) + Ex = Builder.CreateExtractElement(V, ES->getIndexOperand()); + else + Ex = Builder.CreateExtractElement(Vec, Lane); } else if (ReplaceGEP) { // Leave the GEPs as is, they are free in most cases and better to // keep them as GEPs.
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/extract-vectorized-operand.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n %0 = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> zeroinitializer, <2 x i32> <i32 1, i32 0>\n %1 = extractelement <2 x ptr addrspace(1)> %0, i32 0\n %2 = extractelement <2 x ptr addrspace(1)> %0, i32 1\n br label %bb43\n\nbb20: ; No predecessors!\n br label %bb105\n\nbb43: ; preds = %bb51, %bb\n %phi441 = phi ptr addrspace(1) [ %4, %bb51 ], [ %2, %bb ]\n %phi452 = phi ptr addrspace(1) [ %5, %bb51 ], [ %1, %bb ]\n br i1 false, label %bb105, label %bb51\n\nbb51: ; preds = %bb54, %bb43\n %3 = phi <2 x ptr addrspace(1)> [ poison, %bb54 ], [ zeroinitializer, %bb43 ]\n %4 = extractelement <2 x ptr addrspace(1)> %3, i32 0\n %5 = extractelement <2 x ptr addrspace(1)> %3, i32 1\n br label %bb43\n\nbb54: ; No predecessors!\n br label %bb51\n\nbb105: ; preds = %bb43, %bb20\n %phi106 = phi ptr addrspace(1) [ %1, %bb20 ], [ null, %bb43 ]\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run the following test with -passes slp-vectorizer -slp-threshold=-99999\r\n[Test.ll.tgz](https://github.com/user-attachments/files/16431764/Test.ll.tgz)\r\n\r\nReproducer : https://godbolt.org/z/GW41a7WP6\r\n\r\nStack dump:\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = shufflevector <2 x ptr addrspace(1)> %0, <2 x ptr addrspace(1)> poison, <2 x i32> <i32 1, i32 0>\r\n %1 = extractelement <2 x ptr addrspace(1)> %2, i32 0\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"verify\" on module \"<source>\"\r\n #0 0x0000000004eff778 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eff778)\r\n #1 0x0000000004efceec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c0269e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c0269e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c0269e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c0269e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b3ff7 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004e396a8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e396a8)\r\n #8 0x0000000004d360f0 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d360f0)\r\n #9 0x00000000008d865e llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d865e)\r\n#10 0x0000000004cf9c90 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cf9c90)\r\n#11 0x00000000008e33d2 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e33d2)\r\n#12 0x00000000008d62fc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d62fc)\r\n#13 0x00007c0269e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007c0269e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008cd75e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cd75e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "llvm:crash" ], "comments": [ { "author": "Zentrik", "body": "@alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking f70f1228035c9610de38e0e376afdacb647c4ad9 but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. \r\nI can create an IR reproducer for that failure if need be.\r\nThank you.\r\n\r\nEDIT: Would just adding a check that they're in the same basic block work?" }, { "author": "alexey-bataev", "body": "> @alexey-bataev Hi, is there a way to backport this fix for llvm 19, I tried just cherry picking [f70f122](https://github.com/llvm/llvm-project/commit/f70f1228035c9610de38e0e376afdacb647c4ad9) but I ended up getting assertion failures of the form `/workspace/srcdir/llvm-project/llvm/lib/IR/Instruction.cpp:321: bool llvm::Instruction::comesBefore(const llvm::Instruction*) const: Assertion 'getParent() == Other->getParent() && \"cross-BB instruction order comparison\"' failed.'`. I can create an IR reproducer for that failure if need be. Thank you.\r\n> \r\n> EDIT: Would just adding a check that they're in the same basic block work?\r\n\r\nYes, check for the same parent should fix it" } ] }
true
null
106239
https://github.com/llvm/llvm-project/issues/106239
crash
15405b32b1cdbefab9ce1b1f301a51ae25404037
2024-08-27T15:51:29
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "c9a5e1b665dbba898e9981fd7d48881947e6560e", "components": [ "SimplifyIndVar" ], "bug_location_lineno": { "llvm/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": [ [ 1928, 1945 ] ], "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": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [ "WidenIV::widenIVUse" ], "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 c9a5e1b665dbba898e9981fd7d48881947e6560e Author: Nikita Popov <[email protected]> Date: Wed Aug 28 12:54:14 2024 +0200 [IndVars] Check if WideInc available before trying to use it WideInc/WideIncExpr can be null. Previously this worked out because the comparison with WideIncExpr would fail. Now we have accesses to WideInc prior to that. Avoid the issue with an explicit check. Fixes https://github.com/llvm/llvm-project/issues/106239. diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index 8e3a14bb4f6d..a950a4f57ef4 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -1928,18 +1928,24 @@ Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU, if (!WideAddRec.first) return nullptr; - // Reuse the IV increment that SCEVExpander created. Recompute flags, unless - // the flags for both increments agree and it is safe to use the ones from - // the original inc. In that case, the new use of the wide increment won't - // be more poisonous. - bool NeedToRecomputeFlags = - !SCEVExpander::canReuseFlagsFromOriginalIVInc(OrigPhi, WidePhi, - DU.NarrowUse, WideInc) || - DU.NarrowUse->hasNoUnsignedWrap() != WideInc->hasNoUnsignedWrap() || - DU.NarrowUse->hasNoSignedWrap() != WideInc->hasNoSignedWrap(); + auto CanUseWideInc = [&]() { + if (!WideInc) + return false; + // Reuse the IV increment that SCEVExpander created. Recompute flags, + // unless the flags for both increments agree and it is safe to use the + // ones from the original inc. In that case, the new use of the wide + // increment won't be more poisonous. + bool NeedToRecomputeFlags = + !SCEVExpander::canReuseFlagsFromOriginalIVInc( + OrigPhi, WidePhi, DU.NarrowUse, WideInc) || + DU.NarrowUse->hasNoUnsignedWrap() != WideInc->hasNoUnsignedWrap() || + DU.NarrowUse->hasNoSignedWrap() != WideInc->hasNoSignedWrap(); + return WideAddRec.first == WideIncExpr && + Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags); + }; + Instruction *WideUse = nullptr; - if (WideAddRec.first == WideIncExpr && - Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags)) + if (CanUseWideInc()) WideUse = WideInc; else { WideUse = cloneIVUser(DU, WideAddRec.first);
[ { "file": "llvm/test/Transforms/IndVarSimplify/pr106239.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "m", "test_body": "target datalayout = \"n8:16:32:64\"\n\ndefine i32 @m() {\nentry:\n %div.i4 = sdiv i32 1, 0\n br label %for.body.i6\n\nfor.body.i6: ; preds = %if.end.i, %entry\n %add57.i = phi i32 [ %add.i7, %if.end.i ], [ 0, %entry ]\n br i1 true, label %i.exit, label %if.end.i\n\nif.end.i: ; preds = %for.body.i6\n %add.i7 = add i32 %add57.i, %div.i4\n %conv.i = zext i32 %add57.i to i64\n store i64 %conv.i, ptr null, align 8\n br label %for.body.i6\n\ni.exit: ; preds = %for.body.i6\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Crash with O2 optimization flag", "body": "I compiled this code with -O2 flag and it crashed. The code is:\r\n\r\n```c\r\n#include <stdint.h>\r\nlong a, c;\r\nunsigned d;\r\nint32_t g;\r\nuint8_t h[];\r\nlong b(long p1, long k) {\r\n long e = k;\r\n int b = 0;\r\n while (e) {\r\n e /= 10;\r\n b++;\r\n }\r\n for (int f = 0; f < b; f++)\r\n p1 *= 10;\r\n a = p1 + k;\r\n return a;\r\n}\r\nlong i(int p1, int, int l) {\r\n int j = l / p1;\r\n for (int f = 0; f < p1; f++) {\r\n if (d > l)\r\n break;\r\n c = d += j;\r\n }\r\n}\r\nuint32_t m() {\r\n for (g = 8; b(35, 46) - 3546 + g >= 0; g--)\r\n ;\r\n h[i(g + 1, 0, -4294967221)];\r\n}\r\n```\r\n\r\nThe crash is: clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From*) [with To = llvm::BinaryOperator; From = llvm::Instruction]: Assertion `detail::isPresent(Val) && \"dyn_cast on a non-existent value\"' failed.\r\n\r\n\r\nThe details can be found here: https://godbolt.org/z/37WsGxMcv", "author": "cardigan1008", "labels": [ "regression", "release:backport", "confirmed", "crash", "llvm:transforms" ], "comments": [ { "author": "shafik", "body": "Looks like a regression, does not crash in clang-18: https://godbolt.org/z/1zYqs3sbz" }, { "author": "dtcxzyw", "body": "Reproducer: https://godbolt.org/z/bbdhPxx5E\r\n\r\n```\r\n; bin/opt -passes=indvars reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\n\r\ndefine i32 @m() {\r\nentry:\r\n %div.i4 = sdiv i32 1, 0\r\n br label %for.body.i6\r\n\r\nfor.body.i6: ; preds = %if.end.i, %entry\r\n %add57.i = phi i32 [ %add.i7, %if.end.i ], [ 0, %entry ]\r\n br i1 true, label %i.exit, label %if.end.i\r\n\r\nif.end.i: ; preds = %for.body.i6\r\n %add.i7 = add i32 %add57.i, %div.i4\r\n %conv.i = zext i32 %add57.i to i64\r\n store i64 %conv.i, ptr null, align 8\r\n br label %for.body.i6\r\n\r\ni.exit: ; preds = %for.body.i6\r\n ret i32 0\r\n}\r\n```\r\ncc @nikic" }, { "author": "DimitryAndric", "body": "This regressed with `llvmorg-19-init-02822-g`4db93e5d564 (\"[IndVars] Recompute flags if needed in widenIVUse of IV increment. (#82352)\") by @fhahn." } ] }
true
null
76986
https://github.com/llvm/llvm-project/issues/76986
crash
71c17424b5d5c22c0ce6b4c41acaa0401515baca
2024-01-04T18:14:09
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2ab5c47c8752b444885d6bfaf6f570a482fb4cdf", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 829, 843 ] ], "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": [ "simplifyRecipe" ], "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 2ab5c47c8752b444885d6bfaf6f570a482fb4cdf Author: Florian Hahn <[email protected]> Date: Thu Jan 4 20:39:44 2024 +0000 [VPlan] Don't replace scalarizing recipe with VPWidenCastRecipe. Don't replace a scalarizing recipe with a VPWidenCastRecipe. This would introduce wide (vectorizing) recipes when interleaving only. Fixes https://github.com/llvm/llvm-project/issues/76986 diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp index 33132880d5a4..5c430620a2dc 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -829,15 +829,20 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) { Type *ATy = TypeInfo.inferScalarType(A); if (TruncTy == ATy) { Trunc->replaceAllUsesWith(A); - } else if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) { - auto *VPC = - new VPWidenCastRecipe(Instruction::CastOps(ExtOpcode), A, TruncTy); - VPC->insertBefore(&R); - Trunc->replaceAllUsesWith(VPC); - } else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) { - auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy); - VPC->insertBefore(&R); - Trunc->replaceAllUsesWith(VPC); + } else { + // Don't replace a scalarizing recipe with a widened cast. + if (isa<VPReplicateRecipe>(&R)) + break; + if (ATy->getScalarSizeInBits() < TruncTy->getScalarSizeInBits()) { + auto *VPC = + new VPWidenCastRecipe(Instruction::CastOps(ExtOpcode), A, TruncTy); + VPC->insertBefore(&R); + Trunc->replaceAllUsesWith(VPC); + } else if (ATy->getScalarSizeInBits() > TruncTy->getScalarSizeInBits()) { + auto *VPC = new VPWidenCastRecipe(Instruction::Trunc, A, TruncTy); + VPC->insertBefore(&R); + Trunc->replaceAllUsesWith(VPC); + } } #ifndef NDEBUG // Verify that the cached type info is for both A and its users is still
[ { "file": "llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -debug -disable-output %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s" ], "tests": [ { "test_name": "test_scalarize_call", "test_body": "define void @test_scalarize_call(i32 %start, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ %start, %entry ], [ %iv.next, %loop ]\n %min = tail call i32 @llvm.smin.i32(i32 %iv, i32 65535)\n %arrayidx = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %min, ptr %arrayidx, align 8\n %iv.next = add nsw i32 %iv, 1\n %tobool.not = icmp eq i32 %iv.next, 1000\n br i1 %tobool.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "scalarize_ptrtoint", "test_body": "define void @scalarize_ptrtoint(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr ptr, ptr %src, i64 %iv\n %l = load ptr, ptr %gep, align 8\n %cast = ptrtoint ptr %l to i64\n %add = add i64 %cast, 10\n %cast.2 = inttoptr i64 %add to ptr\n store ptr %cast.2, ptr %dst, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "first_order_recurrence_using_induction", "test_body": "define void @first_order_recurrence_using_induction(i32 %n, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %for = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %for, ptr %dst, align 4\n %iv.next = add nuw nsw i64 %iv, 1\n %iv.next.trunc = trunc i64 %iv.next to i32\n %ec = icmp slt i32 %iv.next.trunc, %n\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "reduction_with_casts", "test_body": "define i16 @reduction_with_casts() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %count.0.in1 = phi i32 [ 0, %entry ], [ %add, %loop ]\n %iv = phi i16 [ 1, %entry ], [ %iv.next, %loop ]\n %conv1 = and i32 %count.0.in1, 65535\n %add = add nuw nsw i32 %conv1, 1\n %iv.next = add i16 %iv, 1\n %cmp = icmp eq i16 %iv.next, 10000\n br i1 %cmp, label %exit, label %loop\n\nexit: ; preds = %loop\n %add.lcssa = phi i32 [ %add, %loop ]\n %count.0 = trunc i32 %add.lcssa to i16\n ret i16 %count.0\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr76986_trunc_sext_interleaving_only", "test_body": "define void @pr76986_trunc_sext_interleaving_only(i16 %arg, ptr noalias %src, ptr noalias %dst) {\nbb:\n br label %loop\n\nloop: ; preds = %loop, %bb\n %iv = phi i64 [ 0, %bb ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i8, ptr %src, i64 %iv\n %l = load i8, ptr %gep.src, align 1\n %sext = sext i8 %l to i32\n %trunc = trunc i32 %sext to i16\n %sdiv = sdiv i16 %trunc, %arg\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %sdiv, ptr %gep.dst, align 2\n %iv.next = add i64 %iv, 1\n %icmp = icmp ult i64 %iv, 14933\n br i1 %icmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_scalarize_with_branch_cond", "test_body": "define void @test_scalarize_with_branch_cond(ptr %src, ptr %dst) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %d = phi i1 [ false, %entry ], [ %d.next, %loop.latch ]\n %d.next = xor i1 %d, true\n br i1 %d, label %cond.false, label %loop.latch\n\ncond.false: ; preds = %loop.header\n %gep.src = getelementptr inbounds i32, ptr %src, i64 %iv\n %gep.dst = getelementptr inbounds i32, ptr %dst, i64 %iv\n %l = load i32, ptr %gep.src, align 4\n store i32 %l, ptr %gep.dst, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %cond.false, %loop.header\n %iv.next = add nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `State.VF.isVector() && \"Not vectorizing?\"' failed.", "body": "Run opt with -passes=loop-vectorize\r\n\r\nhttps://godbolt.org/z/xdrTfEddx\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"aarch64-none-linux-gnu\"\r\n\r\ndefine void @wombat(i16 %arg) gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ 0, %bb ], [ %add, %bb1 ]\r\n %sext = sext i8 0 to i32\r\n %add = add i64 %phi, 1\r\n %trunc = trunc i32 %sext to i16\r\n %sdiv = sdiv i16 0, %arg\r\n %sext2 = sext i16 %trunc to i32\r\n %sext3 = sext i32 %sext2 to i64\r\n %icmp = icmp ult i64 %phi, 14933\r\n br i1 %icmp, label %bb1, label %bb4\r\n\r\nbb4: ; preds = %bb1\r\n %phi5 = phi i64 [ %sext3, %bb1 ]\r\n ret void\r\n}\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "fhahn", "body": "Taking a look now!" } ] }
true
null
99899
https://github.com/llvm/llvm-project/issues/99899
crash
9a8b0407fc16af4ca6f79a2583297318a645d88a
2024-07-22T17:02:03
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "3cb82f49dc990dc20a765856c0e126193992fe44", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 9699, 9705 ] ], "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::getEntryCost" ], "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 3cb82f49dc990dc20a765856c0e126193992fe44 Author: Alexey Bataev <[email protected]> Date: Mon Jul 22 12:45:28 2024 -0700 [SLP]Fix PR99899: Use canonical type instead of original vector of ptr. Use adjusted canonical integer type instead of the original ptr type to fix the crash in the TTI. Fixes https://github.com/llvm/llvm-project/issues/99899 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 667c4eb311c2..cca9eeebaa53 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -9699,7 +9699,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, CanonicalType = CanonicalType->getWithNewType(IntegerType::get( CanonicalType->getContext(), DL->getTypeSizeInBits(CanonicalType->getScalarType()))); - IntrinsicCostAttributes CostAttrs(MinMaxID, VecTy, {VecTy, VecTy}); + IntrinsicCostAttributes CostAttrs(MinMaxID, CanonicalType, + {CanonicalType, CanonicalType}); InstructionCost IntrinsicCost = TTI->getIntrinsicInstrCost(CostAttrs, CostKind); // If the selects are the only uses of the compares, they will be
[ { "file": "llvm/test/Transforms/SLPVectorizer/SystemZ/cmp-ptr-minmax.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=s390x-unknown-linux-gnu -mcpu=z16 -slp-threshold=-10 < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i1 @test(i64 %0, i64 %1, ptr %2) {\n;\nentry:\n %gep44 = getelementptr i8, ptr null, i64 %0\n %gep45 = getelementptr i8, ptr null, i64 %1\n %4 = icmp ult ptr %gep44, %gep45\n %umin = select i1 %4, ptr %gep44, ptr %gep45\n %gep48 = getelementptr i8, ptr null, i64 %0\n %gep49 = getelementptr i8, ptr null, i64 %1\n %5 = icmp ult ptr %gep48, %gep49\n %umin50 = select i1 %5, ptr %gep48, ptr %gep49\n %b095 = icmp ult ptr %umin, %2\n %b196 = icmp ult ptr %umin50, %2\n %res = and i1 %b095, %b196\n ret i1 %res\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLP] crash after 8ff233f", "body": "8ff233f \"[SLP]Correctly detect minnum/maxnum patterns for select/cmp operations on floats.\" seems to have introduced a problem when building SPEC on SystemZ.\r\n\r\nopt -mtriple=s390x-linux-gnu -mcpu=z16 -O3 ./tc_slp.ll -o /dev/null\r\nopt: /home/ijonpan/llvm-project/llvm/include/llvm/IR/DerivedTypes.h:704: llvm::Type* llvm::Type::getWithNewBitWidth(unsigned int) const: Assertion `isIntOrIntVectorTy() && \"Original type expected to be a vector of integers or a scalar integer.\"' failed.\r\n...\r\n#15 0x000000000519c8f8 llvm::slpvectorizer::BoUpSLP::getEntryCost\r\n\r\n[tc_slp.ll.tar.gz](https://github.com/user-attachments/files/16337301/tc_slp.ll.tar.gz)\r\n", "author": "JonPsson1", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
99411
https://github.com/llvm/llvm-project/issues/99411
crash
cb3de24b5c0a662ba4a03c6c06a2d765d558bf62
2024-07-18T00:03:03
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "b634e057ddecc41dce046887d0f0854fed305374", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 11852, 11859 ] ], "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": [ "castToScalarTyElem" ], "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 b634e057ddecc41dce046887d0f0854fed305374 Author: Han-Kuan Chen <[email protected]> Date: Thu Jul 18 19:54:46 2024 +0800 [SLP][REVEC] Fix false assumption of the source for castToScalarTyElem. (#99424) The argument V may come from adjustExtracts, which is the vector operand of ExtractElementInst. In addition, it is not existed in getTreeEntry. The vector operand of ExtractElementInst may have a type of <1 x Ty>, ensuring that the number of elements in ScalarTy and VecTy are equal. reference: https://github.com/llvm/llvm-project/issues/99411 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d88c6307b994..b994645cece6 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -11852,8 +11852,7 @@ class BoUpSLP::ShuffleInstructionBuilder final : public BaseShuffleAnalysis { Value *castToScalarTyElem(Value *V, std::optional<bool> IsSigned = std::nullopt) { auto *VecTy = cast<VectorType>(V->getType()); - assert(getNumElements(ScalarTy) < getNumElements(VecTy) && - (getNumElements(VecTy) % getNumElements(ScalarTy) == 0)); + assert(getNumElements(VecTy) % getNumElements(ScalarTy) == 0); if (VecTy->getElementType() == ScalarTy->getScalarType()) return V; return Builder.CreateIntCast(
[ { "file": "llvm/test/Transforms/SLPVectorizer/revec-fix-99411.ll", "commands": [ "opt -mtriple x86_64-unknown-linux-gnu -passes=slp-vectorizer -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @e() {\n;\nentry:\n %0 = extractelement <1 x i64> zeroinitializer, i64 0\n %bf.value = and i64 %0, 0\n %bf.set = or i64 0, %bf.value\n store i64 %bf.set, ptr getelementptr inbounds (i8, ptr null, i64 8), align 8\n %bf.value2 = and i64 0, 0\n %bf.set4 = or i64 0, %bf.value2\n store i64 %bf.set4, ptr null, align 8\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "A/F: `getNumElements(ScalarTy) < getNumElements(VecTy) && (getNumElements(VecTy) % getNumElements(ScalarTy) == 0)' failed after 1813ffd", "body": "Several of our internal tests started hitting an assertion failure while building, one of which I bisected back to commit 1813ffd. Consider the following code:\r\n```c++\r\ntypedef long long __m64 __attribute__((__vector_size__(8), __aligned__(8)));\r\nstatic __inline__ long long foo(__m64 m) { return (long long) m; }\r\nstruct c {\r\n long a : 43;\r\n long b : 61;\r\n} d;\r\nvoid e() {\r\n volatile __m64 f;\r\n long g, i = d.b = g = foo(f);\r\n d.a = i;\r\n}\r\n```\r\nWhen compiled with optimizations with a compiler that includes 1813ffd, it hits an assertion failure:\r\n```\r\n$ ~/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang -c -O2 repro.cpp \r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:11853: llvm::Value* llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::castToScalarTyElem(llvm::Value*, std::optional<bool>): Assertion `getNumElements(ScalarTy) < getNumElements(VecTy) && (getNumElements(VecTy) % getNumElements(ScalarTy) == 0)' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang -c -O2 repro.cpp\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-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>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>)\" on module \"repro.cpp\" \r\n4. Running pass \"slp-vectorizer\" on function \"_Z7test119v\"\r\n #0 0x00005650f775179f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x41a279f) \r\n #1 0x00005650f774f2fc llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x41a02fc) \r\n #2 0x00005650f76947e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 \r\n #3 0x00007ff89a3f9420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420) \r\n #4 0x00007ff899ec600b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1 \r\n #5 0x00007ff899ea5859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7 \r\n #6 0x00007ff899ea5729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8 \r\n #7 0x00007ff899ea5729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34 \r\n #8 0x00007ff899eb6fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6) \r\n #9 0x00005650f903005c llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::castToScalarTyElem(llvm::Value*, std::optional<bool>) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5a8105c)\r\n#10 0x00005650f9071f00 llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::adjustExtracts(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::MutableArrayRef<int>, llvm::ArrayRef<std::optional<llvm::TargetTransformInfo::ShuffleKind>>, unsigned int, bool&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5ac2f00) \r\n#11 0x00005650f909dfdd llvm::Value* llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder, llvm::Value*, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>, llvm::slpvectorizer::BoUpSLP>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderDefaultInserter>&, llvm::slpvectorizer::BoUpSLP&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5aeefdd)\r\n#12 0x00005650f90a941a llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afa41a)\r\n#13 0x00005650f90a80e3 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5af90e3)\r\n#14 0x00005650f90a9484 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afa484)\r\n#15 0x00005650f90a7cdf llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5af8cdf)\r\n#16 0x00005650f90ac099 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afd099)\r\n#17 0x00005650f90a7cdf llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5af8cdf)\r\n#18 0x00005650f90a9e6c llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5afae6c)\r\n#19 0x00005650f90c7263 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b18263)\r\n#20 0x00005650f90cacbc llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b1bcbc)\r\n#21 0x00005650f90e045b llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b3145b) \r\n#22 0x00005650f90e1a5e llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::'lambda'(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&)::operator()(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&) const SLPVectorizer.cpp:0:0\r\n#23 0x00005650f90e39a0 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b349a0)\r\n#24 0x00005650f90e42c3 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b352c3)\r\n#25 0x00005650f90e57dd llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#26 0x00005650f90e6253 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x5b37253)\r\n#27 0x00005650f8baedb6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x55ffdb6)\r\n#28 0x00005650f70f6421 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x3b47421)\r\n#29 0x00005650f4cb9ca6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x170aca6)\r\n#30 0x00005650f70f4ded llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x3b45ded)\r\n#31 0x00005650f4cbac56 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x170bc56)\r\n#32 0x00005650f70f2f31 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x3b43f31)\r\n#33 0x00005650f7a062c8 (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#34 0x00005650f7a09645 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#35 0x00005650f7a09ce6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x445ace6)\r\n#36 0x00005650f808091c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ad191c)\r\n#37 0x00005650f9e7fe6c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x68d0e6c)\r\n#38 0x00005650f8080d28 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ad1d28)\r\n#39 0x00005650f8318339 clang::FrontendAction::Execute() (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4d69339)\r\n#40 0x00005650f829a98e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ceb98e)\r\n#41 0x00005650f8403dc6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4e54dc6)\r\n#42 0x00005650f489f105 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x12f0105)\r\n#43 0x00005650f489811a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#44 0x00005650f80c610d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#45 0x00005650f7694cf0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x40e5cf0)\r\n#46 0x00005650f80c672f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#47 0x00005650f808aa6c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4adba6c)\r\n#48 0x00005650f808b4fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4adc4fd)\r\n#49 0x00005650f80935d5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x4ae45d5)\r\n#50 0x00005650f489c37b clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x12ed37b)\r\n#51 0x00005650f478ee1b main (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x11dfe1b)\r\n#52 0x00007ff899ea7083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#53 0x00005650f4897bae _start (/home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin/clang+0x12e8bae)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 19.0.0 (https://github.com/llvm/llvm-project.git 1813ffd6b2eb04ee2c296a4399a18748740a439d)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/1813ffd6b2eb04ee2c296a4399a18748740a439d-linux/bin\r\nBuild config: +assertions\r\n```\r\nIf built using the a compiler built from fa0e529 (the parent commit of 1813ffd), the compilation succeeds:\r\n```\r\n$ ~/src/upstream/fa0e52995929ab67dfb468d71fe793be5e1c7f03-linux/bin/clang -c -O2 repro.cpp\r\n$\r\n```\r\n", "author": "dyung", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "madhur13490", "body": "@dyung https://godbolt.org/z/ofneqo6zK I don't see here. Am I missing anything?" }, { "author": "dyung", "body": "> @dyung https://godbolt.org/z/ofneqo6zK I don't see here. Am I missing anything?\r\n\r\nI don't know if it reproduces on an ARM targeting compiler, I used an x86-64 targeting x86-64 compiler. Also the compiler currently used by godbolt was built from commit f56cdd4a45b7bbe84be5d4ba9442eb7071605efc which does not include 1813ffd6b2eb04ee2c296a4399a18748740a439d which introduced the issue." }, { "author": "HanKuanChen", "body": "Close the issue since https://github.com/llvm/llvm-project/commit/b634e057ddecc41dce046887d0f0854fed305374 is merged." } ] }
true
null
117518
https://github.com/llvm/llvm-project/issues/117518
crash
3de21477c49172081e502b47d608e729915f0914
2024-11-25T05:31:23
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "f953b5eb72df77fc301aac210eab31c6270ff771", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 10875, 10883 ], [ 14372, 14378 ] ], "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": [ "finalize" ], "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 f953b5eb72df77fc301aac210eab31c6270ff771 Author: Alexey Bataev <[email protected]> Date: Mon Nov 25 08:29:22 2024 -0800 [SLP]Relax assertion about subvectors mask size SubVectorsMask might be less than CommonMask, if the vectors with larger number of elements are permuted or reused elements are used. Need to consider this when estimation/building the vector to avoid compiler crash Fixes #117518 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 73218f377a06..34b80c1e3608 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -10875,9 +10875,10 @@ public: CommonMask[Idx] = Idx; // Add subvectors permutation cost. if (!SubVectorsMask.empty()) { - assert(SubVectorsMask.size() == CommonMask.size() && + assert(SubVectorsMask.size() <= CommonMask.size() && "Expected same size of masks for subvectors and common mask."); - SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end()); + SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem); + copy(SubVectorsMask, SVMask.begin()); for (auto [I1, I2] : zip(SVMask, CommonMask)) { if (I2 != PoisonMaskElem) { assert(I1 == PoisonMaskElem && "Expected unused subvectors mask"); @@ -14372,7 +14373,8 @@ public: if (SubVectorsMask.empty()) { Vec = CreateSubVectors(Vec, CommonMask); } else { - SmallVector<int> SVMask(SubVectorsMask.begin(), SubVectorsMask.end()); + SmallVector<int> SVMask(CommonMask.size(), PoisonMaskElem); + copy(SubVectorsMask, SVMask.begin()); for (auto [I1, I2] : zip(SVMask, CommonMask)) { if (I2 != PoisonMaskElem) { assert(I1 == PoisonMaskElem && "Expected unused subvectors mask");
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/non-power-of-2-subvectors-insert.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-300 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\n %xor108.i.i.i = xor i64 0, 1\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\n %cond.i1002.1.i.i.i = lshr i64 0, 0\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\n %cond.i1002.3.i.i.i = lshr i64 0, 0\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' failed.", "body": "Reproducer: https://godbolt.org/z/chKcKacPK\r\n```\r\n; bin/opt -passes=slp-vectorizer test.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @test() {\r\n %xor108.i.i.i = xor i64 0, 1\r\n %conv115.i.i.i = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i = or i16 %conv115.i.i.i, 0\r\n %add.i.frozen.i.i.i = freeze i16 %add.i.i.i.i\r\n %.cmp.not.i.i.i = icmp eq i16 %add.i.frozen.i.i.i, 0\r\n %cond.i1002.1.i.i.i = lshr i64 0, 0\r\n %conv115.1.i.i.i = trunc i64 %cond.i1002.1.i.i.i to i16\r\n %add.i.1.i.i.i = or i16 %conv115.1.i.i.i, 0\r\n %add.i.frozen.1.i.i.i = freeze i16 %add.i.1.i.i.i\r\n %.cmp.not.1.i.i.i = icmp eq i16 %add.i.frozen.1.i.i.i, 0\r\n %cond.i1002.2.i.i.i = lshr i64 %xor108.i.i.i, 0\r\n %conv115.2.i.i.i = trunc i64 %cond.i1002.2.i.i.i to i16\r\n %add.i.2.i.i.i = or i16 %conv115.2.i.i.i, 0\r\n %add.i.frozen.2.i.i.i = freeze i16 %add.i.2.i.i.i\r\n %.cmp.not.2.i.i.i = icmp eq i16 %add.i.frozen.2.i.i.i, 0\r\n %cond.i1002.3.i.i.i = lshr i64 0, 0\r\n %conv115.3.i.i.i = trunc i64 %cond.i1002.3.i.i.i to i16\r\n %add.i.3.i.i.i = or i16 %conv115.3.i.i.i, 0\r\n %add.i.frozen.3.i.i.i = freeze i16 %add.i.3.i.i.i\r\n %.cmp.not.3.i.i.i = icmp eq i16 %add.i.frozen.3.i.i.i, 0\r\n %conv115.i.i.i.1 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.1 = or i16 %conv115.i.i.i.1, 0\r\n %add.i.frozen.i.i.i.1 = freeze i16 %add.i.i.i.i.1\r\n %.cmp.not.i.i.i.1 = icmp eq i16 %add.i.frozen.i.i.i.1, 0\r\n %cond.i1002.1.i.i.i.1 = lshr i64 0, 0\r\n %conv115.1.i.i.i.1 = trunc i64 %cond.i1002.1.i.i.i.1 to i16\r\n %add.i.1.i.i.i.1 = or i16 %conv115.1.i.i.i.1, 0\r\n %add.i.frozen.1.i.i.i.1 = freeze i16 %add.i.1.i.i.i.1\r\n %.cmp.not.1.i.i.i.1 = icmp eq i16 %add.i.frozen.1.i.i.i.1, 0\r\n %cond.i1002.2.i.i.i.1 = lshr i64 0, 0\r\n %conv115.2.i.i.i.1 = trunc i64 %cond.i1002.2.i.i.i.1 to i16\r\n %add.i.2.i.i.i.1 = or i16 %conv115.2.i.i.i.1, 0\r\n %add.i.frozen.2.i.i.i.1 = freeze i16 %add.i.2.i.i.i.1\r\n %.cmp.not.2.i.i.i.1 = icmp eq i16 %add.i.frozen.2.i.i.i.1, 0\r\n %cond.i1002.3.i.i.i.1 = lshr i64 0, 0\r\n %conv115.3.i.i.i.1 = trunc i64 %cond.i1002.3.i.i.i.1 to i16\r\n %add.i.3.i.i.i.1 = or i16 %conv115.3.i.i.i.1, 0\r\n %add.i.frozen.3.i.i.i.1 = freeze i16 %add.i.3.i.i.i.1\r\n %.cmp.not.3.i.i.i.1 = icmp eq i16 %add.i.frozen.3.i.i.i.1, 0\r\n %conv115.i.i.i.2 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.2 = or i16 %conv115.i.i.i.2, 0\r\n %add.i.frozen.i.i.i.2 = freeze i16 %add.i.i.i.i.2\r\n %.cmp.not.i.i.i.2 = icmp eq i16 %add.i.frozen.i.i.i.2, 0\r\n %cond.i1002.1.i.i.i.2 = lshr i64 0, 0\r\n %conv115.1.i.i.i.2 = trunc i64 %cond.i1002.1.i.i.i.2 to i16\r\n %add.i.1.i.i.i.2 = or i16 %conv115.1.i.i.i.2, 0\r\n %add.i.frozen.1.i.i.i.2 = freeze i16 %add.i.1.i.i.i.2\r\n %.cmp.not.1.i.i.i.2 = icmp eq i16 %add.i.frozen.1.i.i.i.2, 0\r\n %cond.i1002.2.i.i.i.2 = lshr i64 0, 0\r\n %conv115.2.i.i.i.2 = trunc i64 %cond.i1002.2.i.i.i.2 to i16\r\n %add.i.2.i.i.i.2 = or i16 %conv115.2.i.i.i.2, 0\r\n %add.i.frozen.2.i.i.i.2 = freeze i16 %add.i.2.i.i.i.2\r\n %.cmp.not.2.i.i.i.2 = icmp eq i16 %add.i.frozen.2.i.i.i.2, 0\r\n %cond.i1002.3.i.i.i.2 = lshr i64 0, 0\r\n %conv115.3.i.i.i.2 = trunc i64 %cond.i1002.3.i.i.i.2 to i16\r\n %add.i.3.i.i.i.2 = or i16 %conv115.3.i.i.i.2, 0\r\n %add.i.frozen.3.i.i.i.2 = freeze i16 %add.i.3.i.i.i.2\r\n %.cmp.not.3.i.i.i.2 = icmp eq i16 %add.i.frozen.3.i.i.i.2, 0\r\n %conv115.i.i.i.3 = trunc i64 %xor108.i.i.i to i16\r\n %add.i.i.i.i.3 = or i16 %conv115.i.i.i.3, 0\r\n %add.i.frozen.i.i.i.3 = freeze i16 %add.i.i.i.i.3\r\n %.cmp.not.i.i.i.3 = icmp eq i16 %add.i.frozen.i.i.i.3, 0\r\n %cond.i1002.1.i.i.i.3 = lshr i64 0, 0\r\n %conv115.1.i.i.i.3 = trunc i64 %cond.i1002.1.i.i.i.3 to i16\r\n %add.i.1.i.i.i.3 = or i16 %conv115.1.i.i.i.3, 0\r\n %add.i.frozen.1.i.i.i.3 = freeze i16 %add.i.1.i.i.i.3\r\n %.cmp.not.1.i.i.i.3 = icmp eq i16 %add.i.frozen.1.i.i.i.3, 0\r\n %cond.i1002.2.i.i.i.3 = lshr i64 0, 0\r\n %conv115.2.i.i.i.3 = trunc i64 %cond.i1002.2.i.i.i.3 to i16\r\n %add.i.2.i.i.i.3 = or i16 %conv115.2.i.i.i.3, 0\r\n %add.i.frozen.2.i.i.i.3 = freeze i16 %add.i.2.i.i.i.3\r\n %.cmp.not.2.i.i.i.3 = icmp eq i16 %add.i.frozen.2.i.i.i.3, 0\r\n %cond.i1002.3.i.i.i.3 = lshr i64 0, 0\r\n %conv115.3.i.i.i.3 = trunc i64 %cond.i1002.3.i.i.i.3 to i16\r\n %add.i.3.i.i.i.3 = or i16 %conv115.3.i.i.i.3, 0\r\n %add.i.frozen.3.i.i.i.3 = freeze i16 %add.i.3.i.i.i.3\r\n %.cmp.not.3.i.i.i.3 = icmp eq i16 %add.i.frozen.3.i.i.i.3, 0\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10880: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `SubVectorsMask.size() == CommonMask.size() && \"Expected same size of masks for subvectors and common mask.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x00000000051b7378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b7378)\r\n #1 0x00000000051b4d6c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007ac42d642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ac42d6969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ac42d642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ac42d6287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ac42d62871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ac42d639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000041e9132 llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41e9132)\r\n #9 0x00000000042256f9 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42256f9)\r\n#10 0x000000000422f707 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x422f707)\r\n#11 0x00000000042636a1 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x42636a1)\r\n#12 0x000000000426d57c llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x426d57c)\r\n#13 0x000000000427168f bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427168f)\r\n#14 0x0000000004271fdb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\r\n#15 0x0000000004275785 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4275785)\r\n#16 0x000000000427bf86 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000427ca9b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x427ca9b)\r\n#18 0x0000000002fcc5ce llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2fcc5ce)\r\n#19 0x0000000004fb6a68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb6a68)\r\n#20 0x0000000000e3dd4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3dd4e)\r\n#21 0x0000000004fb548e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb548e)\r\n#22 0x0000000000e3d3fe llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe3d3fe)\r\n#23 0x0000000004fb4ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb4ec0)\r\n#24 0x000000000090ce7a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90ce7a)\r\n#25 0x00000000008ff519 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ff519)\r\n#26 0x00007ac42d629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007ac42d629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008f6d6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6d6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
97330
https://github.com/llvm/llvm-project/issues/97330
miscompilation
fdcfb277465e4530e5837fb8a95031794e58cb9b
2024-07-01T17:37:19
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "b558ac0eef57a3737b1e27844115fa91e0b32582", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 91, 98 ], [ 124, 173 ], [ 1105, 1117 ], [ 1119, 1131 ] ], "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": [ [ 545, 554 ] ], "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::SimplifyDemandedBits", "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 b558ac0eef57a3737b1e27844115fa91e0b32582 Author: Nikita Popov <[email protected]> Date: Tue Jul 2 10:08:45 2024 +0200 [InstCombine] Fix context for multi-use demanded bits simplification When simplifying a multi-use root value, the demanded bits were reset to full, but we also need to reset the context extract. To make this convenient (without requiring by-value passing of SimplifyQuery), move the logic that that handles constants and dispatches to SimplifyDemandedUseBits/SimplifyMultipleUseDemandedBits into SimplifyDemandedBits. The SimplifyDemandedInstructionBits caller starts with full demanded bits and an appropriate context anyway. The different context instruction does mean that the ephemeral value protection no longer triggers in some cases, as the changes to assume tests show. An alternative, which I will explore in a followup, is to always use SimplifyMultipleUseDemandedBits() -- the previous root special case is only really intended for SimplifyDemandedInstructionBits(), which now no longer shares this code path. Fixes https://github.com/llvm/llvm-project/issues/97330. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 318c455fd7ef..64fbcc80e0ed 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -545,10 +545,11 @@ public: ConstantInt *&Less, ConstantInt *&Equal, ConstantInt *&Greater); - /// Attempts to replace V with a simpler value based on the demanded + /// Attempts to replace I with a simpler value based on the demanded /// bits. - Value *SimplifyDemandedUseBits(Value *V, APInt DemandedMask, KnownBits &Known, - unsigned Depth, const SimplifyQuery &Q); + Value *SimplifyDemandedUseBits(Instruction *I, const APInt &DemandedMask, + KnownBits &Known, unsigned Depth, + const SimplifyQuery &Q); using InstCombiner::SimplifyDemandedBits; bool SimplifyDemandedBits(Instruction *I, unsigned Op, const APInt &DemandedMask, KnownBits &Known, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 6cf2e71363ab..b1d03786f321 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -91,8 +91,47 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { Use &U = I->getOperandUse(OpNo); - Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known, - Depth, Q); + Value *V = U.get(); + if (isa<Constant>(V)) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Known.resetAll(); + if (DemandedMask.isZero()) { + // Not demanding any bits from V. + replaceUse(U, UndefValue::get(V->getType())); + return true; + } + + if (Depth == MaxAnalysisRecursionDepth) + return false; + + Instruction *VInst = dyn_cast<Instruction>(V); + if (!VInst) { + llvm::computeKnownBits(V, Known, Depth, Q); + return false; + } + + Value *NewVal; + if (VInst->hasOneUse()) { + // If the instruction has one use, we can directly simplify it. + NewVal = SimplifyDemandedUseBits(VInst, DemandedMask, Known, Depth, Q); + } else if (Depth != 0) { + // If there are multiple uses of this instruction and we aren't at the root, + // then we can simplify VInst to some other value, but not modify the + // instruction. + NewVal = + SimplifyMultipleUseDemandedBits(VInst, DemandedMask, Known, Depth, Q); + } else { + // If this is the root being simplified, allow it to have multiple uses, + // just set the DemandedMask to all bits and reset the context instruction. + // This allows visitTruncInst (for example) to simplify the operand of a + // trunc without duplicating all the SimplifyDemandedUseBits() logic. + NewVal = + SimplifyDemandedUseBits(VInst, APInt::getAllOnes(Known.getBitWidth()), + Known, Depth, Q.getWithInstruction(VInst)); + } if (!NewVal) return false; if (Instruction* OpInst = dyn_cast<Instruction>(U)) salvageDebugInfo(*OpInst); @@ -124,50 +163,21 @@ bool InstCombinerImpl::SimplifyDemandedBits(Instruction *I, unsigned OpNo, /// operands based on the information about what bits are demanded. This returns /// some other non-null value if it found out that V is equal to another value /// in the context where the specified bits are demanded, but not for all users. -Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, +Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I, + const APInt &DemandedMask, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { - assert(V != nullptr && "Null pointer of Value???"); + assert(I != nullptr && "Null pointer of Value???"); assert(Depth <= MaxAnalysisRecursionDepth && "Limit Search Depth"); uint32_t BitWidth = DemandedMask.getBitWidth(); - Type *VTy = V->getType(); + Type *VTy = I->getType(); assert( (!VTy->isIntOrIntVectorTy() || VTy->getScalarSizeInBits() == BitWidth) && Known.getBitWidth() == BitWidth && "Value *V, DemandedMask and Known must have same BitWidth"); - if (isa<Constant>(V)) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; - } - - Known.resetAll(); - if (DemandedMask.isZero()) // Not demanding any bits from V. - return UndefValue::get(VTy); - - if (Depth == MaxAnalysisRecursionDepth) - return nullptr; - - Instruction *I = dyn_cast<Instruction>(V); - if (!I) { - llvm::computeKnownBits(V, Known, Depth, Q); - return nullptr; // Only analyze instructions. - } - - // If there are multiple uses of this value and we aren't at the root, then - // we can't do any simplifications of the operands, because DemandedMask - // only reflects the bits demanded by *one* of the users. - if (Depth != 0 && !I->hasOneUse()) - return SimplifyMultipleUseDemandedBits(I, DemandedMask, Known, Depth, Q); - KnownBits LHSKnown(BitWidth), RHSKnown(BitWidth); - // If this is the root being simplified, allow it to have multiple uses, - // just set the DemandedMask to all bits so that we can try to simplify the - // operands. This allows visitTruncInst (for example) to simplify the - // operand of a trunc without duplicating all the logic below. - if (Depth == 0 && !V->hasOneUse()) - DemandedMask.setAllBits(); // Update flags after simplifying an operand based on the fact that some high // order bits are not demanded. @@ -1105,13 +1115,13 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, } if (!KnownBitsComputed) - llvm::computeKnownBits(V, Known, Depth, Q); + llvm::computeKnownBits(I, Known, Depth, Q); break; } } - if (V->getType()->isPointerTy()) { - Align Alignment = V->getPointerAlignment(DL); + if (I->getType()->isPointerTy()) { + Align Alignment = I->getPointerAlignment(DL); Known.Zero.setLowBits(Log2(Alignment)); } @@ -1119,13 +1129,14 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, // constant. We can't directly simplify pointers as a constant because of // pointer provenance. // TODO: We could return `(inttoptr const)` for pointers. - if (!V->getType()->isPointerTy() && DemandedMask.isSubsetOf(Known.Zero | Known.One)) + if (!I->getType()->isPointerTy() && + DemandedMask.isSubsetOf(Known.Zero | Known.One)) return Constant::getIntegerValue(VTy, Known.One); if (VerifyKnownBits) { - KnownBits ReferenceKnown = llvm::computeKnownBits(V, Depth, Q); + KnownBits ReferenceKnown = llvm::computeKnownBits(I, Depth, Q); if (Known != ReferenceKnown) { - errs() << "Mismatched known bits for " << *V << " in " + errs() << "Mismatched known bits for " << *I << " in " << I->getFunction()->getName() << "\n"; errs() << "computeKnownBits(): " << ReferenceKnown << "\n"; errs() << "SimplifyDemandedBits(): " << Known << "\n";
[ { "file": "llvm/test/Transforms/InstCombine/assume-inseltpoison.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "PR40940", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i32 @PR40940(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> poison, <4 x i32> <i32 1, i32 1, i32 2, i32 3>\n %t2 = bitcast <4 x i8> %shuf to i32\n %t3 = icmp ult i32 %t2, 65536\n call void @llvm.assume(i1 %t3)\n ret i32 %t2\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/assume.ll", "commands": [ "opt < %s -passes=instcombine -S", "opt < %s -passes=instcombine --enable-knowledge-retention -S", "opt < %s -passes=instcombine -S --try-experimental-debuginfo-iterators", "opt < %s -passes=instcombine --enable-knowledge-retention -S --try-experimental-debuginfo-iterators" ], "tests": [ { "test_name": "PR40940", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine i32 @PR40940(<4 x i8> %x) {\n %shuf = shufflevector <4 x i8> %x, <4 x i8> undef, <4 x i32> <i32 1, i32 1, i32 2, i32 3>\n %t2 = bitcast <4 x i8> %shuf to i32\n %t3 = icmp ult i32 %t2, 65536\n call void @llvm.assume(i1 %t3)\n ret i32 %t2\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n\n!llvm.dbg.cu = !{}\n!llvm.module.flags = !{!0, !1, !2, !3}\n\n!0 = !{i32 2, !\"Dwarf Version\", i32 4}\n!1 = !{i32 2, !\"Debug Info Version\", i32 3}\n!2 = !{i32 1, !\"wchar_size\", i32 4}\n!3 = !{i32 8, !\"PIC Level\", i32 2}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/known-bits.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "simplifydemanded_context", "test_body": "define i8 @simplifydemanded_context(i8 %x, i8 %y) {\n %and1 = and i8 %x, 1\n call void @dummy()\n %x.lobits = and i8 %x, 3\n %precond = icmp eq i8 %x.lobits, 0\n call void @llvm.assume(i1 %precond)\n %and2 = and i8 %and1, %y\n ret i8 %and2\n}\n\ndeclare void @dummy()\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr97330", "test_body": "define i16 @pr97330(i1 %c, ptr %p1, ptr %p2) {\nentry:\n %v = load i64, ptr %p1, align 8\n %conv = trunc i64 %v to i16\n br i1 %c, label %exit, label %if\n\nif: ; preds = %entry\n %cmp = icmp ne i16 %conv, 1\n %conv2 = zext i1 %cmp to i32\n store i32 %conv2, ptr %p2, align 4\n %cmp2 = icmp eq i64 %v, 1\n call void @llvm.assume(i1 %cmp2)\n unreachable\n\nexit: ; preds = %entry\n ret i16 %conv\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Miscompilation with llvm.assume in unreachable blocks", "body": "Reproducer: https://alive2.llvm.org/ce/z/zKvpXV\r\n```\r\n; bin/opt -passes=instcombine reduced.ll -S\r\ndefine i16 @src(i16 %g, ptr %e, ptr %d) {\r\nentry:\r\n %0 = load i64, ptr %d, align 8\r\n %conv = trunc i64 %0 to i16\r\n %tobool.not.i = icmp eq i16 %g, 0\r\n br i1 %tobool.not.i, label %i.exit, label %for.cond.preheader.i\r\n\r\nfor.cond.preheader.i:\r\n %cmp5.i = icmp ne i16 %g, %conv\r\n %conv6.i = zext i1 %cmp5.i to i32\r\n store i32 %conv6.i, ptr %e, align 4\r\n %cmp7.i = icmp eq i64 %0, 1\r\n call void @llvm.assume(i1 %cmp7.i)\r\n unreachable\r\n\r\ni.exit:\r\n ret i16 %conv\r\n}\r\n```\r\n```\r\ndefine i16 @tgt(i16 %g, ptr %e, ptr %d) {\r\nentry:\r\n %tobool.not.i = icmp eq i16 %g, 0\r\n br i1 %tobool.not.i, label %i.exit, label %for.cond.preheader.i\r\n\r\nfor.cond.preheader.i: ; preds = %entry\r\n unreachable\r\n\r\ni.exit: ; preds = %entry\r\n ret i16 1\r\n}\r\n```\r\n\r\nllvm version: a8e1c3e1239604ac787b6a2d39b5278ddec8aa8a\r\n\r\ncc @nikic", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reverting https://github.com/llvm/llvm-project/commit/11484cb817bcc2a6e2ef9572be982a1a5a4964ec fixes this issue.\r\n" }, { "author": "nikic", "body": "I've applied two fixes for this. https://github.com/llvm/llvm-project/commit/86b37944a70229b07626e63bdb9a46b4bc3d1460 tries to stick closer to the current logic, while https://github.com/llvm/llvm-project/commit/05670b42f5b45710bfdba48dcb7e8c30c8c7478f is a more thorough fix on top of that." }, { "author": "dtcxzyw", "body": "Confirmed that the original case has been fixed. Thank you!\r\n" }, { "author": "chapuni", "body": "@nikic Fixed, thanks!" } ] }
true
null
85333
https://github.com/llvm/llvm-project/issues/85333
miscompilation
fa67986d5b309ddd4c2ea74e8a5eeb0559aa8022
2024-03-14T23:23:02
[ "llvm/test/Transforms/GVNSink" ]
{ "fix_commit": "1c979ab7e59feb03c58cac631a93143b0c776c20", "components": [ "GVNSink" ], "bug_location_lineno": { "llvm/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": [ [ 719, 730 ] ], "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": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": [ "GVNSink::analyzeInstructionForSinking" ], "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 1c979ab7e59feb03c58cac631a93143b0c776c20 Author: AdityaK <[email protected]> Date: Tue Apr 30 11:31:45 2024 -0700 [GVNSink] Fix incorrect codegen with respect to GEPs #85333 (#88440) As mentioned in #68882 and https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699 Gep arithmetic isn't consistent with different types. GVNSink didn't realize this and sank all geps as long as their operands can be wired via PHIs in a post-dominator. Fixes: #85333 diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp index d4907326eb0a..1d2577e1da33 100644 --- a/llvm/lib/Transforms/Scalar/GVNSink.cpp +++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp @@ -719,12 +719,11 @@ GVNSink::analyzeInstructionForSinking(LockstepReverseIterator &LRI, // try and continue making progress. Instruction *I0 = NewInsts[0]; - // If all instructions that are going to participate don't have the same - // number of operands, we can't do any useful PHI analysis for all operands. - auto hasDifferentNumOperands = [&I0](Instruction *I) { - return I->getNumOperands() != I0->getNumOperands(); + auto isNotSameOperation = [&I0](Instruction *I) { + return !I0->isSameOperationAs(I); }; - if (any_of(NewInsts, hasDifferentNumOperands)) + + if (any_of(NewInsts, isNotSameOperation)) return std::nullopt; for (unsigned OpNum = 0, E = I0->getNumOperands(); OpNum != E; ++OpNum) {
[ { "file": "llvm/test/Transforms/GVNSink/different-gep-types.ll", "commands": [ "opt -passes=gvn-sink -S %s" ], "tests": [ { "test_name": "bar", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\n\n%\"struct.std::pair\" = type <{ i32, %struct.substruct, [2 x i8] }>\n%struct.substruct = type { i8, i8 }\n\ndefine void @bar(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) {\nentry:\n %cmp = icmp eq i32 %__n, 1\n br i1 %cmp, label %if.then, label %if.else\n\nif.then: ; preds = %entry\n %0 = load ptr, ptr %__i, align 4\n %incdec.ptr4 = getelementptr inbounds i8, ptr %0, i32 -8\n br label %if.end6\n\nif.else: ; preds = %entry\n %1 = load ptr, ptr %__i, align 4\n %add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %1, i32 %__n\n br label %if.end6\n\nif.end6: ; preds = %if.else, %if.then\n %incdec.ptr.sink = phi ptr [ %incdec.ptr4, %if.then ], [ %add.ptr, %if.else ]\n store ptr %incdec.ptr.sink, ptr %__i, align 4\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "foo", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\n\ndefine void @foo(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) {\nentry:\n %cmp = icmp eq i32 %__n, 1\n br i1 %cmp, label %if.then, label %if.else\n\nif.then: ; preds = %entry\n %0 = load ptr, ptr %__i, align 4\n %incdec.ptr = getelementptr inbounds i8, ptr %0, i32 8\n store ptr %incdec.ptr, ptr %__i, align 4\n br label %if.end6\n\nif.else: ; preds = %entry\n %cmp2 = icmp eq i32 %__n, -1\n br i1 %cmp2, label %if.then3, label %if.else5\n\nif.then3: ; preds = %if.else\n %1 = load ptr, ptr %__i, align 4\n %incdec.ptr4 = getelementptr inbounds i8, ptr %1, i32 -8\n store ptr %incdec.ptr4, ptr %__i, align 4\n br label %if.end6\n\nif.else5: ; preds = %if.else\n %2 = load ptr, ptr %__i, align 4\n %add.ptr = getelementptr inbounds i8, ptr %2, i32 -4\n store ptr %add.ptr, ptr %__i, align 4\n br label %if.end6\n\nif.end6: ; preds = %if.else5, %if.then3, %if.then\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "GVNSink produces incorrect codegen with respect to GEPs", "body": "```llvm\r\ntarget datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\r\ntarget triple = \"thumbv7em-none-unknown-eabi\"\r\n\r\n%\"struct.std::pair\" = type <{ i32, %struct.substruct, [2 x i8] }>\r\n%struct.substruct = type { i8, i8 }\r\n%\"struct.std::random_access_iterator_tag\" = type { i8 }\r\n\r\ndefine linkonce_odr dso_local void @__advance(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) local_unnamed_addr {\r\nentry:\r\n %0 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp = icmp eq i32 %__n, 1\r\n %or.cond = and i1 %0, %cmp\r\n br i1 %or.cond, label %if.then, label %if.else\r\n\r\nif.then: ; preds = %entry\r\n %1 = load ptr, ptr %__i, align 4\r\n %incdec.ptr = getelementptr inbounds i8, ptr %1, i32 8\r\n store ptr %incdec.ptr, ptr %__i, align 4\r\n br label %if.end6\r\n\r\nif.else: ; preds = %entry\r\n %2 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp2 = icmp eq i32 %__n, -1\r\n %or.cond7 = and i1 %2, %cmp2\r\n br i1 %or.cond7, label %if.then3, label %if.else5\r\n\r\nif.then3: ; preds = %if.else\r\n %3 = load ptr, ptr %__i, align 4\r\n %incdec.ptr4 = getelementptr inbounds i8, ptr %3, i32 -8\r\n store ptr %incdec.ptr4, ptr %__i, align 4\r\n br label %if.end6\r\n\r\nif.else5: ; preds = %if.else\r\n %4 = load ptr, ptr %__i, align 4\r\n %add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %4, i32 %__n\r\n store ptr %add.ptr, ptr %__i, align 4\r\n br label %if.end6\r\n\r\nif.end6: ; preds = %if.then3, %if.else5, %if.then\r\n ret void\r\n}\r\n```\r\n\r\nThe above IR when piped through gvn-sink via `./bin/opt < /tmp/repro.ll -passes=gvn-sink -S` produces:\r\n\r\n```llvm\r\n; ModuleID = '<stdin>'\r\nsource_filename = \"<stdin>\"\r\ntarget datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\r\ntarget triple = \"thumbv7em-none-unknown-eabi\"\r\n\r\ndefine linkonce_odr dso_local void @__advance(ptr noundef nonnull align 4 dereferenceable(4) %__i, i32 noundef %__n) local_unnamed_addr {\r\nentry:\r\n %0 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp = icmp eq i32 %__n, 1\r\n %or.cond = and i1 %0, %cmp\r\n br i1 %or.cond, label %if.then, label %if.else\r\n\r\nif.then: ; preds = %entry\r\n br label %if.end6\r\n\r\nif.else: ; preds = %entry\r\n %1 = call i1 @llvm.is.constant.i32(i32 %__n)\r\n %cmp2 = icmp eq i32 %__n, -1\r\n %or.cond7 = and i1 %1, %cmp2\r\n br i1 %or.cond7, label %if.then3, label %if.else5\r\n\r\nif.then3: ; preds = %if.else\r\n br label %if.end6\r\n\r\nif.else5: ; preds = %if.else\r\n br label %if.end6\r\n\r\nif.end6: ; preds = %if.else5, %if.then3, %if.then\r\n %.sink1 = phi i32 [ 8, %if.then ], [ -8, %if.then3 ], [ %__n, %if.else5 ]\r\n %2 = load ptr, ptr %__i, align 4\r\n %incdec.ptr = getelementptr inbounds i8, ptr %2, i32 %.sink1\r\n store ptr %incdec.ptr, ptr %__i, align 4\r\n ret void\r\n}\r\n\r\n; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)\r\ndeclare i1 @llvm.is.constant.i32(i32) #0\r\n\r\nattributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }\r\n```\r\n\r\nThe GEP in the result is incorrect. Prior, the GEPs were\r\n```llvm\r\n %incdec.ptr = getelementptr inbounds i8, ptr %1, i32 8\r\n %incdec.ptr4 = getelementptr inbounds i8, ptr %3, i32 -8\r\n %add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %4, i32 %__n\r\n```\r\nbut now it's\r\n```llvm\r\n%incdec.ptr = getelementptr inbounds i8, ptr %2, i32 %.sink1\r\n```\r\nThis results in an incorrect offset for `%add.ptr = getelementptr inbounds %\"struct.std::pair\", ptr %4, i32 %__n` since we'd now just add `%.sink1` bytes (where `%.sink1 = %__n` which is the second argument), whereas before we'd add `%__n * 8` bytes (where 8 is the sizeof `%\"struct.std::pair\"`).\r\n\r\nThe before ASM is:\r\n```asm\r\n__advance:\r\n ldr r2, [r0]\r\n add.w r1, r2, r1, lsl #3\r\n str r1, [r0]\r\n bx lr\r\n```\r\nbut the after asm is:\r\n```asm\r\n__advance:\r\n ldr r2, [r0]\r\n add r1, r2\r\n str r1, [r0]\r\n bx lr\r\n```\r\n\r\nThe GEP should not be a candidate for sinking.", "author": "PiJoules", "labels": [ "bug", "miscompilation", "llvm:GVN" ], "comments": [] }
true
null
115575
https://github.com/llvm/llvm-project/issues/115575
miscompilation
6fb2a6044f11e251c3847d227049d9dae8b87796
2024-11-09T02:09:23
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/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": [ [ 952, 957 ] ], "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::scalarizeBinopOrCmp" ], "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 958e37cd1feabf29fb1cc3fb5ac82051ad8d43eb Author: Simon Pilgrim <[email protected]> Date: Sat Nov 9 15:59:52 2024 +0000 [VectorCombine] scalarizeBinopOrCmp - check for out of bounds element indices Fixes #115575 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 04ea12ef0f12..b8754b03c2eb 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -952,6 +952,12 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) { if (!IsConst0 && !IsConst1 && Index0 != Index1) return false; + auto *VecTy0 = cast<VectorType>(Ins0->getType()); + auto *VecTy1 = cast<VectorType>(Ins1->getType()); + if (VecTy0->getElementCount().getKnownMinValue() <= Index0 || + VecTy1->getElementCount().getKnownMinValue() <= Index1) + return false; + // Bail for single insertion if it is a load. // TODO: Handle this once getVectorInstrCost can cost for load/stores. auto *I0 = dyn_cast_or_null<Instruction>(V0);
[ { "file": "llvm/test/Transforms/VectorCombine/X86/pr115575.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64--" ], "tests": [ { "test_name": "PR115575", "test_body": "define <2 x i8> @PR115575(i8 %x) {\n %ins = insertelement <2 x i8> poison, i8 %x, i32 3\n %bo = sdiv <2 x i8> %ins, <i8 5, i8 2>\n ret <2 x i8> %bo\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VectorCombine] UB triggered after optimization", "body": "https://github.com/llvm/llvm-project/blob/c93e001ca695e905cb965b36d63f7a348d1dd809/llvm/lib/Transforms/Vectorize/VectorCombine.cpp#L1013-L1031\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/78CM4x\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i8> @sdiv_constant_op1_not_undef_lane.2(i8 %x) {\r\n#0:\r\n %ins = insertelement <2 x i8> poison, i8 %x, i32 3\r\n %bo = sdiv <2 x i8> %ins, { 5, 2 }\r\n ret <2 x i8> %bo\r\n}\r\n=>\r\ndefine <2 x i8> @sdiv_constant_op1_not_undef_lane.2(i8 %x) {\r\n#0:\r\n %bo.scalar = sdiv i8 %x, poison\r\n %bo = insertelement <2 x i8> poison, i8 %bo.scalar, i64 3\r\n ret <2 x i8> %bo\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni8 %x = poison\r\n\r\nSource:\r\n<2 x i8> %ins = < poison, poison >\r\n<2 x i8> %bo = < poison, poison >\r\n\r\nTarget:\r\ni8 %bo.scalar = UB triggered!\r\n\r\n\r\n\r\n----------------------------------------\r\ndefine <2 x i64> @urem_constant_op1_not_undef_lane.2(i64 %x) {\r\n#0:\r\n %ins = insertelement <2 x i64> poison, i64 %x, i32 4294967295\r\n %bo = urem <2 x i64> %ins, { 5, 2 }\r\n ret <2 x i64> %bo\r\n}\r\n=>\r\ndefine <2 x i64> @urem_constant_op1_not_undef_lane.2(i64 %x) {\r\n#0:\r\n %bo.scalar = urem i64 %x, poison\r\n %bo = insertelement <2 x i64> poison, i64 %bo.scalar, i64 4294967295\r\n ret <2 x i64> %bo\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Source is more defined than target\r\n\r\nExample:\r\ni64 %x = poison\r\n\r\nSource:\r\n<2 x i64> %ins = < poison, poison >\r\n<2 x i64> %bo = < poison, poison >\r\n\r\nTarget:\r\ni64 %bo.scalar = UB triggered!\r\n\r\n\r\nSummary:\r\n 0 correct transformations\r\n 2 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "vectorizers" ], "comments": [] }
true
null
95547
https://github.com/llvm/llvm-project/issues/95547
miscompilation
7767f0d47428db66d65b07b35aa52f0507df71f9
2024-06-14T13:54:00
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "534f8569a3c9fccfd5cbc5f632b63ad0cf711098", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 291, 300 ] ], "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": [ "canEvaluateTruncated" ], "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 534f8569a3c9fccfd5cbc5f632b63ad0cf711098 Author: Nikita Popov <[email protected]> Date: Mon Jun 17 15:36:55 2024 +0200 [InstCombine] Don't preserve context across div We can't preserve the context across a non-speculatable instruction, as this might introduce a trap. Alternatively, we could also insert all the replacement instruction at the use-site, but that would be a more intrusive change for the sake of this edge case. Fixes https://github.com/llvm/llvm-project/issues/95547. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 1b4c319032ca..6a6bdba3fa70 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -291,10 +291,12 @@ static bool canEvaluateTruncated(Value *V, Type *Ty, InstCombinerImpl &IC, uint32_t BitWidth = Ty->getScalarSizeInBits(); assert(BitWidth < OrigBitWidth && "Unexpected bitwidths!"); APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, BitWidth); - if (IC.MaskedValueIsZero(I->getOperand(0), Mask, 0, CxtI) && - IC.MaskedValueIsZero(I->getOperand(1), Mask, 0, CxtI)) { - return canEvaluateTruncated(I->getOperand(0), Ty, IC, CxtI) && - canEvaluateTruncated(I->getOperand(1), Ty, IC, CxtI); + // Do not preserve the original context instruction. Simplifying div/rem + // based on later context may introduce a trap. + if (IC.MaskedValueIsZero(I->getOperand(0), Mask, 0, I) && + IC.MaskedValueIsZero(I->getOperand(1), Mask, 0, I)) { + return canEvaluateTruncated(I->getOperand(0), Ty, IC, I) && + canEvaluateTruncated(I->getOperand(1), Ty, IC, I); } break; }
[ { "file": "llvm/test/Transforms/InstCombine/trunc.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "trunc_nuw_xor_vector", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine <2 x i1> @trunc_nuw_xor_vector(<2 x i8> %x, <2 x i8> %y) {\n %xor = xor <2 x i8> %x, %y\n %r = trunc nuw <2 x i8> %xor to <2 x i1>\n ret <2 x i1> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr95547", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndeclare void @use.i8(i8)\n\ndefine void @pr95547(i32 %x) {\n %x.trunc = trunc i32 %x to i16\n %div = udiv i16 11, %x.trunc\n %cmp = icmp ult i32 %x, 256\n br i1 %cmp, label %loop, label %exit\n\nloop: ; preds = %loop, %0\n %trunc = trunc i16 %div to i8\n call void @use.i8(i8 %trunc)\n br label %loop\n\nexit: ; preds = %0\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Wrong value truncation due to incorrect analysis of iv known bits", "body": "```llvm\r\ndefine void @src(i32 %0, ptr %p, i1 %cnd) {\r\nentry:\r\n br i1 %cnd, label %header, label %exit\r\n\r\nheader: ; preds = %latch, %entry\r\n %iv = phi i32 [ %iv.next, %latch ], [ 256, %entry ]\r\n %iv.trunc = trunc i32 %iv to i16\r\n %div = udiv i16 11, %iv.trunc\r\n br i1 %cnd, label %loop1, label %loop0\r\n\r\nloop0: ; preds = %header\r\n %load = load i32, ptr %p, align 4\r\n br label %loop1\r\n\r\nloop1: ; preds = %loop0, %header\r\n %v = phi i32 [ %load, %loop0 ], [ 0, %header ]\r\n store i32 %v, ptr %p, align 4\r\n %guard = icmp ugt i32 %iv, 10\r\n br i1 %guard, label %latch, label %loop2\r\n\r\nloop2: ; preds = %loop1\r\n %div.trunc = trunc i16 %div to i8\r\n store i8 %div.trunc, ptr %p, align 1\r\n br label %latch\r\n\r\nlatch: ; preds = %loop2, %loop1\r\n %iv.next = add nuw nsw i32 %iv, 1\r\n %exitcond = icmp ugt i32 %iv, 300\r\n br i1 %exitcond, label %exit, label %header\r\n\r\nexit: ; preds = %latch\r\n ret void\r\n}\r\n```\r\nIf we run `instcombine` pass on this example, it will convert `trunc i32 %iv to i16` into `trunc i32 %iv to i8` to avoid cast:\r\nhttps://godbolt.org/z/ze4E45ThT\r\n\r\nBut this transformation is wrong, because on the first iteration `%iv` is equal to 256, and the 8 bits trunc makes it equal to `0`. This give us a division by zero on the next instruction: `%div = udiv i16 11, %iv.trunc`.\r\n\r\nIt seems that the problematic patch is https://github.com/llvm/llvm-project/pull/73662\r\n\r\n@nikic Could you please take a look?", "author": "aleks-tmb", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "antoniofrighetto", "body": "May be false positive in Alive2 as well?" }, { "author": "dtcxzyw", "body": "> May be false positive in Alive2 as well?\r\n\r\nYou need `-src-unroll` and `-tgt-unroll` for loops :)\r\nhttps://alive2.llvm.org/ce/z/Vh4zAU" }, { "author": "antoniofrighetto", "body": "Just out of curiosity, did you fine-tune the iterations in a particular way, or some trial-and-error? (I had tried a few ones before and didn’t manage to have the UB triggered)" }, { "author": "dtcxzyw", "body": "> Just out of curiosity, did you fine-tune the iterations in a particular way, or some trial-and-error? (I had tried a few ones before and didn’t manage to have the UB triggered)\r\n\r\nI just full unrolled the loop :)\r\n```\r\n%iv.next = add nuw nsw i32 %iv, 1\r\n%exitcond = icmp ugt i32 %iv, 300\r\n```" }, { "author": "antoniofrighetto", "body": "> I just full unrolled the loop :)\r\n\r\nDefinitely makes sense, thanks!" }, { "author": "nikic", "body": "Reduced test case:\r\n```llvm\r\ndefine void @src(i32 %x) {\r\n %x.trunc = trunc i32 %x to i16\r\n %div = udiv i16 11, %x.trunc\r\n %cmp = icmp ult i32 %x, 256\r\n br i1 %cmp, label %loop, label %exit\r\n\r\nloop:\r\n %trunc = trunc i16 %div to i8\r\n call void @use(i8 %trunc)\r\n br label %loop\r\n\r\nexit:\r\n ret void\r\n}\r\n\r\ndeclare void @use(i8)\r\n```\r\n\r\nThe issue is that canEvaluateTruncated() preserves context instruction across non-speculatable operations." } ] }
true
null
94897
https://github.com/llvm/llvm-project/issues/94897
miscompilation
add89088fb8de84fdbeb97c0386a831e51d090a1
2024-06-09T10:15:35
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "e4b0655b297e4f4b0eb26548c8be48d527ebc178", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 2441, 2449 ] ], "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::foldICmpShlConstant" ], "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 e4b0655b297e4f4b0eb26548c8be48d527ebc178 Author: Yingwei Zheng <[email protected]> Date: Mon Jun 10 03:17:01 2024 +0800 [InstCombine] Fix missing argument typo in `InstCombinerImpl::foldICmpShlConstant` (#94899) Closes #94897. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4203147bc6a5..3fce4a3c20b3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2441,9 +2441,10 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp, Type *TruncTy = ShType->getWithNewBitWidth(TypeBits - Amt); Constant *NewC = ConstantInt::get(TruncTy, RHSC.ashr(*ShiftAmt).trunc(TypeBits - Amt)); - return new ICmpInst( - CmpPred, Builder.CreateTrunc(X, TruncTy, "", Shl->hasNoSignedWrap()), - NewC); + return new ICmpInst(CmpPred, + Builder.CreateTrunc(X, TruncTy, "", /*IsNUW=*/false, + Shl->hasNoSignedWrap()), + NewC); } }
[ { "file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_icmp_shl_sgt", "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 @test_icmp_shl_sgt(i64 %x) {\n %shl = shl i64 %x, 32\n %cmp = icmp sgt i64 %shl, 8589934591\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nuw_i31", "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 @test_icmp_shl_nuw_i31(i31 %x) {\n %shl = shl nuw i31 %x, 23\n %cmp = icmp ugt i31 %shl, -50331648\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_vec", "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 <2 x i1> @test_icmp_shl_vec(<2 x i64> %x) {\n %shl = shl <2 x i64> %x, splat (i64 32)\n %cmp = icmp ult <2 x i64> %shl, splat (i64 8589934593)\n ret <2 x i1> %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nsw_i31", "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 @test_icmp_shl_nsw_i31(i31 %x) {\n %shl = shl nsw i31 %x, 23\n %cmp = icmp ugt i31 %shl, -50331648\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nsw", "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 @test_icmp_shl_nsw(i64 %x) {\n %shl = shl nsw i64 %x, 32\n %cmp = icmp ult i64 %shl, 8589934593\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr94897", "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 @pr94897(i32 range(i32 -2147483648, 0) %x) {\n %shl = shl nsw i32 %x, 24\n %cmp = icmp ugt i32 %shl, -50331648\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nuw", "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 @test_icmp_shl_nuw(i64 %x) {\n %shl = shl nuw i64 %x, 32\n %cmp = icmp ult i64 %shl, 8589934593\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "wrong code at -O1 and above on x86_64-linux-gnu", "body": "This 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/T9b4a7z3v\r\n\r\n```console\r\n% clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 338cbfef03e0ab58d7b52f3301928c58b194a1b4)\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% \r\n% clangtk -O0 small.c; ./a.out\r\n% clangtk -O1 small.c\r\n% ./a.out\r\nAborted\r\n% cat small.c\r\nint a;\r\nchar b(char c, char d) { return c - d; }\r\nint main() {\r\n int e;\r\n for (a = -10; a > -11; a--)\r\n e = b(a, -1);\r\n if (e > -2)\r\n __builtin_abort();\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "miscompilation", "confirmed", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/_3cyuT\r\n```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\n\r\ndefine i1 @src() {\r\nentry:\r\n br label %for.body\r\n\r\nfor.body:\r\n %storemerge4 = phi i32 [ -10, %entry ], [ %dec, %for.body ]\r\n %dec = add nsw i32 %storemerge4, -1\r\n %cmp = icmp ugt i32 %dec, -11\r\n br i1 %cmp, label %for.body, label %for.end\r\n\r\nfor.end:\r\n %sub.i.le = shl nsw i32 %storemerge4, 24\r\n %cmp2 = icmp ugt i32 %sub.i.le, -50331648\r\n ret i1 %cmp2\r\n}\r\n\r\ndefine i1 @tgt() {\r\nentry:\r\n br label %for.body\r\n\r\nfor.body:\r\n %storemerge4 = phi i32 [ -10, %entry ], [ %dec, %for.body ]\r\n %dec = add nsw i32 %storemerge4, -1\r\n %cmp = icmp ugt i32 %dec, -11\r\n br i1 %cmp, label %for.body, label %for.end\r\n\r\nfor.end:\r\n %0 = trunc nuw i32 %storemerge4 to i8\r\n %cmp2 = icmp ugt i8 %0, -3\r\n ret i1 %cmp2\r\n}\r\n```\r\n\r\n`nuw` flag is incorrectly added." }, { "author": "dtcxzyw", "body": "Caused by https://github.com/llvm/llvm-project/commit/5c7c1f6aba467b1c5a51d58fc591314ecd7147ce." } ] }
true
null
124526
https://github.com/llvm/llvm-project/issues/124526
crash
e14962a39cc6476bebba65e5639b74b0318c7fc3
2025-01-27T10:24:37
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "212f344b84b400c0a9dedfa3c1ec6af9d9d30223", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 732, 738 ] ], "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": [ "tryFactorization" ], "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 212f344b84b400c0a9dedfa3c1ec6af9d9d30223 Author: Nikita Popov <[email protected]> Date: Mon Jan 27 16:24:15 2025 +0100 [InstCombine] Handle constant expression result in tryFactorization() If IRBuilder folds the result to a constant expression, don't try to set nowrap flags on it. Fixes https://github.com/llvm/llvm-project/issues/124526. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index cad17c511b6d..a64c188575e6 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -732,7 +732,7 @@ static Value *tryFactorization(BinaryOperator &I, const SimplifyQuery &SQ, RetVal->takeName(&I); // Try to add no-overflow flags to the final value. - if (isa<OverflowingBinaryOperator>(RetVal)) { + if (isa<BinaryOperator>(RetVal)) { bool HasNSW = false; bool HasNUW = false; if (isa<OverflowingBinaryOperator>(&I)) {
[ { "file": "llvm/test/Transforms/InstCombine/add2.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "mul_add_to_mul_9", "test_body": "define i16 @mul_add_to_mul_9(i16 %a) {\n %mul1 = mul nsw i16 %a, 16384\n %mul2 = mul nsw i16 %a, 16384\n %add = add nsw i16 %mul1, %mul2\n ret i16 %add\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "shl_add_to_shl_constexpr", "test_body": "@g = external global i8\n\ndefine i32 @shl_add_to_shl_constexpr() {\n %shl = shl i32 ptrtoint (ptr @g to i32), 1\n %add = add i32 %shl, %shl\n ret i32 %add\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Crash at -O2: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.", "body": "This code crashes at `-O2`:\n\n```c\nint a, b;\nvoid c();\nint d(int e) {\n if (e)\n return 3;\n return 2;\n}\nint f(int e) {\n int i = d(e) + e;\n return i;\n}\nint j(int e) {\n static char g;\n char *h = &g;\n a = h - \"\";\n b = a << e;\n return f(b - 7) + 303 + b;\n}\nvoid k() {\n int l = j(4);\n c(l);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/4h9PrKG8z\n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\n```\n\nBacktrace:\n\n```console\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O2 -Wextra -Wall <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,extra-simple-loop-unswitch-passes,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide)),function(invalidate<should-not-run-function-passes>),cgscc(devirt<4>())\" on module \"<source>\"\n4.\tRunning pass \"cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>,loop(loop-idiom,indvars,extra-simple-loop-unswitch-passes,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,instcombine<max-iterations=1;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split,coro-annotation-elide))\" on module \"<source>\"\n5.\tRunning pass \"instcombine<max-iterations=1;no-verify-fixpoint>\" on function \"k\"\n #0 0x0000000003def1b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3def1b8)\n #1 0x0000000003dece74 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3dece74)\n #2 0x0000000003d39368 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x0000789749042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007897490969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x0000789749042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007897490287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x000078974902871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x0000789749039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000000000d8d74a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd8d74a)\n#10 0x0000000003935620 tryFactorization(llvm::BinaryOperator&, llvm::SimplifyQuery const&, llvm::IRBuilder<llvm::TargetFolder, llvm::IRBuilderCallbackInserter>&, llvm::Instruction::BinaryOps, llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*) InstructionCombining.cpp:0:0\n#11 0x0000000003935ce2 llvm::InstCombinerImpl::tryFactorizationFolds(llvm::BinaryOperator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3935ce2)\n#12 0x0000000003935d67 llvm::InstCombinerImpl::foldUsingDistributiveLaws(llvm::BinaryOperator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3935d67)\n#13 0x0000000003972ab2 llvm::InstCombinerImpl::visitAdd(llvm::BinaryOperator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3972ab2)\n#14 0x00000000039586c1 llvm::InstCombinerImpl::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x39586c1)\n#15 0x000000000395a066 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) (.isra.0) InstructionCombining.cpp:0:0\n#16 0x000000000395b52c llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x395b52c)\n#17 0x0000000004094a6e llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4094a6e)\n#18 0x0000000003796c50 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3796c50)\n#19 0x000000000114aa4e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x114aa4e)\n#20 0x0000000002c71112 llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c71112)\n#21 0x000000000114aede llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x114aede)\n#22 0x0000000002c68502 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c68502)\n#23 0x000000000548dd6e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x548dd6e)\n#24 0x0000000002c6dbd6 llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c6dbd6)\n#25 0x000000000548dd8e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x548dd8e)\n#26 0x0000000002c6ba86 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x2c6ba86)\n#27 0x000000000548dd4e llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x548dd4e)\n#28 0x0000000003794f70 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3794f70)\n#29 0x00000000056e3783 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x56e3783)\n#30 0x000000000532b69e llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x532b69e)\n#31 0x0000000003794f70 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3794f70)\n#32 0x00000000040a7734 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#33 0x00000000040ab13e clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x40ab13e)\n#34 0x000000000477edb0 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x477edb0)\n#35 0x00000000067c259c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67c259c)\n#36 0x000000000477f1b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x477f1b8)\n#37 0x0000000004a44575 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a44575)\n#38 0x00000000049c72ae clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49c72ae)\n#39 0x0000000004b31ede clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b31ede)\n#40 0x0000000000cfcd0f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcfcd0f)\n#41 0x0000000000cf47aa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#42 0x00000000047c5ae9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#43 0x0000000003d39814 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d39814)\n#44 0x00000000047c60df clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#45 0x0000000004788f4d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4788f4d)\n#46 0x0000000004789fce clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4789fce)\n#47 0x0000000004791b05 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4791b05)\n#48 0x0000000000cf9b23 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcf9b23)\n#49 0x0000000000bc2a84 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbc2a84)\n#50 0x0000789749029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#51 0x0000789749029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#52 0x0000000000cf4255 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcf4255)\n```", "author": "cardigan1008", "labels": [ "crash", "llvm:instcombine", "regression:19" ], "comments": [ { "author": "shafik", "body": "Looks like a clang-19 regression: https://godbolt.org/z/EvWdTGY6E" }, { "author": "nikic", "body": "```llvm\n; RUN: opt -passes=instcombine < %s\n@g = external global i8\n\ndefine i32 @test() {\n %shl = shl i32 ptrtoint (ptr @g to i32), 1\n %add1 = add i32 %shl, -1\n %add2 = add i32 %shl, 2\n %add3 = add i32 %add1, %add2\n ret i32 %add3 \n} \n```" }, { "author": "nikic", "body": "Further reduced:\n```llvm\n@g = external global i8\n\ndefine i32 @test() {\n %shl = shl i32 ptrtoint (ptr @g to i32), 1\n %add = add i32 %shl, %shl\n ret i32 %add \n} \n```" } ] }
true
null
113423
https://github.com/llvm/llvm-project/issues/113423
miscompilation
a1c6dc223ee1eedc049890676992b508ebd6b623
2024-10-23T07:13:21
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "cf1963afad335cf74a9411f106d1f2fe80dbed2f", "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": [ [ 529, 537 ], [ 564, 569 ] ], "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::foldSelectIntoOp" ], "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 cf1963afad335cf74a9411f106d1f2fe80dbed2f Author: Yingwei Zheng <[email protected]> Date: Thu Oct 31 23:26:45 2024 +0800 [InstCombine] Fix FMF propagation in `foldSelectIntoOp` (#114356) Closes https://github.com/llvm/llvm-project/issues/113423. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index c5f39a4c381e..9e193e7faa8a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -529,9 +529,6 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal, if (!OpToFold) return nullptr; - // TODO: We probably ought to revisit cases where the select and FP - // instructions have different flags and add tests to ensure the - // behaviour is correct. FastMathFlags FMF; if (isa<FPMathOperator>(&SI)) FMF = SI.getFastMathFlags(); @@ -564,6 +561,8 @@ Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal, BinaryOperator *BO = BinaryOperator::Create(TVI->getOpcode(), FalseVal, NewSel); BO->copyIRFlags(TVI); + if (isa<FPMathOperator>(&SI)) + BO->andIRFlags(NewSel); return BO; };
[ { "file": "llvm/test/Transforms/InstCombine/fold-select-fmul-if-zero.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "fmul_by_self_if_0_oeq_zero_f32_fmul_nnan_ninf_nsz", "test_body": "define float @fmul_by_self_if_0_oeq_zero_f32_fmul_nnan_ninf_nsz(float %x) {\n %x.is.zero = fcmp oeq float %x, 0.000000e+00\n %scaled.x = fmul nnan ninf nsz float %x, %x\n %scaled.if.denormal = select nnan i1 %x.is.zero, float %scaled.x, float %x\n ret float %scaled.if.denormal\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Wrong folding of `select` into floating number ops", "body": "https://github.com/llvm/llvm-project/blob/ae618d360456c5ccf6c8cf2294e708ac6625950e/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L559-L568\r\n\r\nThe compiler explorer's alive2 times out for this case.\r\nBut I post a proof that the optimization actually happens: https://alive2.llvm.org/ce/z/7MRSu5\r\n\r\n\r\nThis is the Alive2 report on my machine:\r\n```llvm\r\n----------------------------------------\r\ndefine float @fmul_by_self_if_0_oeq_zero_f32_fmul_nnan_ninf_nsz.2(float %x) {\r\n#0:\r\n %#1 = fcmp ule float %x, 0.000000\r\n %scaled.x = fmul nnan ninf nsz float %x, %x\r\n %scaled.if.denormal = select nnan i1 %#1, float %x, float %scaled.x\r\n ret float %scaled.if.denormal\r\n}\r\n=>\r\ndefine float @fmul_by_self_if_0_oeq_zero_f32_fmul_nnan_ninf_nsz.2(float %x) {\r\n#0:\r\n %#1 = fcmp ule float %x, 0.000000\r\n %scaled.x = select nnan i1 %#1, float 1.000000, float %x\r\n %scaled.if.denormal = fmul nnan ninf nsz float %scaled.x, %x\r\n ret float %scaled.if.denormal\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 %#1 = #x1 (1)\r\nfloat %scaled.x = poison\r\nfloat %scaled.if.denormal = #xff800000 (-oo)\r\n\r\nTarget:\r\ni1 %#1 = #x1 (1)\r\nfloat %scaled.x = #x3f800000 (1)\r\nfloat %scaled.if.denormal = poison\r\nSource value: #xff800000 (-oo)\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": [] }
true
null
99701
https://github.com/llvm/llvm-project/issues/99701
crash
9a258664024d12a06ba8eb9344e270a9bb5f5d87
2024-07-19T20:27:53
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "ba8126b6fef79bd344a247f6291aaec7b67bdff0", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 137, 142 ], [ 6681, 6686 ], [ 6690, 6695 ], [ 6717, 6722 ] ], "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 ba8126b6fef79bd344a247f6291aaec7b67bdff0 Author: Florian Hahn <[email protected]> Date: Wed Jul 24 09:31:32 2024 +0100 [LV] Mark dead instructions in loop as free. Update collectValuesToIgnore to also ignore dead instructions in the loop. Such instructions will be removed by VPlan-based DCE and won't be considered by the VPlan-based cost model. This closes a gap between the legacy and VPlan-based cost model. In practice with the default pipelines, there shouldn't be any dead instructions in loops reaching LoopVectorize, but it is easy to generate such cases by hand or automatically via fuzzers. Fixes https://github.com/llvm/llvm-project/issues/99701. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 8fa1a57177d9..e4477f96aa62 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -137,6 +137,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/InjectTLIMappings.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/LoopSimplify.h" #include "llvm/Transforms/Utils/LoopUtils.h" #include "llvm/Transforms/Utils/LoopVersioning.h" @@ -6681,6 +6682,7 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { CodeMetrics::collectEphemeralValues(TheLoop, AC, ValuesToIgnore); SmallVector<Value *, 4> DeadInterleavePointerOps; + SmallVector<Value *, 4> DeadOps; for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { // Find all stores to invariant variables. Since they are going to sink @@ -6690,6 +6692,17 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { Legal->isInvariantAddressOfReduction(SI->getPointerOperand())) ValuesToIgnore.insert(&I); + if (VecValuesToIgnore.contains(&I) || ValuesToIgnore.contains(&I)) + continue; + + // Add instructions that would be trivially dead and are only used by + // values already ignored to DeadOps to seed worklist. + if (wouldInstructionBeTriviallyDead(&I, TLI) && + all_of(I.users(), [this](User *U) { + return VecValuesToIgnore.contains(U) || ValuesToIgnore.contains(U); + })) + DeadOps.push_back(&I); + // For interleave groups, we only create a pointer for the start of the // interleave group. Queue up addresses of group members except the insert // position for further processing. @@ -6717,6 +6730,29 @@ void LoopVectorizationCostModel::collectValuesToIgnore() { DeadInterleavePointerOps.append(Op->op_begin(), Op->op_end()); } + // Mark ops that would be trivially dead and are only used by ignored + // instructions as free. + for (unsigned I = 0; I != DeadOps.size(); ++I) { + auto *Op = dyn_cast<Instruction>(DeadOps[I]); + // Skip any op that shouldn't be considered dead. + if (!Op || !TheLoop->contains(Op) || + !wouldInstructionBeTriviallyDead(Op, TLI) || + any_of(Op->users(), [this](User *U) { + return !VecValuesToIgnore.contains(U) && !ValuesToIgnore.contains(U); + })) + continue; + + // If all of Op's users are in ValuesToIgnore, add it to ValuesToIgnore + // which applies for both scalar and vector versions. Otherwise it is only + // dead in vector versions, so only add it to VecValuesToIgnore. + if (all_of(Op->users(), + [this](User *U) { return ValuesToIgnore.contains(U); })) + ValuesToIgnore.insert(Op); + + VecValuesToIgnore.insert(Op); + DeadOps.append(Op->op_begin(), Op->op_end()); + } + // Ignore type-promoting instructions we identified during reduction // detection. for (const auto &Reduction : Legal->getReductionVars()) {
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll", "commands": [ "opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Test with a dead load in the loop, from\n; https://github.com/llvm/llvm-project/issues/99701\ndefine void @dead_load(ptr %p, i16 %start) {\n;\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop:\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit:\n ret void\n}\n;.\n;.", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "I have a few finds by the fuzzer that affect LLVM (tested using a1d77caaabbb5279b734c061dab36b2138ec476d).\r\nI think they're all duplicates but I'm attaching them all in a .zip so it can be confirmed.\r\n\r\nTestcase:\r\n```llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @e(i64 %0) #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.for.cond.cleanup_crit_edge: ; preds = %for.body\r\n ret void\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\r\n %arrayidx = getelementptr i16, ptr null, i64 %indvars.iv\r\n %1 = load i16, ptr %arrayidx, align 2\r\n %arrayidx5 = getelementptr [0 x i8], ptr null, i64 0, i64 %indvars.iv\r\n store i8 0, ptr %arrayidx5, align 1\r\n %indvars.iv.next = add nsw i64 %indvars.iv, 4\r\n %cmp = icmp ult i64 %indvars.iv, %0\r\n br i1 %cmp, label %for.body, label %for.cond.for.cond.cleanup_crit_edge\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zacas,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n\r\n```\r\n\r\nCommand/backtrace:\r\n```bash\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10444: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"e\"\r\n #0 0x000055b365fe4a60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f0ea60)\r\n #1 0x000055b365fe1e7f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2f0be7f)\r\n #2 0x000055b365fe1fd5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007612a3042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007612a30969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007612a30969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007612a30969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007612a3042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007612a30287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007612a302871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007612a3039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000055b365005ba8 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f2fba8)\r\n#12 0x000055b365008761 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f32761)\r\n#13 0x000055b365008ee0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f32ee0)\r\n#14 0x000055b363e81296 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xdab296)\r\n#15 0x000055b365dfd4be llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d274be)\r\n#16 0x000055b363e84426 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xdae426)\r\n#17 0x000055b365dfc24b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d2624b)\r\n#18 0x000055b363e80776 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xdaa776)\r\n#19 0x000055b365dfa39d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2d2439d)\r\n#20 0x000055b3636cbdc6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5f5dc6)\r\n#21 0x000055b3636bda11 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e7a11)\r\n#22 0x00007612a3029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#23 0x00007612a3029e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#24 0x00007612a3029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#25 0x000055b3636b3855 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5dd855)\r\nzsh: IOT instruction /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/a7KPnMh94\r\n\r\nZip with all finds reduced: \r\n[finds.zip](https://github.com/user-attachments/files/16316789/finds.zip)\r\n\r\nRelated: https://github.com/llvm/llvm-project/pull/92555 @fhahn \r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "JonPsson1", "body": "I'm seeing this as well with a multitude of hits with csmith. One reduced test case:\r\n\r\nclang -O3 -march=z16 crash0.i -o a.out -w -mllvm -disable-licm-promotion -mllvm -force-target-instruction-cost=1 -mllvm -unroll-count=4\r\nLoopVectorize.cpp:10071: bool llvm::LoopVectorizePass::processLoop(llvm::Loop*): Assertion `VF.Width == Width && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\n#9 0x0000000004749e30 llvm::LoopVectorizePass::processLoop()\r\n\r\n[tc_lv.i.tar.gz](https://github.com/user-attachments/files/16337463/tc_lv.i.tar.gz)\r\n\r\n" }, { "author": "fhahn", "body": "Thanks @patrick-rivos, it looks like all test cases had dead instructions, which would be considered by the legacy cost model but not the VPlan-based one (because VPlan-based DCE would clean them up before). Should be fixed now.\r\n\r\n@JonPsson1's case was a different issue and should also be fixed." } ] }
true
null
81561
https://github.com/llvm/llvm-project/issues/81561
crash
e79ad7bb94611666a23764459098574bc0394d56
2024-02-13T01:36:19
[ "llvm/test/DebugInfo/Generic" ]
{ "fix_commit": "97088b2ab2184ad4bd64f59fba0b92b70468b10d", "components": [ "ValueMapper" ], "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": [ [ 552, 557 ] ], "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": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": [ "Mapper::remapDPValue" ], "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 97088b2ab2184ad4bd64f59fba0b92b70468b10d Author: Orlando Cazalet-Hyams <[email protected]> Date: Tue Feb 13 11:35:28 2024 +0000 [RemoveDIs][ValueMapper] Remap DIAssignIDs in DPValues (#81595) Fix crash raised in comments for 5c9f7682b090124d9a8b69f92d3f7c269dca25fc diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index a8ae3ee3b251..93a4c829df06 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -552,6 +552,7 @@ void Mapper::remapDPValue(DPValue &V) { V.setKillAddress(); else if (NewAddr) V.setAddress(NewAddr); + V.setAssignId(cast<DIAssignID>(mapMetadata(V.getAssignID()))); } // Find Value operands and remap those.
[ { "file": "llvm/test/DebugInfo/Generic/ipsccp-remap-assign-id.ll", "commands": [ "opt -passes=ipsccp %s -S -o -", "opt --try-experimental-debuginfo-iterators -passes=ipsccp %s -S -o -" ], "tests": [ { "test_name": "<module>", "test_body": "\n;; Check the dbg.assign DIAssignID operand gets remapped after cloning.\n\n;\n\n; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare void @llvm.dbg.declare(metadata, metadata, metadata)\n\ndefine void @inv_txfm_add_dct_dct_4x4_c() {\nentry:\n call void @inv_txfm_add_c(ptr @dav1d_inv_dct4_1d_c)\n ret void\n}\n\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)\n\n; Function Attrs: noinline\ndefine void @inv_txfm_add_c(ptr %first_1d_fn) #2 {\nentry:\n %tmp = alloca [4096 x i32], i32 0, align 16, !DIAssignID !5\n tail call void @llvm.dbg.assign(metadata i1 undef, metadata !6, metadata !DIExpression(), metadata !5, metadata ptr %tmp, metadata !DIExpression()), !dbg !16\n call void @llvm.memset.p0.i64(ptr %tmp, i8 0, i64 0, i1 false), !DIAssignID !17\n call void %first_1d_fn(ptr null, i64 0, i32 0, i32 0)\n ret void\n}\n\ndeclare void @dav1d_inv_dct4_1d_c(ptr, i64, i32, i32)\n\ndeclare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)\n\nattributes #2 = { noinline }\n\n!llvm.dbg.cu = !{!0}\n!llvm.module.flags = !{!3, !4}\n\n!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, splitDebugInlining: false, nameTableKind: GNU)\n!1 = !DIFile(filename: \"itx_tmpl.c\", directory: \".\")\n!2 = !{}\n!3 = !{i32 2, !\"Debug Info Version\", i32 3}\n!4 = !{i32 7, !\"debug-info-assignment-tracking\", i1 true}\n!5 = distinct !DIAssignID()\n!6 = !DILocalVariable(name: \"tmp\", scope: !7, file: !1, line: 78, type: !10)\n!7 = distinct !DISubprogram(name: \"inv_txfm_add_c\", scope: !1, file: !1, line: 41, type: !8, scopeLine: 45, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)\n!8 = distinct !DISubroutineType(types: !9)\n!9 = !{null}\n!10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 131072, elements: !2)\n!11 = !DIDerivedType(tag: DW_TAG_typedef, name: \"int32_t\", file: !12, line: 26, baseType: !13)\n!12 = !DIFile(filename: \"stdint-intn.h\", directory: \".\")\n!13 = !DIDerivedType(tag: DW_TAG_typedef, name: \"__int32_t\", file: !14, line: 41, baseType: !15)\n!14 = !DIFile(filename: \"types.h\", directory: \".\")\n!15 = !DIBasicType(name: \"int\", size: 32, encoding: DW_ATE_signed)\n!16 = !DILocation(line: 0, scope: !7)\n!17 = distinct !DIAssignID()", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Clang frontend command failed to build lib/vsprintf.c in Linux kernel", "body": "```\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: clang -Wp,-MMD,lib/.vsprintf.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ --target=x86_64-linux-gnu -fintegrated-as -Werror=unknown-warning-option -Werror=ignored-optimization-argument -Werror=option-ignored -Werror=unused-command-line-argument -fmacro-prefix-map=./= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mstack-alignment=8 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mretpoline-external-thunk -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -mharden-sls=all -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -O2 -fstack-protector-strong -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=zero -fno-stack-clash-protection -fzero-call-used-regs=used-gpr -DCC_USING_NOP_MCOUNT -DCC_USING_FENTRY -falign-functions=16 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=1024 -Wno-gnu -Wno-unused-but-set-variable -Wno-unused-const-variable -Wvla -Wno-pointer-sign -Wcast-function-type -Wimplicit-fallthrough -Werror=date-time -Werror=incompatible-pointer-types -Wenum-conversion -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-format-overflow -Wno-format-truncation -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -Wno-unaligned-access -Wno-cast-function-type-strict -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-initializer-overrides -Wno-sign-compare -g -gdwarf-5 -fsanitize=array-bounds -fsanitize=shift -fsanitize=bool -fsanitize=enum -DKBUILD_MODFILE=\\\"lib/vsprintf\\\" -DKBUILD_BASENAME=\\\"vsprintf\\\" -DKBUILD_MODNAME=\\\"vsprintf\\\" -D__KBUILD_MODNAME=kmod_vsprintf -c -o lib/vsprintf.o lib/vsprintf.c\r\n1.\t<eof> parser at end of file\r\n2.\tCode generation\r\n3.\tRunning pass 'Function Pass Manager' on module 'lib/vsprintf.c'.\r\n4.\tRunning pass 'Assignment Tracking Analysis' on function '@ip4_string'\r\n #0 0x000055fc39a6be88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2d82e88)\r\n #1 0x000055fc39a69c6e llvm::sys::RunSignalHandlers() (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2d80c6e)\r\n #2 0x000055fc399e7729 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f7639a42990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)\r\n #4 0x000055fc39484775 (anonymous namespace)::AssignmentTrackingLowering::run(FunctionVarLocsBuilder*) AssignmentTrackingAnalysis.cpp:0:0\r\n #5 0x000055fc3947f3fe analyzeFunction(llvm::Function&, llvm::DataLayout const&, FunctionVarLocsBuilder*) AssignmentTrackingAnalysis.cpp:0:0\r\n #6 0x000055fc3947fdcd llvm::AssignmentTrackingAnalysis::runOnFunction(llvm::Function&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2796dcd)\r\n #7 0x000055fc395bab96 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x28d1b96)\r\n #8 0x000055fc395c1a23 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x28d8a23)\r\n #9 0x000055fc395bb807 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x28d2807)\r\n#10 0x000055fc39c161b6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2f2d1b6)\r\n#11 0x000055fc3a09fed5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33b6ed5)\r\n#12 0x000055fc3b7248f6 clang::ParseAST(clang::Sema&, bool, bool) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x4a3b8f6)\r\n#13 0x000055fc3a316d86 clang::FrontendAction::Execute() (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x362dd86)\r\n#14 0x000055fc3a28c654 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x35a3654)\r\n#15 0x000055fc3a3d293e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x36e993e)\r\n#16 0x000055fc37b20c3c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe37c3c)\r\n#17 0x000055fc37b1dc71 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#18 0x000055fc3a0e9eb9 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::$_0>(long) Job.cpp:0:0\r\n#19 0x000055fc399e750c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x2cfe50c)\r\n#20 0x000055fc3a0e9906 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x3400906)\r\n#21 0x000055fc3a0abd57 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33c2d57)\r\n#22 0x000055fc3a0ac1fe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33c31fe)\r\n#23 0x000055fc3a0ca5df clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0x33e15df)\r\n#24 0x000055fc37b1d338 clang_main(int, char**, llvm::ToolContext const&) (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe34338)\r\n#25 0x000055fc37b2b8d7 main (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe428d7)\r\n#26 0x00007f7639a28150 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\r\n#27 0x00007f7639a28209 call_init ./csu/../csu/libc-start.c:128:20\r\n#28 0x00007f7639a28209 __libc_start_main ./csu/../csu/libc-start.c:347:5\r\n#29 0x000055fc37b1a4b5 _start (/home/eve/Downloads/llvm-project/build2/bin/clang-19+0xe314b5)\r\nclang: error: clang frontend command failed with exit code 139 (use -v to see invocation)\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 3bdc4c702dfdd1f2fb513943f034d49bb79ded29)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/eve/Downloads/llvm-project/build2/bin\r\nclang: note: diagnostic msg: \r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclang: note: diagnostic msg: /tmp/vsprintf-e230c3.c\r\nclang: note: diagnostic msg: /tmp/vsprintf-e230c3.sh\r\nclang: note: diagnostic msg: \r\n\r\n********************\r\n\r\n```\r\n[vsprintf-e230c3.zip](https://github.com/llvm/llvm-project/files/14254556/vsprintf-e230c3.zip)\r\n\r\nThis issue occurs at commit:\r\n```\r\ncommit 3bdc4c702dfdd1f2fb513943f034d49bb79ded29 (HEAD -> main, origin/main, origin/HEAD)\r\nAuthor: Kevin Frei <[email protected]>\r\nDate: Mon Feb 12 16:57:02 2024 -0800\r\n```\r\n\r\nThis issue does not occur at commit:\r\n```\r\ncommit 63b414e4977d6e19f05947c88f57cd127fa328e3\r\nAuthor: Vlad Serebrennikov <[email protected]>\r\nDate: Sun Feb 11 15:01:18 2024 +0300\r\n```\r\nEdit: this issue also occurs at commit:\r\n```\r\ncommit 13d60ce2f262ef9055389908b63824e53b3054a1 (HEAD)\r\nAuthor: Amir Ayupov <[email protected]>\r\nDate: Mon Feb 12 14:51:15 2024 -0800\r\n```\r\nThis issue does not occur at commit:\r\n```\r\ncommit f5fd0deb2371d0bae3bef2563f50e005a140fc6d (HEAD)\r\nAuthor: Joseph Huber <[email protected]>\r\nDate: Mon Feb 12 08:14:54 2024 -0600\r\n```", "author": "eve2023", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "ms178", "body": "CC'ing @nathanchance for awareness." }, { "author": "nathanchance", "body": "Caused by 5c9f7682b090124d9a8b69f92d3f7c269dca25fc, which was reverted in bc66e0cf9feb8f3c38fa2e33850b6c6e5477fb21 and forward fixed by 97088b2ab2184ad4bd64f59fba0b92b70468b10d. I can confirm that there is no crash at 5e3c7e3aa48356a62a4b70d5d9d3e4ddd055a390." } ] }
true
null
101337
https://github.com/llvm/llvm-project/issues/101337
crash
1b936e4812ab395328203f65cacd4ffe02bb318e
2024-07-31T14:11:24
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "cd08fadd03904806fa26a1f117879ddae34fbf67", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 7080, 7086 ] ], "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::cost" ], "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 cd08fadd03904806fa26a1f117879ddae34fbf67 Author: Florian Hahn <[email protected]> Date: Mon Aug 12 14:45:43 2024 +0100 [LV] Include chains feeding inductions in cost precomputation. Include chain of ops feeding inductions in cost precomputation for inductions, not just the induction increment. In VPlan, those instructions will be cleaned up, as both phi and increment are generated by VPWidenIntOrFpInductionRecipe independently. Fixes https://github.com/llvm/llvm-project/issues/101337. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 542d74ef0e1e..41e4b0fcd9b0 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7080,7 +7080,16 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, for (const auto &[IV, IndDesc] : Legal->getInductionVars()) { Instruction *IVInc = cast<Instruction>( IV->getIncomingValueForBlock(OrigLoop->getLoopLatch())); - SmallVector<Instruction *> IVInsts = {IV, IVInc}; + SmallVector<Instruction *> IVInsts = {IVInc}; + for (unsigned I = 0; I != IVInsts.size(); I++) { + for (Value *Op : IVInsts[I]->operands()) { + auto *OpI = dyn_cast<Instruction>(Op); + if (Op == IV || !OpI || !OrigLoop->contains(OpI) || !Op->hasOneUse()) + continue; + IVInsts.push_back(OpI); + } + } + IVInsts.push_back(IV); for (User *U : IV->users()) { auto *CI = cast<Instruction>(U); if (!CostCtx.CM.isOptimizableIVTruncate(CI, VF))
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/induction-costs.ll", "commands": [ "opt -p loop-vectorize -mtriple=x86_64-apple-macosx -S %s" ], "tests": [ { "test_name": "iv_and_step_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i16 @iv_and_step_trunc() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %rec = phi i16 [ 0, %entry ], [ %rec.next, %loop ]\n %iv.next = add i64 %iv, 1\n %0 = trunc i64 %iv to i16\n %1 = trunc i64 %iv.next to i16\n %rec.next = mul i16 %0, %1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %rec\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "wombat2", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat2(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc.1, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc.0 = trunc i64 %mul3 to i60\n %trunc.1 = trunc i60 %trunc.0 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "with_dead_use", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @with_dead_use(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n %dead.and = and i32 %trunc, 123\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_scalar_predicated_cost", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @test_scalar_predicated_cost(i64 %x, i64 %y, ptr %A) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %cmp9.not = icmp ule i64 %iv, %y\n br i1 %cmp9.not, label %loop.latch, label %if.then\n\nif.then: ; preds = %loop.header\n %or = or i64 %x, %iv\n %gep = getelementptr i32, ptr %A, i64 %iv\n %t = trunc i64 %or to i32\n store i32 %t, ptr %gep, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %if.then, %loop.header\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 100\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "truncated_ivs_with_wide_and_scalar_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @truncated_ivs_with_wide_and_scalar_uses(i1 %c, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %gep = getelementptr i16, ptr %dst, i32 %iv.32\n %sel = select i1 %c, i16 %iv.16, i16 10\n store i16 %sel, ptr %gep, align 2\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "multiple_truncated_ivs_with_wide_uses", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_truncated_ivs_with_wide_uses(i1 %c, ptr %A, ptr %B) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.16 = trunc i64 %iv to i16\n %iv.32 = trunc i64 %iv to i32\n %sel = select i1 %c, i16 %iv.16, i16 10\n %gep.A = getelementptr i16, ptr %A, i64 %iv\n store i16 %sel, ptr %gep.A, align 2\n %gep.B = getelementptr i32, ptr %B, i64 %iv\n store i32 %iv.32, ptr %gep.B, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 64\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "wide_iv_trunc_reuse", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc_reuse(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.trunc, %loop ]\n store i32 %iv.2, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 0\n %iv.trunc = trunc i64 %iv to i32\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "iv_used_widened_and_truncated", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine i32 @iv_used_widened_and_truncated(ptr %dst, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr { i32, [8 x i32] }, ptr %dst, i64 %iv\n %t = trunc i64 %iv to i32\n store i32 %t, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %c = icmp eq i64 %iv, %N\n br i1 %c, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 0\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "wombat", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wombat(i32 %arg, ptr %dst) #0 {\nentry:\n %mul = mul i32 %arg, 3\n %zext = zext i32 %arg to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 4, %entry ], [ %add, %loop ]\n %phi2 = phi i32 [ %mul, %entry ], [ %trunc, %loop ]\n %getelementptr = getelementptr i32, ptr %dst, i64 %phi\n %and = and i32 %phi2, 12\n store i32 %and, ptr %getelementptr, align 4\n %mul3 = mul i64 %phi, %zext\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %phi, 65\n %trunc = trunc i64 %mul3 to i32\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-cpu\"=\"skylake-avx512\" \"target-features\"=\"-avx512f\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "wide_iv_trunc", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_iv_trunc(ptr %dst, i64 %N) {\nentry:\n %cmp = icmp ult i64 %N, 8\n br i1 %cmp, label %loop, label %exit\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.trunc = trunc i64 %iv to i32\n store i32 %iv.trunc, ptr %dst, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop, %entry\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "multiple_pointer_ivs_with_scalar_uses_only", "test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\n\ndefine void @multiple_pointer_ivs_with_scalar_uses_only(ptr %A, ptr %B) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv.1 = phi i32 [ 100, %entry ], [ %dec, %loop ]\n %iv.2 = phi i32 [ 2048, %entry ], [ %add38, %loop ]\n %ptr.iv.1 = phi ptr [ %A, %entry ], [ %outptr.0, %loop ]\n %ptr.iv.2 = phi ptr [ %B, %entry ], [ %incdec.ptr36, %loop ]\n %ptr.iv.3 = phi ptr [ %B, %entry ], [ %incdec.ptr33, %loop ]\n %incdec.ptr33 = getelementptr i8, ptr %ptr.iv.3, i64 1\n %0 = load i8, ptr %ptr.iv.3, align 1\n %conv34 = zext i8 %0 to i32\n %incdec.ptr36 = getelementptr i8, ptr %ptr.iv.2, i64 1\n %1 = load i8, ptr %ptr.iv.2, align 1\n %conv37 = zext i8 %1 to i32\n %add38 = add i32 %conv34, %conv37\n %shr42 = lshr i32 %iv.2, 1\n %conv43 = trunc i32 %shr42 to i8\n store i8 %conv43, ptr %ptr.iv.1, align 1\n %dec = add i32 %iv.1, 1\n %outptr.0 = getelementptr i8, ptr %ptr.iv.1, i64 2\n %cmp30.not = icmp eq i32 %dec, 0\n br i1 %cmp30.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"skylake-avx512\" }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.", "body": "To reproduce run opt with \r\n```\r\n-passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\r\n```\r\nwith the following test:\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat(i32 %arg) #0 gc \"statepoint-example\" {\r\nbb:\r\n %mul = mul i32 %arg, 3\r\n %zext = zext i32 %arg to i64\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i64 [ %add, %bb1 ], [ 4, %bb ]\r\n %phi2 = phi i32 [ %trunc, %bb1 ], [ %mul, %bb ]\r\n %getelementptr = getelementptr i32, ptr addrspace(1) null, i64 %phi\r\n %and = and i32 %phi2, 0\r\n store i32 0, ptr addrspace(1) %getelementptr, align 4\r\n %mul3 = mul i64 %phi, %zext\r\n %add = add i64 %phi, 1\r\n %icmp = icmp ugt i64 %phi, 65\r\n %trunc = trunc i64 %mul3 to i32\r\n br i1 %icmp, label %bb4, label %bb1\r\n\r\nbb4: ; preds = %bb1\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/nPsP7h51n\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize --mcpu=skylake-avx512 --mattr=+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f <source>\r\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\r\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\r\n #0 0x0000000004f053c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f053c8)\r\n #1 0x0000000004f02b3c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007458cc042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007458cc0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007458cc042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007458cc0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007458cc02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007458cc039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003f83f37 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f83f37)\r\n #9 0x0000000003f86659 llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86659)\r\n#10 0x0000000003f86cd2 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f86cd2)\r\n#11 0x0000000002e596ce llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e596ce)\r\n#12 0x0000000004d02758 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d02758)\r\n#13 0x0000000000de089e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde089e)\r\n#14 0x0000000004d0114e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d0114e)\r\n#15 0x0000000000de0eee llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde0eee)\r\n#16 0x0000000004cff2b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cff2b0)\r\n#17 0x00000000008e3752 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e3752)\r\n#18 0x00000000008d667c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d667c)\r\n#19 0x00007458cc029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#20 0x00007458cc029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#21 0x00000000008cdade _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cdade)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "patrick-rivos", "body": "Potentially related: https://github.com/llvm/llvm-project/issues/100591" } ] }
true
null
126085
https://github.com/llvm/llvm-project/issues/126085
crash
6575154b6eca80097d77db69ce1ee60c72854ee6
2025-02-06T15:41:55
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "eb2b453eb73dfe0b8cf516dfb4d568c0b858d1fa", "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": [ [ 3210, 3216 ] ], "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::foldInsExtVectorToShuffle" ], "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 eb2b453eb73dfe0b8cf516dfb4d568c0b858d1fa Author: Simon Pilgrim <[email protected]> Date: Thu Feb 6 16:40:48 2025 +0000 [VectorCombine] foldInsExtVectorToShuffle - ensure we call getShuffleCost with the input operand type, not the result Typo in #121216 Fixes #126085 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 4f46b621c8a7..746742e14d08 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -3210,7 +3210,7 @@ bool VectorCombine::foldInsExtVectorToShuffle(Instruction &I) { ExtToVecMask[0] = ExtIdx; // Add cost for expanding or narrowing NewCost = TTI.getShuffleCost(TargetTransformInfo::SK_PermuteSingleSrc, - DstVecTy, ExtToVecMask, CostKind); + SrcVecTy, ExtToVecMask, CostKind); NewCost += TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind); }
[ { "file": "llvm/test/Transforms/VectorCombine/X86/pr126085.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64--" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine i32 @test(ptr %a0) {\n;\n %load = load <16 x i8>, ptr %a0, align 1\n %shuf = shufflevector <16 x i8> %load, <16 x i8> poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison>\n %elt = extractelement <16 x i8> %load, i64 11\n %ins = insertelement <4 x i8> %shuf, i8 %elt, i64 1\n %res = bitcast <4 x i8> %ins to i32\n ret i32 %res\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VectorCombine] Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.", "body": "Reproducer:\n```\n; bin/opt -passes=vector-combine reduced.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @test(ptr readonly captures(none) dereferenceable(16) %0) {\n %2 = load <16 x i8>, ptr %0, align 1\n %.sroa.01.2.vec.insert = shufflevector <16 x i8> %2, <16 x i8> poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison>\n %3 = extractelement <16 x i8> %2, i64 11\n %.sroa.01.3.vec.insert = insertelement <4 x i8> %.sroa.01.2.vec.insert, i8 %3, i64 1\n %4 = bitcast <4 x i8> %.sroa.01.3.vec.insert to i32\n ret i32 %4\n}\n```\n```\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/IR/Instructions.cpp:1890: bool isSingleSourceMaskImpl(llvm::ArrayRef<int>, int): Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: bin/opt -passes=vector-combine reduced.ll -S\n1. Running pass \"function(vector-combine)\" on module \"reduced.ll\"\n2. Running pass \"vector-combine\" on function \"test\"\n #0 0x00007f4379a17152 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.21.0git+0x217152)\n #1 0x00007f4379a1403f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.21.0git+0x21403f)\n #2 0x00007f4379a1417c SignalHandler(int) Signals.cpp:0:0\n #3 0x00007f4379442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007f43794969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #5 0x00007f43794969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #6 0x00007f43794969fc pthread_kill ./nptl/pthread_kill.c:89:10\n #7 0x00007f4379442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\n #8 0x00007f43794287f3 abort ./stdlib/abort.c:81:7\n #9 0x00007f437942871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n#10 0x00007f4379439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n#11 0x00007f4370e71a16 isSingleSourceMaskImpl(llvm::ArrayRef<int>, int) Instructions.cpp:0:0\n#12 0x00007f4370e7c3dc llvm::ShuffleVectorInst::isReverseMask(llvm::ArrayRef<int>, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x27c3dc)\n#13 0x00007f43788933f2 llvm::X86TTIImpl::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0x4933f2)\n#14 0x00007f43716ddf0c llvm::TargetTransformInfo::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.21.0git+0x4ddf0c)\n#15 0x00007f437224f6e7 (anonymous namespace)::VectorCombine::foldInsExtVectorToShuffle(llvm::Instruction&) VectorCombine.cpp:0:0\n#16 0x00007f4372256116 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const VectorCombine.cpp:0:0\n#17 0x00007f437225787f llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.21.0git+0x25787f)\n#18 0x00007f4373f225c5 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.21.0git+0x1225c5)\n#19 0x00007f4370f10cad llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x310cad)\n#20 0x00007f43784dc235 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xdc235)\n#21 0x00007f4370f0ee75 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x30ee75)\n#22 0x00007f43784dcbf5 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xdcbf5)\n#23 0x00007f4370f0fb2a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x30fb2a)\n#24 0x00007f4379ba3dc6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.21.0git+0x2fdc6)\n#25 0x00007f4379baf5c2 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.21.0git+0x3b5c2)\n#26 0x00007f4379429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\n#27 0x00007f4379429e40 call_init ./csu/../csu/libc-start.c:128:20\n#28 0x00007f4379429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\n#29 0x00006293bc5a5095 _start (bin/opt+0x1095)\nAborted (core dumped)\n```\n\nTriggered by https://github.com/llvm/llvm-project/pull/121216. cc @ParkHanbum @RKSimon \nReported by https://github.com/dtcxzyw/llvm-opt-benchmark/issues/2093\n\n", "author": "dtcxzyw", "labels": [ "crash-on-valid", "llvm:transforms" ], "comments": [ { "author": "RKSimon", "body": "Found the problem - fix incoming" } ] }
true
null
106417
https://github.com/llvm/llvm-project/issues/106417
crash
66927fb95abef9327b453d7213c5df7d641269be
2024-08-28T16:21:38
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "c4906588ce47de33d59bcd95f3e82ce2c3e61c23", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 7113, 7119 ], [ 7121, 7126 ] ], "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::precomputeCosts" ], "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 c4906588ce47de33d59bcd95f3e82ce2c3e61c23 Author: Florian Hahn <[email protected]> Date: Thu Aug 29 21:19:59 2024 +0100 [VPlan] Use skipCostComputation when pre-computing induction costs. This ensures we skip any instructions identified to be ignored by the legacy cost model as well. Fixes a divergence between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/106417. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4cc75e2e7546..6babfd1eee91 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7113,7 +7113,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, IVInsts.push_back(CI); } for (Instruction *IVInst : IVInsts) { - if (!CostCtx.SkipCostComputation.insert(IVInst).second) + if (CostCtx.skipCostComputation(IVInst, VF.isVector())) continue; InstructionCost InductionCost = CostCtx.getLegacyCost(IVInst, VF); LLVM_DEBUG({ @@ -7121,6 +7121,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, << ": induction instruction " << *IVInst << "\n"; }); Cost += InductionCost; + CostCtx.SkipCostComputation.insert(IVInst); } }
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/induction-costs.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "skip_free_iv_truncate", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @skip_free_iv_truncate(i16 %x, ptr %A) #0 {\nentry:\n %x.i32 = sext i16 %x to i32\n %x.i64 = sext i16 %x to i64\n %invariant.gep = getelementptr i8, ptr %A, i64 -8\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %x.i64, %entry ], [ %iv.next, %loop ]\n %iv.conv = phi i32 [ %x.i32, %entry ], [ %3, %loop ]\n %gep.i64 = getelementptr i64, ptr %A, i64 %iv\n %0 = load i64, ptr %gep.i64, align 8\n %1 = sext i32 %iv.conv to i64\n %gep.conv = getelementptr i64, ptr %invariant.gep, i64 %1\n %2 = load i64, ptr %gep.conv, align 8\n %gep.i16 = getelementptr i16, ptr %A, i64 %iv\n store i16 0, ptr %gep.i16, align 2\n %iv.next = add i64 %iv, 3\n %3 = trunc i64 %iv.next to i32\n %c = icmp slt i64 %iv, 99\n br i1 %c, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl256b\" }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using 190449a5d2a9ddfc2180dce11714a4443f0f29f0\r\n\r\nTestcase:\r\n```c\r\nchar a;\r\nextern short b[][6][6];\r\nshort c;\r\nlong d;\r\nlong *e, *f;\r\nvoid g(char h[][6]) {\r\n for (short i = d + 9; i < 4; i += 3) {\r\n a = ({ f[i]; }) < f[i - 1];\r\n for (int j = c; j; j = ({ h[5][i + 2]; }) ? e[i - 1] : 0)\r\n ;\r\n b[i][i][i] = 0;\r\n }\r\n}\r\n```\r\nhttps://godbolt.org/z/EGdEPbKad\r\n\r\nIR testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @g(i16 %0, i64 %indvars.iv52) #0 {\r\nentry:\r\n %conv146 = sext i16 %0 to i32\r\n %1 = sext i16 %0 to i64\r\n %invariant.gep = getelementptr i8, ptr null, i64 -8\r\n br label %for.body.us\r\n\r\nfor.body.us: ; preds = %for.body.us, %entry\r\n %indvars.iv521 = phi i64 [ %1, %entry ], [ %indvars.iv.next53, %for.body.us ]\r\n %conv149.us = phi i32 [ %conv146, %entry ], [ %5, %for.body.us ]\r\n %arrayidx.us = getelementptr i64, ptr null, i64 %indvars.iv521\r\n %2 = load i64, ptr %arrayidx.us, align 8\r\n %3 = sext i32 %conv149.us to i64\r\n %gep = getelementptr i64, ptr %invariant.gep, i64 %3\r\n %4 = load i64, ptr %gep, align 8\r\n %arrayidx31.us = getelementptr [0 x [6 x [6 x i16]]], ptr null, i64 0, i64 %indvars.iv521, i64 %indvars.iv52, i64 %indvars.iv52\r\n store i16 0, ptr %arrayidx31.us, align 2\r\n %indvars.iv.next53 = add i64 %indvars.iv521, 3\r\n %5 = trunc i64 %indvars.iv.next53 to i32\r\n %cmp.us = icmp slt i64 %indvars.iv521, 0\r\n br i1 %cmp.us, label %for.body.us, label %for.cond.for.cond.cleanup_crit_edge.split.us\r\n\r\nfor.cond.for.cond.cleanup_crit_edge.split.us: ; preds = %for.body.us\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7359: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"g\"\r\n #0 0x0000640a195798f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x30178f0)\r\n #1 0x0000640a19576d0f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3014d0f)\r\n #2 0x0000640a19576e65 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007aac19442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007aac194969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007aac194969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007aac194969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007aac19442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007aac194287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007aac1942871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007aac19439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000640a18546ac9 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe4ac9)\r\n#12 0x0000640a1855cedb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffaedb)\r\n#13 0x0000640a1855fef1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffdef1)\r\n#14 0x0000640a18560567 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffe567)\r\n#15 0x0000640a173c0a96 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5ea96)\r\n#16 0x0000640a19384d4f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e22d4f)\r\n#17 0x0000640a173c3c26 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe61c26)\r\n#18 0x0000640a19383acb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e21acb)\r\n#19 0x0000640a173bfec6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5dec6)\r\n#20 0x0000640a19381b0d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1fb0d)\r\n#21 0x0000640a16be9da6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x687da6)\r\n#22 0x0000640a16bdbb31 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679b31)\r\n#23 0x00007aac19429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007aac19429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007aac19429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x0000640a16bd1ee5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66fee5)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/W3KqbcKrb\r\n\r\nFound via fuzzer\r\nRelated/prior issue: #104714\r\n\r\ncc @fhahn ", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
109835
https://github.com/llvm/llvm-project/issues/109835
crash
79ecb814d0c929a66ad92c7b3e91191f01247ac1
2024-09-24T17:26:42
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "cc01112660499a4db74bc3ee24b6f60b03d88dbd", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 11786, 11792 ], [ 11794, 11799 ] ], "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::getTreeCost" ], "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 cc01112660499a4db74bc3ee24b6f60b03d88dbd Author: Han-Kuan Chen <[email protected]> Date: Tue Oct 1 19:15:58 2024 +0800 [SLP][REVEC] getTypeSizeInBits should apply to scalar type instead of FixedVectorType. (#110610) reference: https://github.com/llvm/llvm-project/issues/109835 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 68bf5c52814f..54a1b99606bc 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -11786,7 +11786,7 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { auto BWIt = MinBWs.find(&Root); if (BWIt != MinBWs.end()) { Type *DstTy = Root.Scalars.front()->getType(); - unsigned OriginalSz = DL->getTypeSizeInBits(DstTy); + unsigned OriginalSz = DL->getTypeSizeInBits(DstTy->getScalarType()); unsigned SrcSz = ReductionBitWidth == 0 ? BWIt->second.first : ReductionBitWidth; if (OriginalSz != SrcSz) { @@ -11794,6 +11794,10 @@ InstructionCost BoUpSLP::getTreeCost(ArrayRef<Value *> VectorizedVals) { if (OriginalSz > SrcSz) Opcode = BWIt->second.second ? Instruction::SExt : Instruction::ZExt; Type *SrcTy = IntegerType::get(DstTy->getContext(), SrcSz); + if (auto *VecTy = dyn_cast<FixedVectorType>(DstTy)) { + assert(SLPReVec && "Only supported by REVEC."); + SrcTy = getWidenedType(SrcTy, VecTy->getNumElements()); + } Cost += TTI->getCastInstrCost(Opcode, DstTy, SrcTy, TTI::CastContextHint::None, TTI::TCK_RecipThroughput);
[ { "file": "llvm/test/Transforms/SLPVectorizer/SystemZ/revec-fix-109835.ll", "commands": [ "opt -mtriple=s390x-unknown-linux -mcpu=z16 -passes=slp-vectorizer -S -slp-revec %s" ], "tests": [ { "test_name": "func_1", "test_body": "@g_3_1_0 = external dso_local global i32, align 4\n@g_7 = external dso_local global [5 x i32], align 4\n\ndefine void @func_1() {\n %.pre = load i32, ptr @g_7, align 4\n %1 = load <4 x i32>, ptr getelementptr inbounds nuw (i8, ptr @g_7, i64 4), align 4\n br label %.loopexit\n\n.loopexit: ; preds = %.loopexit, %0\n %2 = phi i32 [ %op.rdx15, %.loopexit ], [ %.pre, %0 ]\n %3 = phi <4 x i32> [ %71, %.loopexit ], [ %1, %0 ]\n %4 = load volatile i32, ptr @g_3_1_0, align 4\n %5 = load volatile i32, ptr @g_3_1_0, align 4\n %6 = load volatile i32, ptr @g_3_1_0, align 4\n %7 = load volatile i32, ptr @g_3_1_0, align 4\n %8 = load volatile i32, ptr @g_3_1_0, align 4\n %9 = load volatile i32, ptr @g_3_1_0, align 4\n %10 = load volatile i32, ptr @g_3_1_0, align 4\n %11 = load volatile i32, ptr @g_3_1_0, align 4\n %12 = load volatile i32, ptr @g_3_1_0, align 4\n %13 = load volatile i32, ptr @g_3_1_0, align 4\n %14 = load volatile i32, ptr @g_3_1_0, align 4\n %15 = load volatile i32, ptr @g_3_1_0, align 4\n %16 = load volatile i32, ptr @g_3_1_0, align 4\n %17 = load volatile i32, ptr @g_3_1_0, align 4\n %18 = load volatile i32, ptr @g_3_1_0, align 4\n %19 = load volatile i32, ptr @g_3_1_0, align 4\n %20 = insertelement <4 x i32> poison, i32 %4, i32 0\n %21 = insertelement <4 x i32> %20, i32 %9, i32 1\n %22 = insertelement <4 x i32> %21, i32 %14, i32 2\n %23 = insertelement <4 x i32> %22, i32 %19, i32 3\n %24 = icmp eq <4 x i32> %23, zeroinitializer\n %25 = load volatile i32, ptr @g_3_1_0, align 4\n %26 = load volatile i32, ptr @g_3_1_0, align 4\n %27 = load volatile i32, ptr @g_3_1_0, align 4\n %28 = load volatile i32, ptr @g_3_1_0, align 4\n %29 = load volatile i32, ptr @g_3_1_0, align 4\n %.not2.410 = icmp eq i32 %29, 0\n %30 = zext i1 %.not2.410 to i32\n %31 = zext <4 x i1> %24 to <4 x i32>\n %32 = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %31)\n %op.rdx = xor i32 %32, %30\n %op.rdx15 = xor i32 %op.rdx, %2\n %33 = load volatile i32, ptr @g_3_1_0, align 4\n %34 = load volatile i32, ptr @g_3_1_0, align 4\n %35 = load volatile i32, ptr @g_3_1_0, align 4\n %36 = load volatile i32, ptr @g_3_1_0, align 4\n %37 = insertelement <4 x i32> poison, i32 %5, i32 0\n %38 = insertelement <4 x i32> %37, i32 %6, i32 1\n %39 = insertelement <4 x i32> %38, i32 %7, i32 2\n %40 = insertelement <4 x i32> %39, i32 %8, i32 3\n %41 = icmp eq <4 x i32> %40, zeroinitializer\n %42 = zext <4 x i1> %41 to <4 x i32>\n %43 = xor <4 x i32> %3, %42\n %44 = insertelement <4 x i32> poison, i32 %10, i32 0\n %45 = insertelement <4 x i32> %44, i32 %11, i32 1\n %46 = insertelement <4 x i32> %45, i32 %12, i32 2\n %47 = insertelement <4 x i32> %46, i32 %13, i32 3\n %48 = icmp eq <4 x i32> %47, zeroinitializer\n %49 = zext <4 x i1> %48 to <4 x i32>\n %50 = xor <4 x i32> %43, %49\n %51 = insertelement <4 x i32> poison, i32 %15, i32 0\n %52 = insertelement <4 x i32> %51, i32 %16, i32 1\n %53 = insertelement <4 x i32> %52, i32 %17, i32 2\n %54 = insertelement <4 x i32> %53, i32 %18, i32 3\n %55 = icmp eq <4 x i32> %54, zeroinitializer\n %56 = zext <4 x i1> %55 to <4 x i32>\n %57 = xor <4 x i32> %50, %56\n %58 = insertelement <4 x i32> poison, i32 %25, i32 0\n %59 = insertelement <4 x i32> %58, i32 %26, i32 1\n %60 = insertelement <4 x i32> %59, i32 %27, i32 2\n %61 = insertelement <4 x i32> %60, i32 %28, i32 3\n %62 = icmp eq <4 x i32> %61, zeroinitializer\n %63 = zext <4 x i1> %62 to <4 x i32>\n %64 = xor <4 x i32> %57, %63\n %65 = insertelement <4 x i32> poison, i32 %33, i32 0\n %66 = insertelement <4 x i32> %65, i32 %34, i32 1\n %67 = insertelement <4 x i32> %66, i32 %35, i32 2\n %68 = insertelement <4 x i32> %67, i32 %36, i32 3\n %69 = icmp eq <4 x i32> %68, zeroinitializer\n %70 = zext <4 x i1> %69 to <4 x i32>\n %71 = xor <4 x i32> %64, %70\n br label %.loopexit\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLP vectorizer] Assertion fails with slp-revec", "body": "[tc_slp_revec.tar.gz](https://github.com/user-attachments/files/17118250/tc_slp_revec.tar.gz)\r\n\r\nopt -mtriple=systemz-unknown -mcpu=z16 -O3 -o out.ll tc_crash22_aftercreduce.ll -slp-revec\r\n\r\nType.cpp:691: static llvm::FixedVectorType* llvm::FixedVectorType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(\r\nElementType) && \"Element type of a VectorType must \" \"be an integer, floating point, or \" \"pointer type.\"' failed.\r\n\r\n#9 0x000002aa076e014e llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize\r\n\r\n", "author": "JonPsson1", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [ { "author": "HanKuanChen", "body": "The fix is landing." }, { "author": "JonPsson1", "body": "Still failing, but this time I see another assertion:\r\n\r\n[tc_slp_revec.tar.gz](https://github.com/user-attachments/files/17192435/tc_slp_revec.tar.gz)\r\n\r\nopt -mtriple=s390x-unknown-linux -mcpu=z16 -O3 tc_crash38_aftercreduce.ll -o /dev/null -slp-revec\r\n\r\nAssertion `!Dst->isVectorTy()' failed.\r\n14 0x00000000030504c2 llvm::SLPVectorizerPass::vectorizeHorReduction\r\n\r\n" }, { "author": "HanKuanChen", "body": "The fix is landing." } ] }
true
null
105722
https://github.com/llvm/llvm-project/issues/105722
crash
84497c6f4f6c79b0d8c38da666724eed7e9e8db5
2024-08-22T19:30:39
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "533e6bbd0d344a710c491a9eb0ce0ba0852b08cb", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 13, 18 ], [ 173, 178 ] ], "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": 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 533e6bbd0d344a710c491a9eb0ce0ba0852b08cb Author: Florian Hahn <[email protected]> Date: Mon Aug 26 09:15:58 2024 +0100 [VPlan] Simplify live-ins if they are SCEVConstant. The legacy cost model in some parts checks if any of the operands are constants via SCEV. Update VPlan construction to replace live-ins that are constants via SCEV with such constants. This means VPlans (and codegen) reflects what we computing the cost of and removes another case where the legacy and VPlan cost model diverged. Fixes https://github.com/llvm/llvm-project/issues/105722. diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h index 0b27933925d8..0fbdeeddaf4a 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -13,6 +13,7 @@ #include "VPlan.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/IR/IRBuilder.h" namespace llvm { @@ -173,6 +174,11 @@ public: if (auto *R = Ingredient2Recipe.lookup(I)) return R->getVPSingleValue(); } + ScalarEvolution &SE = *PSE.getSE(); + if (!isa<Constant>(V) && SE.isSCEVable(V->getType())) + if (auto *C = dyn_cast<SCEVConstant>(PSE.getSE()->getSCEV(V))) + return Plan.getOrAddLiveIn(C->getValue()); + return Plan.getOrAddLiveIn(V); } };
[ { "file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll", "commands": [ "opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S" ], "tests": [ { "test_name": "cost_assume", "test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i64 @cost_assume(ptr %end, i64 %N) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = phi i64 [ 0, %entry ], [ %1, %loop ]\n %1 = add i64 %0, 1\n %iv.next = add nsw i64 %iv, 1\n %c = icmp ne i64 %N, 0\n tail call void @llvm.assume(i1 %c)\n %gep = getelementptr nusw [9 x i8], ptr null, i64 %iv.next\n %ec = icmp eq ptr %gep, %end\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i64 %1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n", "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": "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": "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_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": "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": "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 }, { "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": "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 } ] } ]
{ "title": "[clang] Assertion failed in Vectorize", "body": "To reproduce, compile it with -O2: clang -O2 example.c\r\n\r\n```c\r\n#include <stdint.h>\r\nint a;\r\nlong b;\r\nstatic int32_t c;\r\nvoid d(int e, int h) {\r\n int f = a = 1;\r\n for (; a <= e; a++)\r\n f *= a;\r\n a = 0;\r\n for (; a < h; a++)\r\n b *= f;\r\n}\r\nlong g() {}\r\nint32_t i() {\r\n for (; g();)\r\n for (c = 3;;)\r\n ;\r\n}\r\nuint16_t j() { d(c + 1, c + 6); }\r\n```\r\n\r\nThe error message is as follows:\r\n\r\n```\r\nllvm/lib/Transforms/Vectorize/LoopVectorize.cpp:9985: bool llvm::LoopVectorizePass::processLoop(llvm::Loop *): Assertion `VF.Width == BestVF && \"VPlan cost model and legacy cost model disagreed\"' failed.\r\n```", "author": "cardigan1008", "labels": [ "vectorizers", "confirmed", "crash" ], "comments": [ { "author": "EugeneZelenko", "body": "See https://godbolt.org/z/jc8qqo8Ta" }, { "author": "shafik", "body": "Looks like a recent regression since it does not crash on trunk: https://godbolt.org/z/sKjdvMq54\r\n\r\nAssertion:\r\n\r\n```console\r\nclang++: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7288: \r\nllvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF():\r\nAssertion `BestFactor.Width == LegacyVF.Width && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n```\r\n\r\nBacktrace: \r\n\r\n```console\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -x c -O2 <source>\r\n1.\t<eof> parser at end of file\r\n2.\tOptimizer\r\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\r\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"j\"\r\n #0 0x0000000003b02648 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b02648)\r\n #1 0x0000000003b0033c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b0033c)\r\n #2 0x0000000003a492b8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x000078485ee42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000078485ee969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #5 0x000078485ee42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #6 0x000078485ee287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #7 0x000078485ee2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #8 0x000078485ee39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #9 0x00000000054df418 llvm::LoopVectorizationPlanner::computeBestVF() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54df418)\r\n#10 0x00000000054fa07a llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54fa07a)\r\n#11 0x00000000054fcd39 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54fcd39)\r\n#12 0x00000000054fd3c3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x54fd3c3)\r\n#13 0x00000000050ac09e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50ac09e)\r\n#14 0x00000000034cac68 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34cac68)\r\n#15 0x00000000010bce6e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10bce6e)\r\n#16 0x00000000034c966e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34c966e)\r\n#17 0x00000000010bc75e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x10bc75e)\r\n#18 0x00000000034c7800 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34c7800)\r\n#19 0x0000000003da8895 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#20 0x0000000003dab9fd clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3dab9fd)\r\n#21 0x00000000044196ac clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44196ac)\r\n#22 0x000000000651f80c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x651f80c)\r\n#23 0x0000000004419b18 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4419b18)\r\n#24 0x00000000046a79f9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46a79f9)\r\n#25 0x000000000462b30e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x462b30e)\r\n#26 0x000000000479104e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x479104e)\r\n#27 0x0000000000ca5b0f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca5b0f)\r\n#28 0x0000000000c9ed5a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#29 0x000000000445d1d9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#30 0x0000000003a49764 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a49764)\r\n#31 0x000000000445d7cf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#32 0x0000000004423365 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4423365)\r\n#33 0x0000000004423dcd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4423dcd)\r\n#34 0x000000000442b9e5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x442b9e5)\r\n#35 0x0000000000ca2f05 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca2f05)\r\n#36 0x0000000000b776e4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb776e4)\r\n#37 0x000078485ee29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#38 0x000078485ee29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#39 0x0000000000c9e80e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc9e80e)\r\nclang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nCompiler returned: 134\r\n```" }, { "author": "cardigan1008", "body": "The crash persists in the above cases even with the applied patches. " }, { "author": "fhahn", "body": "@cardigan1008 I can't reproduce the crash locally with latest main. If it still reproduces on current main for you, could you share the crashing IR, using `-mllvm -print-on-crash -mllvm -print-module-scope`?" }, { "author": "cardigan1008", "body": "@fhahn Apologies for the confusion. I pulled the latest version, and this case is now working. However, I encountered a similar crash with another case that I'm currently fuzzing. I'll open a separate issue as soon as I've finished reducing it." }, { "author": "cardigan1008", "body": "Hi @fhahn , I have submitted another issue with the same crash in #106248 . " } ] }
true
null
106655
https://github.com/llvm/llvm-project/issues/106655
crash
2d5613afec0f4afeeb03cfd4edac556a65ad0eaf
2024-08-30T03:04:59
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "87a988e881ac92e3d87aae01dc632f33c1fb36aa", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13137, 13143 ], [ 13197, 13203 ], [ 13249, 13255 ], [ 13259, 13265 ], [ 13474, 13480 ], [ 13518, 13524 ], [ 13571, 13577 ], [ 13593, 13599 ], [ 13611, 13617 ], [ 13655, 13661 ], [ 13688, 13694 ], [ 13780, 13786 ], [ 13794, 13800 ], [ 13859, 13865 ], [ 13941, 13947 ], [ 14039, 14044 ] ], "llvm/lib/Transforms/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 87a988e881ac92e3d87aae01dc632f33c1fb36aa Author: Alexey Bataev <[email protected]> Date: Fri Aug 30 05:16:57 2024 -0700 [SLP]Fix PR106655: Use FinalShuffle for alternate cast nodes. Need to use FinalShuffle function for all vectorized results to correctly produce vectorized value. Fixes https://github.com/llvm/llvm-project/issues/106655 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index edb2567fa057..345b01b82c6a 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -13137,7 +13137,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { } bool IsReverseOrder = isReverseOrder(E->ReorderIndices); - auto FinalShuffle = [&](Value *V, const TreeEntry *E, VectorType *VecTy) { + auto FinalShuffle = [&](Value *V, const TreeEntry *E) { ShuffleInstructionBuilder ShuffleBuilder(ScalarTy, Builder, *this); if (E->getOpcode() == Instruction::Store && E->State == TreeEntry::Vectorize) { @@ -13197,7 +13197,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { PH->getParent()->getFirstInsertionPt()); Builder.SetCurrentDebugLocation(PH->getDebugLoc()); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; if (PostponedPHIs) @@ -13249,7 +13249,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { if (const TreeEntry *TE = getTreeEntry(V)) V = TE->VectorizedValue; setInsertPointAfterBundle(E); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; return V; } @@ -13259,7 +13259,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *Ptr = LI->getPointerOperand(); LoadInst *V = Builder.CreateAlignedLoad(VecTy, Ptr, LI->getAlign()); Value *NewV = propagateMetadata(V, E->Scalars); - NewV = FinalShuffle(NewV, E, VecTy); + NewV = FinalShuffle(NewV, E); E->VectorizedValue = NewV; return NewV; } @@ -13474,7 +13474,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *V = (VecOpcode != ShuffleOrOp && VecOpcode == Instruction::BitCast) ? InVec : Builder.CreateCast(VecOpcode, InVec, VecTy); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13518,7 +13518,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { propagateIRFlags(V, E->Scalars, VL0); // Do not cast for cmps. VecTy = cast<FixedVectorType>(V->getType()); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13571,7 +13571,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { assert(getNumElements(Cond->getType()) == TrueNumElements && "Cannot vectorize Instruction::Select"); Value *V = Builder.CreateSelect(Cond, True, False); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13593,7 +13593,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { if (auto *I = dyn_cast<Instruction>(V)) V = propagateMetadata(I, E->Scalars); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13611,7 +13611,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { } Value *V = Builder.CreateFreeze(Op); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13655,7 +13655,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { auto *CI = dyn_cast<ConstantInt>(Op); return CI && CI->getValue().countr_one() >= It->second.first; })) { - V = FinalShuffle(I == 0 ? RHS : LHS, E, VecTy); + V = FinalShuffle(I == 0 ? RHS : LHS, E); E->VectorizedValue = V; ++NumVectorInstructions; return V; @@ -13688,7 +13688,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { I->setHasNoUnsignedWrap(/*b=*/false); } - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13780,7 +13780,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { } Value *V = propagateMetadata(NewLI, E->Scalars); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; return V; @@ -13794,7 +13794,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { if (VecValue->getType() != VecTy) VecValue = Builder.CreateIntCast(VecValue, VecTy, GetOperandSignedness(0)); - VecValue = FinalShuffle(VecValue, E, VecTy); + VecValue = FinalShuffle(VecValue, E); Value *Ptr = SI->getPointerOperand(); Instruction *ST; @@ -13859,7 +13859,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { V = propagateMetadata(I, GEPs); } - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -13941,7 +13941,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { Value *V = Builder.CreateCall(CF, OpVecs, OpBundles); propagateIRFlags(V, E->Scalars, VL0); - V = FinalShuffle(V, E, VecTy); + V = FinalShuffle(V, E); E->VectorizedValue = V; ++NumVectorInstructions; @@ -14039,6 +14039,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { "Expected same type as operand."); if (auto *I = dyn_cast<Instruction>(LHS)) LHS = propagateMetadata(I, E->Scalars); + LHS = FinalShuffle(LHS, E); E->VectorizedValue = LHS; ++NumVectorInstructions; return LHS;
[ { "file": "llvm/test/Transforms/SLPVectorizer/resized-alt-shuffle-after-minbw.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-vectorize-hor=false < %s" ], "tests": [ { "test_name": "func", "test_body": "define void @func(i32 %0) {\n %2 = shl i32 %0, 0\n %3 = sext i32 %2 to i64\n %4 = shl i32 0, 0\n %5 = sext i32 %4 to i64\n %6 = or i32 0, 0\n %7 = or i32 0, 0\n %8 = zext i32 %6 to i64\n %9 = zext i32 %7 to i64\n %10 = zext i32 0 to i64\n %11 = zext i32 0 to i64\n %12 = zext i32 0 to i64\n %13 = zext i32 0 to i64\n %14 = zext i32 0 to i64\n %15 = zext i32 0 to i64\n %16 = zext i32 0 to i64\n %17 = zext i32 0 to i64\n %18 = zext i32 0 to i64\n %19 = zext i32 0 to i64\n %20 = zext i32 0 to i64\n %21 = zext i32 0 to i64\n %22 = zext i32 0 to i64\n %23 = zext i32 0 to i64\n %24 = zext i32 0 to i64\n %25 = zext i32 0 to i64\n %26 = zext i32 0 to i64\n %27 = or i64 %3, 0\n %28 = or i64 %3, %8\n %29 = or i64 %3, %9\n %30 = or i64 %3, %10\n %31 = or i64 %3, %11\n %32 = or i64 %3, %12\n %33 = or i64 %3, %13\n %34 = or i64 %3, %14\n %35 = or i64 %3, %15\n %36 = or i64 %3, %16\n %37 = or i64 %3, %17\n %38 = or i64 %3, %18\n %39 = or i64 %3, %19\n %40 = or i64 %3, %20\n %41 = or i64 %3, %21\n %42 = or i64 %3, %22\n %43 = or i64 %3, %23\n %44 = or i64 %3, %24\n %45 = or i64 %3, %25\n %46 = or i64 %3, 0\n %47 = or i64 %3, 0\n %48 = or i64 %3, 0\n %49 = or i64 %3, 0\n %50 = or i64 %3, 0\n %51 = or i64 %3, 0\n %52 = or i64 %3, 0\n %53 = or i64 %3, 0\n %54 = or i64 %3, 0\n %55 = or i64 %3, 0\n %56 = or i64 %3, 0\n %57 = or i64 %3, 0\n %58 = or i64 %3, 0\n %59 = icmp slt i64 %28, 0\n %60 = icmp slt i64 %29, 0\n %61 = icmp slt i64 %30, 0\n %62 = icmp slt i64 %31, 0\n %63 = icmp slt i64 %32, 0\n %64 = icmp slt i64 %33, 0\n %65 = icmp slt i64 %34, 0\n %66 = icmp slt i64 %35, 0\n %67 = icmp slt i64 %36, 0\n %68 = icmp slt i64 %37, 0\n %69 = icmp slt i64 %38, 0\n %70 = icmp slt i64 %39, 0\n %71 = icmp slt i64 %40, 0\n %72 = icmp slt i64 %41, 0\n %73 = icmp slt i64 %42, 0\n %74 = icmp slt i64 %43, 0\n %75 = icmp slt i64 %44, 0\n %76 = icmp slt i64 %45, 0\n %77 = icmp slt i64 %46, 0\n %78 = icmp slt i64 %47, 0\n %79 = icmp slt i64 %48, 0\n %80 = icmp slt i64 %49, 0\n %81 = icmp slt i64 %50, 0\n %82 = icmp slt i64 %51, 0\n %83 = icmp slt i64 %52, 0\n %84 = icmp slt i64 %53, 0\n %85 = icmp slt i64 %54, 0\n %86 = icmp slt i64 %55, 0\n %87 = icmp slt i64 %56, 0\n %88 = icmp slt i64 %57, 0\n %89 = icmp slt i64 %58, 0\n %90 = and i1 false, %59\n %91 = and i1 false, %60\n %92 = and i1 false, %61\n %93 = and i1 false, %62\n %94 = and i1 false, %63\n %95 = and i1 false, %64\n %96 = and i1 false, %65\n %97 = and i1 false, %66\n %98 = and i1 false, %67\n %99 = and i1 false, %68\n %100 = and i1 false, %69\n %101 = and i1 false, %70\n %102 = and i1 false, %71\n %103 = and i1 false, %72\n %104 = and i1 false, %73\n %105 = and i1 false, %74\n %106 = and i1 false, %75\n %107 = and i1 false, %76\n %108 = icmp eq i32 %2, 0\n %109 = and i1 false, %77\n %110 = and i1 false, %78\n %111 = and i1 false, %79\n %112 = and i1 false, %80\n %113 = and i1 false, %81\n %114 = and i1 false, %82\n %115 = and i1 false, %83\n %116 = and i1 false, %84\n %117 = and i1 false, %85\n %118 = and i1 false, %86\n %119 = or i64 %5, %26\n %120 = getelementptr float, ptr addrspace(1) null, i64 %119\n %121 = icmp slt i64 %119, 0\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLP] Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.", "body": "Live link: https://godbolt.org/z/nePMscjGr\r\n\r\nTest case:\r\n\r\n```ll\r\ndefine void @func(i32 %0) {\r\n %2 = shl i32 %0, 0\r\n %3 = sext i32 %2 to i64\r\n %4 = shl i32 0, 0\r\n %5 = sext i32 %4 to i64\r\n %6 = or i32 0, 0\r\n %7 = or i32 0, 0\r\n %8 = zext i32 %6 to i64\r\n %9 = zext i32 %7 to i64\r\n %10 = zext i32 0 to i64\r\n %11 = zext i32 0 to i64\r\n %12 = zext i32 0 to i64\r\n %13 = zext i32 0 to i64\r\n %14 = zext i32 0 to i64\r\n %15 = zext i32 0 to i64\r\n %16 = zext i32 0 to i64\r\n %17 = zext i32 0 to i64\r\n %18 = zext i32 0 to i64\r\n %19 = zext i32 0 to i64\r\n %20 = zext i32 0 to i64\r\n %21 = zext i32 0 to i64\r\n %22 = zext i32 0 to i64\r\n %23 = zext i32 0 to i64\r\n %24 = zext i32 0 to i64\r\n %25 = zext i32 0 to i64\r\n %26 = zext i32 0 to i64\r\n %27 = or i64 %3, 0\r\n %28 = or i64 %3, %8\r\n %29 = or i64 %3, %9\r\n %30 = or i64 %3, %10\r\n %31 = or i64 %3, %11\r\n %32 = or i64 %3, %12\r\n %33 = or i64 %3, %13\r\n %34 = or i64 %3, %14\r\n %35 = or i64 %3, %15\r\n %36 = or i64 %3, %16\r\n %37 = or i64 %3, %17\r\n %38 = or i64 %3, %18\r\n %39 = or i64 %3, %19\r\n %40 = or i64 %3, %20\r\n %41 = or i64 %3, %21\r\n %42 = or i64 %3, %22\r\n %43 = or i64 %3, %23\r\n %44 = or i64 %3, %24\r\n %45 = or i64 %3, %25\r\n %46 = or i64 %3, 0\r\n %47 = or i64 %3, 0\r\n %48 = or i64 %3, 0\r\n %49 = or i64 %3, 0\r\n %50 = or i64 %3, 0\r\n %51 = or i64 %3, 0\r\n %52 = or i64 %3, 0\r\n %53 = or i64 %3, 0\r\n %54 = or i64 %3, 0\r\n %55 = or i64 %3, 0\r\n %56 = or i64 %3, 0\r\n %57 = or i64 %3, 0\r\n %58 = or i64 %3, 0\r\n %59 = icmp slt i64 %28, 0\r\n %60 = icmp slt i64 %29, 0\r\n %61 = icmp slt i64 %30, 0\r\n %62 = icmp slt i64 %31, 0\r\n %63 = icmp slt i64 %32, 0\r\n %64 = icmp slt i64 %33, 0\r\n %65 = icmp slt i64 %34, 0\r\n %66 = icmp slt i64 %35, 0\r\n %67 = icmp slt i64 %36, 0\r\n %68 = icmp slt i64 %37, 0\r\n %69 = icmp slt i64 %38, 0\r\n %70 = icmp slt i64 %39, 0\r\n %71 = icmp slt i64 %40, 0\r\n %72 = icmp slt i64 %41, 0\r\n %73 = icmp slt i64 %42, 0\r\n %74 = icmp slt i64 %43, 0\r\n %75 = icmp slt i64 %44, 0\r\n %76 = icmp slt i64 %45, 0\r\n %77 = icmp slt i64 %46, 0\r\n %78 = icmp slt i64 %47, 0\r\n %79 = icmp slt i64 %48, 0\r\n %80 = icmp slt i64 %49, 0\r\n %81 = icmp slt i64 %50, 0\r\n %82 = icmp slt i64 %51, 0\r\n %83 = icmp slt i64 %52, 0\r\n %84 = icmp slt i64 %53, 0\r\n %85 = icmp slt i64 %54, 0\r\n %86 = icmp slt i64 %55, 0\r\n %87 = icmp slt i64 %56, 0\r\n %88 = icmp slt i64 %57, 0\r\n %89 = icmp slt i64 %58, 0\r\n %90 = and i1 false, %59\r\n %91 = and i1 false, %60\r\n %92 = and i1 false, %61\r\n %93 = and i1 false, %62\r\n %94 = and i1 false, %63\r\n %95 = and i1 false, %64\r\n %96 = and i1 false, %65\r\n %97 = and i1 false, %66\r\n %98 = and i1 false, %67\r\n %99 = and i1 false, %68\r\n %100 = and i1 false, %69\r\n %101 = and i1 false, %70\r\n %102 = and i1 false, %71\r\n %103 = and i1 false, %72\r\n %104 = and i1 false, %73\r\n %105 = and i1 false, %74\r\n %106 = and i1 false, %75\r\n %107 = and i1 false, %76\r\n %108 = icmp eq i32 %2, 0\r\n %109 = and i1 false, %77\r\n %110 = and i1 false, %78\r\n %111 = and i1 false, %79\r\n %112 = and i1 false, %80\r\n %113 = and i1 false, %81\r\n %114 = and i1 false, %82\r\n %115 = and i1 false, %83\r\n %116 = and i1 false, %84\r\n %117 = and i1 false, %85\r\n %118 = and i1 false, %86\r\n %119 = or i64 %5, %26\r\n %120 = getelementptr float, ptr addrspace(1) null, i64 %119\r\n %121 = icmp slt i64 %119, 0\r\n ret void\r\n}\r\n```\r\n\r\nRunning via `opt --passes=slp-vectorizer -slp-vectorize-hor=false`:\r\n\r\n```sh\r\nopt: /root/llvm-project/llvm/lib/IR/Instructions.cpp:1853: bool isSingleSourceMaskImpl(llvm::ArrayRef<int>, int): Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S --passes=slp-vectorizer -slp-vectorize-hor=false <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"func\"\r\n #0 0x0000000004fa4138 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fa4138)\r\n #1 0x0000000004fa18ac SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000073f701e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000073f701e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000073f701e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000073f701e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000073f701e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000073f701e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004d097f6 isSingleSourceMaskImpl(llvm::ArrayRef<int>, int) Instructions.cpp:0:0\r\n #9 0x0000000004d1097a llvm::ShuffleVectorInst::isExtractSubvectorMask(llvm::ArrayRef<int>, int, int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d1097a)\r\n#10 0x000000000400fc53 (anonymous namespace)::BaseShuffleAnalysis::isIdentityMask(llvm::ArrayRef<int>, llvm::FixedVectorType const*, bool) SLPVectorizer.cpp:0:0\r\n#11 0x0000000004043781 (anonymous namespace)::BaseShuffleAnalysis::peekThroughShuffles(llvm::Value*&, llvm::SmallVectorImpl<int>&, bool) SLPVectorizer.cpp:0:0\r\n#12 0x000000000405bd21 llvm::Value* (anonymous namespace)::BaseShuffleAnalysis::createShuffle<llvm::Value*, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder>(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>, llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::ShuffleIRBuilder&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000405c50a llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::createShuffle(llvm::Value*, llvm::Value*, llvm::ArrayRef<int>) (.isra.0) SLPVectorizer.cpp:0:0\r\n#14 0x000000000405ce73 llvm::slpvectorizer::BoUpSLP::ShuffleInstructionBuilder::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x405ce73)\r\n#15 0x000000000405d3d9 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool)::'lambda1'(llvm::Value*, llvm::ArrayRef<int>)::operator()(llvm::Value*, llvm::ArrayRef<int>) const SLPVectorizer.cpp:0:0\r\n#16 0x0000000004095c0a llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4095c0a)\r\n#17 0x0000000004097032 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4097032)\r\n#18 0x0000000004095aa8 llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4095aa8)\r\n#19 0x0000000004097294 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4097294)\r\n#20 0x00000000040b31cc llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b31cc)\r\n#21 0x00000000040b6d45 llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40b6d45)\r\n#22 0x00000000040c3b2a llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40c3b2a)\r\n#23 0x00000000040c78a7 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40c78a7)\r\n#24 0x00000000040cb5d0 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40cb5d0)\r\n#25 0x00000000040d1d49 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#26 0x00000000040d29fb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40d29fb)\r\n...\r\n```\r\n\r\nBisected to f3d2609af3031ddb54030548e86335f295cf49ca / https://github.com/llvm/llvm-project/pull/104144", "author": "rupprecht", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [ { "author": "dklimkin", "body": "Confirmed this resolved the issue. Thanks!" } ] }
true
null
85536
https://github.com/llvm/llvm-project/issues/85536
miscompilation
f84980570d3f85bdf5c9432647c05bae04a735a0
2024-03-16T15:33:21
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "252d01952c087cf0d141f7f281cf60efeb98be41", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 1650, 1655 ] ], "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": [ "foldOperationIntoSelectOperand" ], "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 252d01952c087cf0d141f7f281cf60efeb98be41 Author: Yingwei Zheng <[email protected]> Date: Sun Mar 17 14:15:27 2024 +0800 [InstCombine] Drop UB-implying attrs/metadata after speculating an instruction (#85542) When speculating an instruction in `InstCombinerImpl::FoldOpIntoSelect`, the call may result in undefined behavior. This patch drops all UB-implying attrs/metadata to fix this. Fixes #85536. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index edb046defbc1..5d3e41fb5f29 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1650,6 +1650,7 @@ static Value *foldOperationIntoSelectOperand(Instruction &I, SelectInst *SI, Value *NewOp, InstCombiner &IC) { Instruction *Clone = I.clone(); Clone->replaceUsesOfWith(SI, NewOp); + Clone->dropUBImplyingAttrsAndMetadata(); IC.InsertNewInstBefore(Clone, SI->getIterator()); return Clone; }
[ { "file": "llvm/test/Transforms/InstCombine/intrinsic-select.ll", "commands": [ "opt -passes=instcombine -S < %s" ], "tests": [ { "test_name": "test_drop_noundef", "test_body": "define i8 @test_drop_noundef(i1 %cond, i8 %val) {\nentry:\n %sel = select i1 %cond, i8 -1, i8 %val\n %ret = call noundef i8 @llvm.smin.i8(i8 %sel, i8 0)\n ret i8 %ret\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.smin.i8(i8, i8) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr85536", "test_body": "define i1 @pr85536(i32 %a) {\nentry:\n %cmp1 = icmp ugt i32 %a, 30\n %shl1 = shl nsw i32 -1, %a\n %zext = zext i32 %shl1 to i64\n %shl2 = shl i64 %zext, 48\n %shr = ashr exact i64 %shl2, 48\n %sel = select i1 %cmp1, i64 -1, i64 %shr\n %smin = call noundef i64 @llvm.smin.i64(i64 %sel, i64 0)\n %masked = and i64 %smin, 65535\n %ret = icmp eq i64 %masked, 0\n ret i1 %ret\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.smin.i64(i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "vec_to_scalar_select_vector", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.vector.reduce.add.v2i32(<2 x i32>) #0\n\ndefine i32 @vec_to_scalar_select_vector(<2 x i1> %b) {\n %s = select <2 x i1> %b, <2 x i32> <i32 1, i32 2>, <2 x i32> <i32 3, i32 4>\n %c = call i32 @llvm.vector.reduce.add.v2i32(<2 x i32> %s)\n ret i32 %c\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Miscompile at -O1", "body": "Reduced test case: https://godbolt.org/z/z1a3665hd\r\n```\r\n#include <stdio.h>\r\n#include <stdint.h>\r\nstatic uint16_t\r\n(safe_lshift_func_uint16_t_u_s)(uint16_t left, int right )\r\n{\r\n return\r\n ((((int)right) < 0) || (((int)right) >= 32) || (left > ((65535) >> ((int)right)))) ?\r\n ((left)) :\r\n (left << ((int)right));\r\n}\r\nstatic int16_t\r\n(safe_unary_minus_func_int16_t_s)(int16_t si )\r\n{\r\n return\r\n -si;\r\n}\r\nstatic int32_t\r\n(safe_lshift_func_int32_t_s_u)(int32_t left, unsigned int right )\r\n{\r\n return\r\n ((left < 0) || (((unsigned int)right) >= 32) || (left > ((2147483647) >> ((unsigned int)right)))) ?\r\n ((left)) :\r\n (left << ((unsigned int)right));\r\n}\r\nlong smin(long d, long p) { return d < p ? d : p; }\r\nstruct e { uint32_t f; } static g[] = {1, 36};\r\nint64_t h, i;\r\nuint8_t j(uint64_t m) {\r\n if (safe_lshift_func_uint16_t_u_s(\r\n smin(m, safe_unary_minus_func_int16_t_s(\r\n safe_lshift_func_int32_t_s_u(1, g[1].f))),\r\n 3))\r\n h = 0;\r\n return m;\r\n}\r\nint8_t k() {\r\n j(0);\r\n struct e *l[] = {&g[1], &g[1], &g[1], &g[1], &g[1],\r\n &g[1], &g[1], &g[1], &g[1]};\r\n return i;\r\n}\r\nint main() {\r\n printf(\"%d\\n\", k());\r\n return 0;\r\n}\r\n```\r\n\r\n```\r\n> gcc -O0 -fsanitize=address,undefined -w test.c && ./a.out\r\n0\r\n> clang -O3 -w test.c && ./a.out\r\n; no output\r\n```\r\n\r\nReduced LLVM IR: https://alive2.llvm.org/ce/z/hWuhFG\r\n```\r\n%struct.e = type { i32 }\r\n\r\n@g = internal global [2 x %struct.e] [%struct.e { i32 1 }, %struct.e { i32 36 }], align 4\r\n@h = dso_local local_unnamed_addr global i64 0, align 8\r\n@i = dso_local local_unnamed_addr global i64 0, align 8\r\n\r\ndefine i8 @src() {\r\nentry:\r\n %0 = load i32, ptr getelementptr inbounds ([2 x %struct.e], ptr @g, i64 0, i64 1), align 4\r\n %or.cond.i.i = icmp ult i32 %0, 31\r\n %shl.i.neg.i = shl nsw i32 -1, %0\r\n %.neg.i = zext i32 %shl.i.neg.i to i64\r\n %sext.i = shl i64 %.neg.i, 48\r\n %1 = ashr exact i64 %sext.i, 48\r\n %2 = call i64 @llvm.smin.i64(i64 %1, i64 0)\r\n %3 = and i64 %2, 65535\r\n %tobool.not9.i1 = icmp eq i64 %3, 0\r\n %tobool.not9.i = and i1 %or.cond.i.i, %tobool.not9.i1\r\n br i1 %tobool.not9.i, label %j.exit, label %if.then.i\r\n\r\nif.then.i:\r\n store i64 0, ptr @h, align 8\r\n br label %j.exit\r\n\r\nj.exit:\r\n %4 = load i64, ptr @i, align 8\r\n %conv = trunc i64 %4 to i8\r\n ret i8 %conv\r\n}\r\n\r\n==>\r\n\r\ndefine i8 @tgt() {\r\n ret i8 poison\r\n}\r\n```\r\n\r\nLLVM version: 74d1a40915834cbf0629f8d34a7265734d4d9073\r\n\r\ncc @nikic ", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced IR: https://alive2.llvm.org/ce/z/Gv9zkm\r\n```\r\n@g = internal global [1 x i32] [i32 1], align 4\r\n\r\ndefine i32 @k() {\r\nentry:\r\n %ret = load i32, ptr getelementptr inbounds ([1 x i32], ptr @g, i64 0), align 4\r\n ret i32 %ret\r\n}\r\n\r\n==>\r\ndefine i32 @k() {\r\nentry:\r\n ret i32 1\r\n}\r\n```\r\n" }, { "author": "nikic", "body": "@dtcxzyw That last transform is correct for GlobalOpt, alive2 does not support IPO transforms." }, { "author": "dtcxzyw", "body": "> @dtcxzyw That last transform is correct for GlobalOpt, alive2 does not support IPO transforms.\r\n\r\nOh, sorry about my mistake. I will provide a godbolt link.\r\n\r\n\r\n" }, { "author": "dtcxzyw", "body": "The root cause: https://alive2.llvm.org/ce/z/ThJs3Y\r\n```\r\ndefine i1 @src(i32 %a) {\r\nentry:\r\n %or.cond.i.i = icmp ugt i32 %a, 30\r\n %shl.i.neg.i = shl nsw i32 -1, %a\r\n %.neg.i = zext i32 %shl.i.neg.i to i64\r\n %sext.i = shl i64 %.neg.i, 48\r\n %1 = ashr exact i64 %sext.i, 48\r\n %conv2.i = select i1 %or.cond.i.i, i64 -1, i64 %1\r\n %cond.i8.i = call noundef i64 @llvm.smin.i64(i64 0, i64 %conv2.i)\r\n %2 = and i64 %cond.i8.i, 65535\r\n %tobool.not9.i = icmp eq i64 %2, 0\r\n ret i1 %tobool.not9.i\r\n}\r\n\r\n==> \r\n\r\ndefine i1 @tgt(i32 %a) {\r\nentry:\r\n %or.cond.i.i = icmp ult i32 %a, 31\r\n %shl.i.neg.i = shl nsw i32 -1, %a\r\n %.neg.i = zext i32 %shl.i.neg.i to i64\r\n %sext.i = shl i64 %.neg.i, 48\r\n %0 = ashr exact i64 %sext.i, 48\r\n %1 = call noundef i64 @llvm.smin.i64(i64 %0, i64 0)\r\n %2 = and i64 %1, 65535\r\n %tobool.not9.i1 = icmp eq i64 %2, 0\r\n %tobool.not9.i = and i1 %or.cond.i.i, %tobool.not9.i1\r\n ret i1 %tobool.not9.i\r\n}\r\n```" }, { "author": "dtcxzyw", "body": "We forget to drop the `noundef` attribute for `smin` :(\r\n" }, { "author": "dtcxzyw", "body": "Minimal reproducer: https://alive2.llvm.org/ce/z/aBubZ4\r\n```\r\ndefine i8 @src(i1 %cond, i8 %val) {\r\nentry:\r\n %sel = select i1 %cond, i8 -1, i8 %val\r\n %ret = call noundef i8 @llvm.smin.i8(i8 %sel, i8 0)\r\n ret i8 %ret\r\n}\r\n\r\n==>\r\n\r\ndefine i8 @tgt(i1 %cond, i8 %val) {\r\n %min = call noundef i8 @llvm.smin.i8(i8 %val, i8 0)\r\n %ret = select i1 %cond, i8 -1, i8 %min\r\n ret i8 %ret\r\n}\r\n```\r\n\r\n" }, { "author": "nikic", "body": "@dtcxzyw We're probably missing a call to dropUBImplyingAttrsAndMetadata in FoldOpIntoSelect." } ] }
true
null
87410
https://github.com/llvm/llvm-project/issues/87410
crash
0bbe953aa3289a32cd816647820c8676bb3a61bc
2024-04-02T21:05:28
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "c83698367125703827f1b739393f006c399cb213", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 8233, 8238 ] ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ [ 1513, 1518 ] ], "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": [ [ 1932, 1945 ], [ 1949, 1963 ] ], "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::tryToBlend" ], "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [ "VPBlendRecipe::print" ], "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": [ "VPBlendRecipe", "clone", "getIncomingValue", "getMask", "getNumIncomingValues" ], "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 c83698367125703827f1b739393f006c399cb213 Author: Florian Hahn <[email protected]> Date: Tue Apr 9 11:14:05 2024 +0100 [VPlan] Remove unused first mask op from VPBlendRecipe. (#87770) VPBlendRecipe does not use the first mask operand. Removing it allows VPlan-based DCE to remove unused mask computations. This also fixes #87410, where unused Not VPInstructions are considered having only their first lane demanded, but some of their operands providing a vector value due to other users. Fixes https://github.com/llvm/llvm-project/issues/87410 PR: https://github.com/llvm/llvm-project/pull/87770 diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index fd54faf17ca3..5535cc55e932 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8221,6 +8221,8 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi, // builder. At this point we generate the predication tree. There may be // duplications since this is a simple recursive scan, but future // optimizations will clean it up. + // TODO: At the moment the first mask is always skipped, but it would be + // better to skip the most expensive mask. SmallVector<VPValue *, 2> OperandsWithMask; for (unsigned In = 0; In < NumIncoming; In++) { @@ -8233,6 +8235,8 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi, "Distinct incoming values with one having a full mask"); break; } + if (In == 0) + continue; OperandsWithMask.push_back(EdgeMask); } return new VPBlendRecipe(Phi, OperandsWithMask); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 5f6334b974cf..5dc905a3c407 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1932,14 +1932,12 @@ public: class VPBlendRecipe : public VPSingleDefRecipe { public: /// The blend operation is a User of the incoming values and of their - /// respective masks, ordered [I0, M0, I1, M1, ...]. Note that a single value - /// might be incoming with a full mask for which there is no VPValue. + /// respective masks, ordered [I0, I1, M1, I2, M2, ...]. Note that the first + /// incoming value does not have a mask associated. VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands) : VPSingleDefRecipe(VPDef::VPBlendSC, Operands, Phi, Phi->getDebugLoc()) { - assert(Operands.size() > 0 && - ((Operands.size() == 1) || (Operands.size() % 2 == 0)) && - "Expected either a single incoming value or a positive even number " - "of operands"); + assert((Operands.size() + 1) % 2 == 0 && + "Expected an odd number of operands"); } VPRecipeBase *clone() override { @@ -1949,15 +1947,20 @@ public: VP_CLASSOF_IMPL(VPDef::VPBlendSC) - /// Return the number of incoming values, taking into account that a single + /// Return the number of incoming values, taking into account that the first /// incoming value has no mask. unsigned getNumIncomingValues() const { return (getNumOperands() + 1) / 2; } /// Return incoming value number \p Idx. - VPValue *getIncomingValue(unsigned Idx) const { return getOperand(Idx * 2); } + VPValue *getIncomingValue(unsigned Idx) const { + return Idx == 0 ? getOperand(0) : getOperand(Idx * 2 - 1); + } /// Return mask number \p Idx. - VPValue *getMask(unsigned Idx) const { return getOperand(Idx * 2 + 1); } + VPValue *getMask(unsigned Idx) const { + assert(Idx > 0 && "First index has no mask associated."); + return getOperand(Idx * 2); + } /// Generate the phi/select nodes. void execute(VPTransformState &State) override; diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index 2438e4dae3eb..625319954e9b 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -1513,6 +1513,8 @@ void VPBlendRecipe::print(raw_ostream &O, const Twine &Indent, for (unsigned I = 0, E = getNumIncomingValues(); I < E; ++I) { O << " "; getIncomingValue(I)->printAsOperand(O, SlotTracker); + if (I == 0) + continue; O << "/"; getMask(I)->printAsOperand(O, SlotTracker); }
[ { "file": "llvm/test/Transforms/LoopVectorize/unused-blend-mask-for-first-operand.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s" ], "tests": [ { "test_name": "test_not_first_lane_only_constant", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_not_first_lane_only_constant(ptr %A, ptr noalias %B) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.A = getelementptr inbounds i16, ptr %A, i16 %iv\n br i1 false, label %loop.latch, label %else.1\n\nelse.1: ; preds = %loop.header\n br i1 false, label %then.2, label %else.2\n\nthen.2: ; preds = %else.1\n br label %else.2\n\nelse.2: ; preds = %then.2, %else.1\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %loop.header\n %merge = phi ptr [ %B, %else.2 ], [ poison, %loop.header ]\n %l = load i16, ptr %merge, align 2\n %iv.next = add i16 %iv, 1\n store i16 %l, ptr %gep.A, align 2\n %c.2 = icmp eq i16 %iv.next, 1000\n br i1 %c.2, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_not_first_lane_only_wide_compare", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_not_first_lane_only_wide_compare(ptr %A, ptr noalias %B, i16 %x, i16 %y) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i16 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %gep.A = getelementptr inbounds i16, ptr %A, i16 %iv\n %l.0 = load i16, ptr %gep.A, align 2\n %c.0 = icmp ult i16 %l.0, %x\n br i1 %c.0, label %loop.latch, label %else.1\n\nelse.1: ; preds = %loop.header\n %c.1 = icmp ult i16 %l.0, %y\n br i1 %c.1, label %then.2, label %else.2\n\nthen.2: ; preds = %else.1\n br label %else.2\n\nelse.2: ; preds = %then.2, %else.1\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %loop.header\n %merge = phi ptr [ %B, %else.2 ], [ poison, %loop.header ]\n %l = load i16, ptr %merge, align 2\n %iv.next = add i16 %iv, 1\n store i16 %l, ptr %gep.A, align 2\n %c.2 = icmp eq i16 %iv.next, 1000\n br i1 %c.2, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[LoopVectorize][VPlan] Assertion \"Trying to access a single scalar per part but has multiple scalars per part.\" failed.", "body": "Reduced LLVM IR\r\n```llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main() #0 {\r\nentry:\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %if.end.i, %entry\r\n %q.0139.i = phi i16 [ 0, %entry ], [ %add.i, %if.end.i ]\r\n %idxprom.i = sext i16 0 to i64\r\n br i1 false, label %if.end.i, label %if.then.i\r\n\r\nif.then.i: ; preds = %for.body.i\r\n br i1 false, label %cond.end41.i, label %cond.end41.i\r\n\r\ncond.end41.i: ; preds = %if.then.i, %if.then.i\r\n br label %if.end.i\r\n\r\nif.end.i: ; preds = %cond.end41.i, %for.body.i\r\n %.in.i = phi ptr [ null, %cond.end41.i ], [ poison, %for.body.i ]\r\n %0 = load i16, ptr %.in.i, align 2\r\n %add.i = add i16 %q.0139.i, 1\r\n %tobool.not.i = icmp eq i16 %add.i, 0\r\n br i1 %tobool.not.i, label %m.exit, label %for.body.i\r\n\r\nm.exit: ; preds = %if.end.i\r\n %.lcssa = phi i16 [ %0, %if.end.i ]\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\r\n```\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-2/llvm/llvm/lib/Transforms/Vectorize/VPlan.cpp:249: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt --passes=loop-vectorize reduced.ll\r\n #0 0x00005ed60f56eb60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)\r\n #1 0x00005ed60f56bf6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)\r\n #2 0x00005ed60f56c0c5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f973de42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007f973de969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007f973de969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007f973de969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007f973de42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007f973de287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007f973de2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007f973de39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005ed60e6cbb72 llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ee1b72)\r\n#12 0x00005ed60e6fa9a6 llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f109a6)\r\n#13 0x00005ed60e6fbbdf llvm::VPInstruction::execute(llvm::VPTransformState&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f11bdf)\r\n#14 0x00005ed60e6d74ff llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1eed4ff)\r\n#15 0x00005ed60e6cd9e0 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ee39e0)\r\n#16 0x00005ed60e6d90e6 llvm::VPlan::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1eef0e6)\r\n#17 0x00005ed60e5d76f3 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1ded6f3)\r\n#18 0x00005ed60e5e9718 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dff718)\r\n#19 0x00005ed60e5eb73e llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0173e)\r\n#20 0x00005ed60e5ec88d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0288d)\r\n#21 0x00005ed60d4f3276 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09276)\r\n#22 0x00005ed60f395141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)\r\n#23 0x00005ed60d4eabd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)\r\n#24 0x00005ed60f393e3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)\r\n#25 0x00005ed60d4f2dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)\r\n#26 0x00005ed60f391cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)\r\n#27 0x00005ed60cd6cce5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)\r\n#28 0x00005ed60cd5f316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)\r\n#29 0x00007f973de29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#30 0x00007f973de29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#31 0x00007f973de29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#32 0x00005ed60cd54f95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt\r\n```\r\nGodbolt: https://godbolt.org/z/jYWea8z4q\r\n\r\nFound via fuzzer.", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
107051
https://github.com/llvm/llvm-project/issues/107051
crash
fcb7b390ccd5b4cfc71f13b5e16a846f3f400c10
2024-09-03T06:19:24
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "3bd161e98d89d31696002994771b7761f1c74859", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 1290, 1297 ], [ 6194, 6199 ], [ 6206, 6219 ], [ 6229, 6248 ] ], "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::setVectorizedCallDecision", "collectUniformsAndScalars" ], "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 3bd161e98d89d31696002994771b7761f1c74859 Author: Florian Hahn <[email protected]> Date: Tue Sep 3 21:06:31 2024 +0100 [LV] Honor forced scalars in setVectorizedCallDecision. Similarly to dd94537b4, setVectorizedCallDecision also did not consider ForcedScalars. This lead to VPlans not reflecting the decision by the legacy cost model (cost computation would use scalar cost, VPlan would have VPWidenCallRecipe). To fix this, check if the call has been forced to scalar in setVectorizedCallDecision. Note that this requires moving setVectorizedCallDecision after collectLoopUniforms (which sets ForcedScalars). collectLoopUniforms does not depend on call decisions and can safely be moved. Fixes https://github.com/llvm/llvm-project/issues/107051. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 17050b2b433c..0200525a718d 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1290,8 +1290,8 @@ public: if (VF.isScalar() || Uniforms.contains(VF)) return; setCostBasedWideningDecision(VF); - setVectorizedCallDecision(VF); collectLoopUniforms(VF); + setVectorizedCallDecision(VF); collectLoopScalars(VF); } @@ -6194,6 +6194,7 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { assert(!VF.isScalar() && "Trying to set a vectorization decision for a scalar VF"); + auto ForcedScalar = ForcedScalars.find(VF); for (BasicBlock *BB : TheLoop->blocks()) { // For each instruction in the old loop. for (Instruction &I : *BB) { @@ -6206,14 +6207,37 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { InstructionCost VectorCost = InstructionCost::getInvalid(); InstructionCost IntrinsicCost = InstructionCost::getInvalid(); TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; - Function *ScalarFunc = CI->getCalledFunction(); Type *ScalarRetTy = CI->getType(); SmallVector<Type *, 4> Tys, ScalarTys; - bool MaskRequired = Legal->isMaskRequired(CI); for (auto &ArgOp : CI->args()) ScalarTys.push_back(ArgOp->getType()); + // Estimate cost of scalarized vector call. The source operands are + // assumed to be vectors, so we need to extract individual elements from + // there, execute VF scalar calls, and then gather the result into the + // vector return value. + InstructionCost ScalarCallCost = + TTI.getCallInstrCost(ScalarFunc, ScalarRetTy, ScalarTys, CostKind); + + // Compute costs of unpacking argument values for the scalar calls and + // packing the return values to a vector. + InstructionCost ScalarizationCost = + getScalarizationOverhead(CI, VF, CostKind); + + ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost; + // Honor ForcedScalars decision. + // TODO: For calls, it might still be more profitable to widen. Use + // VPlan-based cost model to compare different options. + if (VF.isVector() && ForcedScalar != ForcedScalars.end() && + ForcedScalar->second.contains(CI)) { + setCallWideningDecision(CI, VF, CM_Scalarize, nullptr, + Intrinsic::not_intrinsic, std::nullopt, + ScalarCost); + continue; + } + + bool MaskRequired = Legal->isMaskRequired(CI); // Compute corresponding vector type for return value and arguments. Type *RetTy = ToVectorTy(ScalarRetTy, VF); for (Type *ScalarTy : ScalarTys) @@ -6229,20 +6253,6 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { continue; } - // Estimate cost of scalarized vector call. The source operands are - // assumed to be vectors, so we need to extract individual elements from - // there, execute VF scalar calls, and then gather the result into the - // vector return value. - InstructionCost ScalarCallCost = - TTI.getCallInstrCost(ScalarFunc, ScalarRetTy, ScalarTys, CostKind); - - // Compute costs of unpacking argument values for the scalar calls and - // packing the return values to a vector. - InstructionCost ScalarizationCost = - getScalarizationOverhead(CI, VF, CostKind); - - ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost; - // Find the cost of vectorizing the call, if we can find a suitable // vector variant of the function. bool UsesMask = false;
[ { "file": "llvm/test/Transforms/LoopVectorize/AArch64/call-costs.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "call_forced_scalar", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @call_forced_scalar(ptr %src.1, ptr %src.2, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = load i32, ptr %src.1, align 4\n %smax = tail call i32 @llvm.smax.i32(i32 %0, i32 0)\n %umin = tail call i32 @llvm.umin.i32(i32 %smax, i32 1)\n %umin.ext = zext i32 %umin to i64\n %gep.src.2 = getelementptr i8, ptr %src.2, i64 %umin.ext\n %1 = load i8, ptr %gep.src.2, align 1\n %l.ext = zext i8 %1 to i32\n %mul = mul i32 3, %l.ext\n store i32 %mul, ptr %dst.1, align 4\n %gep.dst.2 = getelementptr i32, ptr %dst.2, i64 %iv\n store i32 0, ptr %gep.dst.2, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smax.i32(i32, i32) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "call_scalarized", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @call_scalarized(ptr noalias %src, ptr noalias %dst, double %0) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 100, %entry ], [ %iv.next, %loop.latch ]\n %iv.next = add i64 %iv, -1\n %gep.src = getelementptr double, ptr %src, i64 %iv.next\n %l = load double, ptr %gep.src, align 8\n %cmp295 = fcmp ugt double %0, 0.000000e+00\n %cmp299 = fcmp ugt double %l, 0.000000e+00\n %or.cond = or i1 %cmp295, %cmp299\n br i1 %or.cond, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %sqrt = call double @llvm.sqrt.f64(double %l)\n %gep.dst = getelementptr double, ptr %dst, i64 %iv.next\n store double %sqrt, ptr %gep.dst, align 8\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %tobool.not = icmp eq i64 %iv.next, 0\n br i1 %tobool.not, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare double @llvm.sqrt.f64(double) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "fshl_operand_first_order_recurrence", "test_body": "target triple = \"arm64-apple-macosx11.0.0\"\n\ndefine void @fshl_operand_first_order_recurrence(ptr %dst, ptr noalias %src) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %recur = phi i64 [ 0, %entry ], [ %l, %loop ]\n %gep.src = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep.src, align 8\n %or = tail call i64 @llvm.fshl.i64(i64 1, i64 %recur, i64 1)\n %gep.dst = getelementptr inbounds i64, ptr %dst, i64 %iv\n store i64 %or, ptr %gep.dst, align 8\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 100\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.fshl.i64(i64, i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "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": "[clang] Assertion failed in Vectorize", "body": "I compiled this code with -Os and a crash appeared in assertion failure:\r\n\r\n```c\r\n#include <stdint.h>\r\nint32_t *c;\r\nint8_t ****d;\r\nuint64_t g;\r\nint a();\r\nlong b(long, long h, long p3) {\r\n long e;\r\n int f = 0;\r\n if (h) {\r\n e = h;\r\n f = 1;\r\n }\r\n if (e > p3)\r\n f = 2;\r\n switch (f) {\r\n case 1:\r\n e++;\r\n case 2:\r\n e--;\r\n }\r\n if (e < h)\r\n e = h;\r\n return e;\r\n}\r\n\r\nuint8_t div_func_uint8_t_u_u(uint8_t ui1, uint8_t ui2)\r\n{\r\n return (ui1 / ui2);\r\n}\r\n\r\nuint64_t j() {\r\n uint16_t k[8];\r\n int i;\r\n for (i = 0; *c + ****d + (int)g + i < 8; i++)\r\n k[b(0, g, 0)] = 6;\r\n *c = div_func_uint8_t_u_u(k[6], a());\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7369: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/T81adKPY5\r\n\r\n", "author": "cardigan1008", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "patrick-rivos", "body": "Unreduced LLVM IR:\r\n```llvm ir\r\n; ModuleID = '/app/example.c'\r\nsource_filename = \"/app/example.c\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n@c = dso_local local_unnamed_addr global ptr null, align 8\r\n@d = dso_local local_unnamed_addr global ptr null, align 8\r\n@g = dso_local local_unnamed_addr global i64 0, align 8\r\n\r\n; Function Attrs: mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable\r\ndefine dso_local i64 @b(i64 noundef %0, i64 noundef %h, i64 noundef %p3) local_unnamed_addr #0 {\r\nentry:\r\n %tobool.not = icmp ne i64 %h, 0\r\n %spec.select = zext i1 %tobool.not to i32\r\n %cmp = icmp sgt i64 %h, %p3\r\n %f.1 = select i1 %cmp, i32 2, i32 %spec.select\r\n switch i32 %f.1, label %sw.epilog [\r\n i32 1, label %sw.bb\r\n i32 2, label %sw.bb3\r\n ]\r\n\r\nsw.bb: ; preds = %entry\r\n %inc = add nsw i64 %h, 1\r\n br label %sw.bb3\r\n\r\nsw.bb3: ; preds = %entry, %sw.bb\r\n %e.1 = phi i64 [ %h, %entry ], [ %inc, %sw.bb ]\r\n %dec = add nsw i64 %e.1, -1\r\n br label %sw.epilog\r\n\r\nsw.epilog: ; preds = %sw.bb3, %entry\r\n %e.2 = phi i64 [ %h, %entry ], [ %dec, %sw.bb3 ]\r\n %spec.select14 = tail call i64 @llvm.smax.i64(i64 %e.2, i64 %h)\r\n ret i64 %spec.select14\r\n}\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1\r\n\r\n; Function Attrs: mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable\r\ndefine dso_local noundef zeroext i8 @div_func_uint8_t_u_u(i8 noundef zeroext %ui1, i8 noundef zeroext %ui2) local_unnamed_addr #0 {\r\nentry:\r\n %0 = udiv i8 %ui1, %ui2\r\n ret i8 %0\r\n}\r\n\r\n; Function Attrs: nounwind optsize uwtable\r\ndefine dso_local i64 @j() local_unnamed_addr #2 {\r\nentry:\r\n %k = alloca [8 x i16], align 16\r\n call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %k) #5\r\n %0 = load ptr, ptr @c, align 8, !tbaa !6\r\n %1 = load i32, ptr %0, align 4, !tbaa !10\r\n %2 = load ptr, ptr @d, align 8, !tbaa !6\r\n %3 = load ptr, ptr %2, align 8, !tbaa !6\r\n %4 = load ptr, ptr %3, align 8, !tbaa !6\r\n %5 = load ptr, ptr %4, align 8, !tbaa !6\r\n %6 = load i8, ptr %5, align 1, !tbaa !12\r\n %conv = sext i8 %6 to i32\r\n %7 = load i64, ptr @g, align 8, !tbaa !13\r\n %conv1 = trunc i64 %7 to i32\r\n %invariant.op = add i32 %conv, %conv1\r\n %add3.reass12 = add i32 %1, %invariant.op\r\n %cmp13 = icmp slt i32 %add3.reass12, 8\r\n br i1 %cmp13, label %for.body.lr.ph, label %for.end\r\n\r\nfor.body.lr.ph: ; preds = %entry\r\n %tobool.not.i = icmp ne i64 %7, 0\r\n %spec.select.i = zext i1 %tobool.not.i to i32\r\n %cmp.i = icmp sgt i64 %7, 0\r\n %f.1.i = select i1 %cmp.i, i32 2, i32 %spec.select.i\r\n %inc.i = add nsw i64 %7, 1\r\n br label %for.body\r\n\r\nfor.body: ; preds = %for.body.lr.ph, %b.exit\r\n %i.014 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %b.exit ]\r\n switch i32 %f.1.i, label %b.exit [\r\n i32 1, label %sw.bb.i\r\n i32 2, label %sw.bb3.i\r\n ]\r\n\r\nsw.bb.i: ; preds = %for.body\r\n br label %sw.bb3.i\r\n\r\nsw.bb3.i: ; preds = %sw.bb.i, %for.body\r\n %e.1.i = phi i64 [ %7, %for.body ], [ %inc.i, %sw.bb.i ]\r\n %dec.i = add nsw i64 %e.1.i, -1\r\n br label %b.exit\r\n\r\nb.exit: ; preds = %for.body, %sw.bb3.i\r\n %e.2.i = phi i64 [ %7, %for.body ], [ %dec.i, %sw.bb3.i ]\r\n %spec.select14.i = tail call i64 @llvm.smax.i64(i64 %e.2.i, i64 %7)\r\n %arrayidx = getelementptr inbounds [8 x i16], ptr %k, i64 0, i64 %spec.select14.i\r\n store i16 6, ptr %arrayidx, align 2, !tbaa !15\r\n %inc = add nuw nsw i32 %i.014, 1\r\n %add = add i32 %1, %inc\r\n %add3.reass = add i32 %add, %invariant.op\r\n %cmp = icmp slt i32 %add3.reass, 8\r\n br i1 %cmp, label %for.body, label %for.end.loopexit, !llvm.loop !17\r\n\r\nfor.end.loopexit: ; preds = %b.exit\r\n %arrayidx5.phi.trans.insert = getelementptr inbounds i8, ptr %k, i64 12\r\n %.pre = load i16, ptr %arrayidx5.phi.trans.insert, align 4, !tbaa !15\r\n %8 = trunc i16 %.pre to i8\r\n br label %for.end\r\n\r\nfor.end: ; preds = %for.end.loopexit, %entry\r\n %conv6 = phi i8 [ %8, %for.end.loopexit ], [ undef, %entry ]\r\n %call7 = tail call i32 (...) @a() #6\r\n %conv8 = trunc i32 %call7 to i8\r\n %9 = udiv i8 %conv6, %conv8\r\n %conv10 = zext i8 %9 to i32\r\n %10 = load ptr, ptr @c, align 8, !tbaa !6\r\n store i32 %conv10, ptr %10, align 4, !tbaa !10\r\n call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %k) #5\r\n ret i64 undef\r\n}\r\n\r\n; Function Attrs: optsize\r\ndeclare i32 @a(...) local_unnamed_addr #3\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.smax.i64(i64, i64) #4\r\n\r\nattributes #0 = { mustprogress nofree norecurse nosync nounwind optsize willreturn memory(none) uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }\r\nattributes #2 = { nounwind optsize uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #3 = { optsize \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #5 = { nounwind }\r\nattributes #6 = { nounwind optsize }\r\n\r\n!llvm.module.flags = !{!0, !1, !2, !3, !4}\r\n!llvm.ident = !{!5}\r\n\r\n!0 = !{i32 7, !\"Dwarf Version\", i32 4}\r\n!1 = !{i32 1, !\"wchar_size\", i32 4}\r\n!2 = !{i32 8, !\"PIC Level\", i32 2}\r\n!3 = !{i32 7, !\"PIE Level\", i32 2}\r\n!4 = !{i32 7, !\"uwtable\", i32 2}\r\n!5 = !{!\"clang version 20.0.0git (https://github.com/llvm/llvm-project.git b6597f521d8a040f2b9fee54b3f89c380de8e432)\"}\r\n!6 = !{!7, !7, i64 0}\r\n!7 = !{!\"any pointer\", !8, i64 0}\r\n!8 = !{!\"omnipotent char\", !9, i64 0}\r\n!9 = !{!\"Simple C/C++ TBAA\"}\r\n!10 = !{!11, !11, i64 0}\r\n!11 = !{!\"int\", !8, i64 0}\r\n!12 = !{!8, !8, i64 0}\r\n!13 = !{!14, !14, i64 0}\r\n!14 = !{!\"long\", !8, i64 0}\r\n!15 = !{!16, !16, i64 0}\r\n!16 = !{!\"short\", !8, i64 0}\r\n!17 = distinct !{!17, !18}\r\n!18 = !{!\"llvm.loop.mustprogress\"}\r\n```\r\n\r\nhttps://godbolt.org/z/Yo1crEjGG\r\n\r\ncc @fhahn " } ] }
true
null
121428
https://github.com/llvm/llvm-project/issues/121428
miscompilation
b5f21671ef04984bc00770263234dfb94833a274
2025-01-01T09:27:44
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "a37dbc1f51c70d92fd209c2e52a9d794eb15e4e7", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 1225, 1232 ] ], "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": [ "foldSelectCttzCtlz" ], "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 a37dbc1f51c70d92fd209c2e52a9d794eb15e4e7 Author: Yingwei Zheng <[email protected]> Date: Mon Jan 6 00:04:28 2025 +0800 [InstCombine] Drop noundef in `foldSelectCttzCtlz` (#121692) Close https://github.com/llvm/llvm-project/issues/121428 diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index e7a8e947705f..a18b927678ef 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -1225,8 +1225,12 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal, // zext/trunc) have one use (ending at the select), the cttz/ctlz result will // not be used if the input is zero. Relax to 'zero is poison' for that case. if (II->hasOneUse() && SelectArg->hasOneUse() && - !match(II->getArgOperand(1), m_One())) + !match(II->getArgOperand(1), m_One())) { II->setArgOperand(1, ConstantInt::getTrue(II->getContext())); + // noundef attribute on the intrinsic may no longer be valid. + II->dropUBImplyingAttrsAndMetadata(); + IC.addToWorklist(II); + } return nullptr; }
[ { "file": "llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll", "commands": [ "opt -passes=instcombine -S < %s" ], "tests": [ { "test_name": "test_cttz_not_bw_multiuse", "test_body": "define i32 @test_cttz_not_bw_multiuse(i32 %x) {\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %sel = select i1 %cmp, i32 %ct, i32 123\n %res = or i32 %sel, %ct\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_cttz_not_bw", "test_body": "define i32 @test_cttz_not_bw(i32 %x) {\n %ct = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_cttz_not_bw_noundef", "test_body": "define i32 @test_cttz_not_bw_noundef(i32 %x) {\n %ct = tail call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\n ret i32 %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.cttz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `noundef` attribute should be dropped", "body": "Alive2: https://alive2.llvm.org/ce/z/wKsUWK\n```\ndefine i32 @src(i32 noundef %x) {\n %ct = call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)\n %cmp = icmp ne i32 %x, 0\n %res = select i1 %cmp, i32 %ct, i32 123\n ret i32 %res\n}\ndefine i32 @tgt(i32 noundef %x) {\n %ct = call noundef range(i32 0, 33) i32 @llvm.cttz.i32(i32 %x, i1 true)\n %cmp.not = icmp eq i32 %x, 0\n %res = select i1 %cmp.not, i32 123, i32 %ct\n ret i32 %res\n}\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
null
98753
https://github.com/llvm/llvm-project/issues/98753
miscompilation
c30ce8b9d33d1050ead549705702c1472b7a7d3f
2024-07-13T17:35:41
[ "llvm/test/Transforms/InstSimplify" ]
{ "fix_commit": "de29b850f03092195bf21f3a39402adb4ed3c216", "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": [ [ 1975, 1987 ], [ 4300, 4305 ], [ 4347, 4352 ], [ 4467, 4472 ], [ 4606, 4612 ] ], "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": [ "llvm::simplifyWithOpReplaced", "simplifyAndOrWithICmpEq", "simplifySelectWithICmpEq" ], "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 de29b850f03092195bf21f3a39402adb4ed3c216 Author: Nikita Popov <[email protected]> Date: Tue Jul 16 11:40:04 2024 +0200 [InstSimplify] Fix simplifyAndOrWithICmpEq with undef refinement (#98898) The final case in Simplify (where Res == Absorber and the predicate is inverted) is not generally safe when the simplification is a refinement. In particular, we may simplify assuming a specific value for undef, but then chose a different one later. However, it *is* safe to refine poison in this context, unlike in the equivalent select folds. This is the reason why this fold did not use AllowRefinement=false in the first place, and using that option would introduce a lot of test regressions. This patch takes the middle path of disabling undef refinements in particular using the getWithoutUndef() SimplifyQuery option. However, this option doesn't actually work in this case, because the problematic fold is inside constant folding, and we currently don't propagate this option all the way from InstSimplify over ConstantFolding to ConstantFold. Work around this by explicitly checking for undef operands in simplifyWithOpReplaced(). Finally, make sure that places where AllowRefinement=false also use Q.getWithoutUndef(). I don't have a specific test case for this (the original one does not work because we don't simplify selects with constant condition in this mode in the first place) but this seems like the correct thing to do to be conservative. Fixes https://github.com/llvm/llvm-project/issues/98753. diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 242c200f7ef1..3a7ae577bb06 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1975,13 +1975,16 @@ static Value *simplifyAndOrWithICmpEq(unsigned Opcode, Value *Op0, Value *Op1, return nullptr; }; - if (Value *Res = - simplifyWithOpReplaced(Op1, A, B, Q, /* AllowRefinement */ true, - /* DropFlags */ nullptr, MaxRecurse)) + // In the final case (Res == Absorber with inverted predicate), it is safe to + // refine poison during simplification, but not undef. For simplicity always + // disable undef-based folds here. + if (Value *Res = simplifyWithOpReplaced(Op1, A, B, Q.getWithoutUndef(), + /* AllowRefinement */ true, + /* DropFlags */ nullptr, MaxRecurse)) return Simplify(Res); - if (Value *Res = - simplifyWithOpReplaced(Op1, B, A, Q, /* AllowRefinement */ true, - /* DropFlags */ nullptr, MaxRecurse)) + if (Value *Res = simplifyWithOpReplaced(Op1, B, A, Q.getWithoutUndef(), + /* AllowRefinement */ true, + /* DropFlags */ nullptr, MaxRecurse)) return Simplify(Res); return nullptr; @@ -4300,6 +4303,9 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, bool AllowRefinement, SmallVectorImpl<Instruction *> *DropFlags, unsigned MaxRecurse) { + assert((AllowRefinement || !Q.CanUseUndef) && + "If AllowRefinement=false then CanUseUndef=false"); + // Trivial replacement. if (V == Op) return RepOp; @@ -4347,6 +4353,11 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, } else { NewOps.push_back(InstOp); } + + // Bail out if any operand is undef and SimplifyQuery disables undef + // simplification. Constant folding currently doesn't respect this option. + if (isa<UndefValue>(NewOps.back()) && !Q.CanUseUndef) + return nullptr; } if (!AnyReplaced) @@ -4467,6 +4478,11 @@ Value *llvm::simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl<Instruction *> *DropFlags) { + // If refinement is disabled, also disable undef simplifications (which are + // always refinements) in SimplifyQuery. + if (!AllowRefinement) + return ::simplifyWithOpReplaced(V, Op, RepOp, Q.getWithoutUndef(), + AllowRefinement, DropFlags, RecursionLimit); return ::simplifyWithOpReplaced(V, Op, RepOp, Q, AllowRefinement, DropFlags, RecursionLimit); } @@ -4606,7 +4622,7 @@ static Value *simplifySelectWithICmpEq(Value *CmpLHS, Value *CmpRHS, Value *TrueVal, Value *FalseVal, const SimplifyQuery &Q, unsigned MaxRecurse) { - if (simplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, Q, + if (simplifyWithOpReplaced(FalseVal, CmpLHS, CmpRHS, Q.getWithoutUndef(), /* AllowRefinement */ false, /* DropFlags */ nullptr, MaxRecurse) == TrueVal) return FalseVal;
[ { "file": "llvm/test/Transforms/InstSimplify/and-or-implied-cond.ll", "commands": [ "opt -S -passes=instsimplify < %s" ], "tests": [ { "test_name": "and_is_constant", "test_body": "define i1 @and_is_constant(ptr %arg, ptr %arg2) {\n %icmp = icmp eq ptr %arg, %arg2\n %call = call i1 @llvm.is.constant.i1(i1 %icmp)\n %and = and i1 %call, %icmp\n ret i1 %and\n}\n\n; Function Attrs: convergent nocallback nofree nosync nounwind willreturn memory(none)\ndeclare i1 @llvm.is.constant.i1(i1) #0\n\nattributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr98753", "test_body": "define i1 @pr98753(i32 noundef %x, i32 %y) {\n %cmp1 = icmp ne i32 %x, 0\n %sel = select i1 %cmp1, i32 %y, i32 undef\n %cmp2 = icmp sgt i32 %sel, 0\n %and = and i1 %cmp1, %cmp2\n ret i1 %and\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Miscompilation with libstdc++'s std::optional<int> and -O1", "body": "https://godbolt.org/z/KjEreWf57\r\n\r\nWith Clang 18.1 and libstdc++, we get different behavior when compared to Clang 17 in the code below.\r\nEDIT: requires at least -O1.\r\n\r\n```cpp\r\n#include <optional>\r\n#include <iostream>\r\n\r\n// defined in a separate compilation unit\r\nint takeIntRefAndReturn0(int&);\r\n\r\nstd::optional<int> shouldReturnEmptyOptional() {\r\n int v = 5;\r\n if (takeIntRefAndReturn0(v))\r\n return v;\r\n return std::nullopt;\r\n}\r\n\r\nint main() {\r\n auto opt = shouldReturnEmptyOptional();\r\n if (opt && *opt > 0) {\r\n std::cout << \"SHOULD NOT BE PRINTED: *opt = \" << *opt << std::endl;\r\n return 1;\r\n }\r\n std::cout << \"SHOULD BE PRINTED\" << std::endl;\r\n}\r\n```\r\n\r\nWith Clang 17, we get `SHOULD BE PRINTED`, while with with Clang 18.1 we get `SHOULD NOT BE PRINTED: *opt = 5`.\r\n\r\nWith git-bisect, I found that this is caused by https://github.com/llvm/llvm-project/commit/060de415af335fdd82910f409e2be3b8457eaa43.\r\n\r\nAn isomorphic example to reproduce this (https://godbolt.org/z/9PsjY17sT):\r\n```cpp\r\nint takeIntRefReturn0(int &);\r\nvoid assertNotReached(int);\r\n\r\nstatic bool logicalAnd(bool a, bool b) { return a && b; }\r\n\r\nint main() {\r\n int v4;\r\n bool v3;\r\n {\r\n int v1 = 5;\r\n int v2 = takeIntRefReturn0(v1);\r\n v3 = v2 != 0;\r\n if (v3)\r\n v4 = v1;\r\n }\r\n // Move to a function so that && is not short cutted.\r\n // v4 will be undefined if v2 == 0, but v3 is false, so the branch shouldn't be entered.\r\n if (logicalAnd(v3, v4 > 0))\r\n assertNotReached(v4);\r\n\r\n return 0;\r\n}\r\n```\r\nNote in the generated LLVM IR that\r\n```llvm\r\n%6 = icmp sgt i32 %5, 0\r\n%7 = and i1 %3, %6\r\nbr i1 %7, label %8, label %9\r\n``` \r\nwas reduced to only\r\n```llvm\r\n%6 = icmp sgt i32 %5, 0\r\nbr i1 %6, label %7, label %8\r\n```", "author": "cadubentzen", "labels": [ "regression", "miscompilation", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/p4ZGxe\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i1 @src(i32 noundef %x, i32 %y) {\r\n %3 = icmp ne i32 %x, 0\r\n %5 = select i1 %3, i32 %y, i32 undef\r\n %6 = icmp sgt i32 %5, 0\r\n %7 = and i1 %3, %6\r\n br i1 %7, label %if.then, label %if.else\r\n\r\nif.then:\r\n call void @use(i32 noundef %5)\r\n ret i1 true\r\n\r\nif.else:\r\n ret i1 false\r\n}\r\n\r\ndefine i1 @tgt(i32 noundef %x, i32 %y) {\r\n %.not = icmp eq i32 %x, 0\r\n %1 = select i1 %.not, i32 undef, i32 %y\r\n %2 = icmp sgt i32 %1, 0\r\n br i1 %2, label %if.then, label %if.else\r\n\r\nif.then: ; preds = %0\r\n call void @use(i32 noundef %1)\r\n ret i1 true\r\n\r\nif.else: ; preds = %0\r\n ret i1 false\r\n}\r\n\r\ndeclare void @use(i32 %x)\r\n```\r\ncc @nikic" }, { "author": "nikic", "body": "A bit simpler using just instsimplify: https://alive2.llvm.org/ce/z/tnkf6A" }, { "author": "nikic", "body": "I expect the fix here is to perform replacements with `Q.getWithoutUndef()`. But probably not just here, but also in other places using simplifyWithOpReplaced(). (Possibly making it always use that mode.)" }, { "author": "cadubentzen", "body": "Thanks a lot for fixing this so quickly! I wonder if this should be included in 18.1.9?" }, { "author": "nikic", "body": "The LLVM 18 branch is already closed, there will be no further releases." }, { "author": "thesamesam", "body": "I'll add the milestone anyway as it's easier to track for downstream backports then." } ] }
true
null
98435
https://github.com/llvm/llvm-project/issues/98435
miscompilation
0e124537aabea0d18e030226a3ca4c6f494c1322
2024-07-11T06:06:08
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "9304af3927caecdb43d3a9b5d16c6a5b7a6b5594", "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": [ [ 1735, 1751 ] ], "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::SimplifyDemandedVectorElts" ], "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 9304af3927caecdb43d3a9b5d16c6a5b7a6b5594 Author: Jorge Botto <[email protected]> Date: Fri Aug 9 11:52:56 2024 +0100 [InstCombine] Fixing wrong select folding in vectors with undef elements (#102244) This PR fixes https://github.com/llvm/llvm-project/issues/98435. `SimplifyDemandedVectorElts` mishandles the undef by assuming that !isNullValue() means the condition is true. By preventing any value that we're not certain equals 1 or 0, it avoids having to make any particular choice by not demanding bits from a particular branch with potentially picking a wrong value. Proof: https://alive2.llvm.org/ce/z/r8CmEu diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index c494fec84c1e..153d8c238ed4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -1735,17 +1735,12 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V, APInt DemandedLHS(DemandedElts), DemandedRHS(DemandedElts); if (auto *CV = dyn_cast<ConstantVector>(Sel->getCondition())) { for (unsigned i = 0; i < VWidth; i++) { - // isNullValue() always returns false when called on a ConstantExpr. - // Skip constant expressions to avoid propagating incorrect information. Constant *CElt = CV->getAggregateElement(i); - if (isa<ConstantExpr>(CElt)) - continue; - // TODO: If a select condition element is undef, we can demand from - // either side. If one side is known undef, choosing that side would - // propagate undef. + + // isNullValue() always returns false when called on a ConstantExpr. if (CElt->isNullValue()) DemandedLHS.clearBit(i); - else + else if (CElt->isOneValue()) DemandedRHS.clearBit(i); } }
[ { "file": "llvm/test/Transforms/InstCombine/pr98435.ll", "commands": [ "opt -S -passes=instcombine < %s 2>&1" ], "tests": [ { "test_name": "pr98435", "test_body": "define <2 x i1> @pr98435(<2 x i1> %val) {\n %val1 = select <2 x i1> <i1 undef, i1 true>, <2 x i1> splat (i1 true), <2 x i1> %val\n ret <2 x i1> %val1\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Wrong select folding for undef conditions by InstCombine", "body": "https://github.com/llvm/llvm-project/blob/7eae9bb856135136cddc4208a2b1546e9db44c9c/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L3582-L3585\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/Qtu72J\r\n\r\n\r\n```ll\r\n----------------------------------------\r\ndefine <2 x i1> @fun0(<2 x i1> %val0, <2 x i1> %val1) {\r\n#0:\r\n %val2 = select <2 x i1> %val0, <2 x i1> %val0, <2 x i1> %val0\r\n %val3 = select <2 x i1> { undef, 1 }, <2 x i1> { 1, 1 }, <2 x i1> %val2\r\n ret <2 x i1> %val3\r\n}\r\n=>\r\ndefine <2 x i1> @fun0(<2 x i1> %val0, <2 x i1> %val1) {\r\n#0:\r\n ret <2 x i1> { poison, 1 }\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 i1> %val0 = < #x0 (0), #x0 (0) >\r\n<2 x i1> %val1 = < #x0 (0), #x0 (0) >\r\n\r\nSource:\r\n<2 x i1> %val2 = < #x0 (0), #x0 (0) >\r\n<2 x i1> %val3 = < #x0 (0)\t[based on undef value], #x1 (1) >\r\n\r\nTarget:\r\nSource value: < #x0 (0), #x1 (1) >\r\nTarget value: < poison, #x1 (1) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "jf-botto", "body": "Would this issue be to fix InstCombine to not try to optimise it or get InstCombine to pick `<2 x i1> { 1, 1 }` because `undef` let's it pick either values and picking a constant vector is better than picking a variable?" }, { "author": "nikic", "body": "The problematic step seems to be this one: https://alive2.llvm.org/ce/z/C2waWU\r\n\r\nI don't think the quoted code is responsible for this, as it is guarded by `!isa<Constant>(CondVal)`." }, { "author": "jf-botto", "body": "I think the problem is with how `SimplifyDemandedVectorElts` handles the undef: https://github.com/llvm/llvm-project/blob/af80d3a248101d6f5d9d5e229c7899136b8ce0b8/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L1721-L1760" }, { "author": "nikic", "body": "@jf-botto Agree. It assumes that !isNullValue() means \"is true\", which is not the case." } ] }
true
null
109468
https://github.com/llvm/llvm-project/issues/109468
crash
51039101cf32591782ef564a108db71150a3b7c3
2024-09-20T20:22:11
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "a068b974b199b0e7350da2d9506adc7df3995ce3", "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": [ [ 2267, 2272 ], [ 2363, 2368 ] ], "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": [ [ 2709, 2714 ], [ 2787, 2792 ] ], "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": [ "VPWidenLoadEVLRecipe::execute", "VPWidenLoadEVLRecipe::print", "VPWidenStoreEVLRecipe::execute", "VPWidenStoreEVLRecipe::print" ], "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 a068b974b199b0e7350da2d9506adc7df3995ce3 Author: Elvis Wang <[email protected]> Date: Thu Sep 26 07:10:25 2024 +0800 [VPlan] Implement VPWidenLoad/StoreEVLRecipe::computeCost(). (#109644) Currently the EVL recipes transfer the tail masking to the EVL. But in the legacy cost model, the mask exist and will calculate the instruction cost of the mask. To fix the difference between the VPlan-based cost model and the legacy cost model, we always calculate the instruction cost for the mask in the EVL recipes. Note that we should remove the mask cost in the EVL recipes when we don't need to compare to the legacy cost model. This patch also fixes #109468. diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index bbcfaf9e19cd..23a24ce293ef 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -2709,6 +2709,10 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue { /// Generate the wide load or gather. void execute(VPTransformState &State) override; + /// Return the cost of this VPWidenLoadEVLRecipe. + InstructionCost computeCost(ElementCount VF, + VPCostContext &Ctx) const override; + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, @@ -2787,6 +2791,10 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe { /// Generate the wide store or scatter. void execute(VPTransformState &State) override; + /// Return the cost of this VPWidenStoreEVLRecipe. + InstructionCost computeCost(ElementCount VF, + VPCostContext &Ctx) const override; + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index dacba152611c..9a0aefb898e5 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -2267,6 +2267,31 @@ void VPWidenLoadEVLRecipe::execute(VPTransformState &State) { State.set(this, Res); } +InstructionCost VPWidenLoadEVLRecipe::computeCost(ElementCount VF, + VPCostContext &Ctx) const { + if (!Consecutive || IsMasked) + return VPWidenMemoryRecipe::computeCost(VF, Ctx); + + // We need to use the getMaskedMemoryOpCost() instead of getMemoryOpCost() + // here because the EVL recipes using EVL to replace the tail mask. But in the + // legacy model, it will always calculate the cost of mask. + // TODO: Using getMemoryOpCost() instead of getMaskedMemoryOpCost when we + // don't need to compare to the legacy cost model. + Type *Ty = ToVectorTy(getLoadStoreType(&Ingredient), VF); + const Align Alignment = + getLoadStoreAlignment(const_cast<Instruction *>(&Ingredient)); + unsigned AS = + getLoadStoreAddressSpace(const_cast<Instruction *>(&Ingredient)); + TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; + InstructionCost Cost = Ctx.TTI.getMaskedMemoryOpCost( + Ingredient.getOpcode(), Ty, Alignment, AS, CostKind); + if (!Reverse) + return Cost; + + return Cost + Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, + cast<VectorType>(Ty), {}, CostKind, 0); +} + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPWidenLoadEVLRecipe::print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const { @@ -2363,6 +2388,31 @@ void VPWidenStoreEVLRecipe::execute(VPTransformState &State) { State.addMetadata(NewSI, SI); } +InstructionCost VPWidenStoreEVLRecipe::computeCost(ElementCount VF, + VPCostContext &Ctx) const { + if (!Consecutive || IsMasked) + return VPWidenMemoryRecipe::computeCost(VF, Ctx); + + // We need to use the getMaskedMemoryOpCost() instead of getMemoryOpCost() + // here because the EVL recipes using EVL to replace the tail mask. But in the + // legacy model, it will always calculate the cost of mask. + // TODO: Using getMemoryOpCost() instead of getMaskedMemoryOpCost when we + // don't need to compare to the legacy cost model. + Type *Ty = ToVectorTy(getLoadStoreType(&Ingredient), VF); + const Align Alignment = + getLoadStoreAlignment(const_cast<Instruction *>(&Ingredient)); + unsigned AS = + getLoadStoreAddressSpace(const_cast<Instruction *>(&Ingredient)); + TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; + InstructionCost Cost = Ctx.TTI.getMaskedMemoryOpCost( + Ingredient.getOpcode(), Ty, Alignment, AS, CostKind); + if (!Reverse) + return Cost; + + return Cost + Ctx.TTI.getShuffleCost(TargetTransformInfo::SK_Reverse, + cast<VectorType>(Ty), {}, CostKind, 0); +} + #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPWidenStoreEVLRecipe::print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const {
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-uniform-store.ll", "commands": [ "opt < %s --prefer-predicate-over-epilogue=predicate-dont-vectorize --passes=loop-vectorize -mcpu=sifive-p470 -mattr=+v,+f -force-tail-folding-style=data-with-evl -S" ], "tests": [ { "test_name": "lshift_significand", "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 @lshift_significand(i32 %n, ptr nocapture writeonly %dst) {\nentry:\n %cmp1.peel = icmp eq i32 %n, 0\n %spec.select = select i1 %cmp1.peel, i64 2, i64 0\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %spec.select, %entry ], [ %iv.next, %loop ]\n %0 = sub nuw nsw i64 1, %iv\n %arrayidx13 = getelementptr i64, ptr %dst, i64 %0\n store i64 0, ptr %arrayidx13, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 3\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": "[LV][VPlan] Crash due to disagreements on the VPlan cost v.s. legacy cost model", "body": "Given this input:\r\n``` llvm\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 @lshift_significand(i32 %n, ptr %0) {\r\nentry:\r\n br label %for.cond\r\n\r\nfor.cond: ; preds = %for.cond, %entry\r\n %i.0 = phi i32 [ 0, %entry ], [ 2, %for.cond ]\r\n %add = or i32 %n, %i.0\r\n %cmp1 = icmp eq i32 %add, 0\r\n br i1 %cmp1, label %for.cond, label %for.cond7\r\n\r\nfor.cond7: ; preds = %for.body9, %for.cond\r\n %i.1 = phi i32 [ %i.0, %for.cond ], [ %inc15, %for.body9 ]\r\n %cmp8 = icmp ult i32 %i.1, 3\r\n br i1 %cmp8, label %for.body9, label %for.end16\r\n\r\nfor.body9: ; preds = %for.cond7\r\n %sub11 = sub nuw i32 1, %i.1\r\n %idxprom12 = zext i32 %sub11 to i64\r\n %arrayidx13 = getelementptr [3 x i64], ptr %0, i64 0, i64 %idxprom12\r\n store i64 0, ptr %arrayidx13, align 8\r\n %inc15 = add i32 %i.1, 1\r\n br label %for.cond7\r\n\r\nfor.end16: ; preds = %for.cond7\r\n ret void\r\n}\r\n```\r\nAnd this command:\r\n``` bash\r\nopt -mcpu=sifive-p470 -O3 -prefer-predicate-over-epilogue=predicate-dont-vectorize -force-tail-folding-style=data-with-evl input.ll -disable-output\r\n```\r\nWe'll get the following assertion:\r\n```\r\nllvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7386: VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n```\r\n\r\n\r\nPreliminary investigation shows that this is caused by the disagreement on (reverse) widen store's cost. First, this is the trace for VPlan's cost model:\r\n```\r\nLV: Scalar loop costs: 4.\r\nCost of 1 for VF vscale x 1: induction instruction %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\r\nCost of 0 for VF vscale x 1: induction instruction %indvars.iv = phi i64 [ %spec.select, %entry ], [ %indvars.iv.next, %for.body9 ]\r\nCost of 1 for VF vscale x 1: exit condition instruction %exitcond.not = icmp eq i64 %indvars.iv.next, 3\r\nCost of 0 for VF vscale x 1: EMIT vp<%4> = CANONICAL-INDUCTION ir<0>, vp<%12>\r\nCost of 0 for VF vscale x 1: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI vp<%5> = phi ir<0>, vp<%11>\r\nCost of 0 for VF vscale x 1: EMIT vp<%6> = EXPLICIT-VECTOR-LENGTH vp<%5>, vp<%3>\r\nCost of 0 for VF vscale x 1: vp<%7> = DERIVED-IV ir<%spec.select> + vp<%5> * ir<1>\r\nCost of 0 for VF vscale x 1: vp<%8> = SCALAR-STEPS vp<%7>, ir<1>\r\nCost of 1 for VF vscale x 1: CLONE ir<%1> = sub nuw nsw ir<1>, vp<%8>\r\nCost of 0 for VF vscale x 1: CLONE ir<%arrayidx13> = getelementptr ir<%0>, ir<0>, ir<%1>\r\nCost of 0 for VF vscale x 1: vp<%9> = vector-pointer (reverse) ir<%arrayidx13>\r\nCost of 8 for VF vscale x 1: WIDEN vp.store vp<%9>, ir<0>, vp<%6>\r\nCost of 0 for VF vscale x 1: SCALAR-CAST vp<%10> = zext vp<%6> to i64\r\nCost of 0 for VF vscale x 1: EMIT vp<%11> = add vp<%10>, vp<%5>\r\nCost of 0 for VF vscale x 1: EMIT vp<%12> = add vp<%4>, vp<%0>\r\nCost of 0 for VF vscale x 1: EMIT branch-on-count vp<%12>, vp<%1>\r\nCost of 0 for VF vscale x 1: vector loop backedge\r\nCost for VF vscale x 1: 11\r\nCost of 1 for VF vscale x 2: induction instruction %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\r\nCost of 0 for VF vscale x 2: induction instruction %indvars.iv = phi i64 [ %spec.select, %entry ], [ %indvars.iv.next, %for.body9 ]\r\nCost of 1 for VF vscale x 2: exit condition instruction %exitcond.not = icmp eq i64 %indvars.iv.next, 3\r\nCost of 0 for VF vscale x 2: EMIT vp<%4> = CANONICAL-INDUCTION ir<0>, vp<%12>\r\nCost of 0 for VF vscale x 2: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI vp<%5> = phi ir<0>, vp<%11>\r\nCost of 0 for VF vscale x 2: EMIT vp<%6> = EXPLICIT-VECTOR-LENGTH vp<%5>, vp<%3>\r\nCost of 0 for VF vscale x 2: vp<%7> = DERIVED-IV ir<%spec.select> + vp<%5> * ir<1>\r\nCost of 0 for VF vscale x 2: vp<%8> = SCALAR-STEPS vp<%7>, ir<1>\r\nCost of 1 for VF vscale x 2: CLONE ir<%1> = sub nuw nsw ir<1>, vp<%8>\r\nCost of 0 for VF vscale x 2: CLONE ir<%arrayidx13> = getelementptr ir<%0>, ir<0>, ir<%1>\r\nCost of 0 for VF vscale x 2: vp<%9> = vector-pointer (reverse) ir<%arrayidx13>\r\nCost of 14 for VF vscale x 2: WIDEN vp.store vp<%9>, ir<0>, vp<%6>\r\nCost of 0 for VF vscale x 2: SCALAR-CAST vp<%10> = zext vp<%6> to i64\r\nCost of 0 for VF vscale x 2: EMIT vp<%11> = add vp<%10>, vp<%5>\r\nCost of 0 for VF vscale x 2: EMIT vp<%12> = add vp<%4>, vp<%0>\r\nCost of 0 for VF vscale x 2: EMIT branch-on-count vp<%12>, vp<%1>\r\nCost of 0 for VF vscale x 2: vector loop backedge\r\nCost for VF vscale x 2: 17\r\n```\r\nWith VPlan's cost model, we will eventually choose scalar loop, because when VF=vscale x 1, the final cost is `ceil(11 / 2) = 6`; when VF=vscale x 2, the final cost is `ceil(17 / 4) = 5`. Both of them are larger than the scalar cost, 4.\r\n\r\nWhile with the legacy cost model:\r\n```\r\nLV: Found an estimated cost of 0 for VF 1 For instruction: %indvars.iv = phi i64 [ %spec.select, %entry ], [ %indvars.iv.next, %for.body9 ]\r\nLV: Found an estimated cost of 1 for VF 1 For instruction: %1 = sub nuw nsw i64 1, %indvars.iv\r\nLV: Found an estimated cost of 0 for VF 1 For instruction: %arrayidx13 = getelementptr [3 x i64], ptr %0, i64 0, i64 %1\r\nLV: Found an estimated cost of 1 for VF 1 For instruction: store i64 0, ptr %arrayidx13, align 8\r\nLV: Found an estimated cost of 1 for VF 1 For instruction: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\r\nLV: Found an estimated cost of 1 for VF 1 For instruction: %exitcond.not = icmp eq i64 %indvars.iv.next, 3\r\nLV: Found an estimated cost of 0 for VF 1 For instruction: br i1 %exitcond.not, label %for.end16, label %for.body9\r\nLV: Scalar loop costs: 4.\r\nLV: Found an estimated cost of 0 for VF vscale x 1 For instruction: %indvars.iv = phi i64 [ %spec.select, %entry ], [ %indvars.iv.next, %for.body9 ]\r\nLV: Found an estimated cost of 1 for VF vscale x 1 For instruction: %1 = sub nuw nsw i64 1, %indvars.iv\r\nLV: Found an estimated cost of 0 for VF vscale x 1 For instruction: %arrayidx13 = getelementptr [3 x i64], ptr %0, i64 0, i64 %1\r\nLV: Found an estimated cost of 7 for VF vscale x 1 For instruction: store i64 0, ptr %arrayidx13, align 8\r\nLV: Found an estimated cost of 1 for VF vscale x 1 For instruction: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\r\nLV: Found an estimated cost of 1 for VF vscale x 1 For instruction: %exitcond.not = icmp eq i64 %indvars.iv.next, 3\r\nLV: Found an estimated cost of 0 for VF vscale x 1 For instruction: br i1 %exitcond.not, label %for.end16, label %for.body9\r\nLV: Vector loop of width vscale x 1 costs: 5 (assuming a minimum vscale of 2).\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %indvars.iv = phi i64 [ %spec.select, %entry ], [ %indvars.iv.next, %for.body9 ]\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %1 = sub nuw nsw i64 1, %indvars.iv\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %arrayidx13 = getelementptr [3 x i64], ptr %0, i64 0, i64 %1\r\nLV: Found an estimated cost of 13 for VF vscale x 2 For instruction: store i64 0, ptr %arrayidx13, align 8\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %exitcond.not = icmp eq i64 %indvars.iv.next, 3\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %exitcond.not, label %for.end16, label %for.body9\r\nLV: Vector loop of width vscale x 2 costs: 4 (assuming a minimum vscale of 2).\r\nLV: Selecting VF: vscale x 2.\r\n```\r\nWe will eventually choose VF=vscale x 2.\r\n\r\nThe key difference is the cost of `store i64 0, ptr %arrayidx13, align 8` v.s. cost of `WIDEN vp.store vp<%9>, ir<0>, vp<%6>`, where the latter is larger than the former by 1.\r\n\r\nIn both cases (the store instruction in VPlan cost model v.s. legacy cost model) their costs are computed by the base cost of store + the cost of shuffle due to being reverse store. I used debugger to confirm that they used the same shuffle cost, which means that for some reason, VPlan's cost model yield a slightly higher cost for store than that in the legacy cost model.\r\n", "author": "mshockwave", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "ElvisWang123", "body": "It seems that the legacy cost model using `getMaskedMemoryOpCost` to query the instruction cost. But in the VPlan-based cost model using `getMemoryOpCost`. \r\n\r\nIn this case, the mask in the `VPWidenStoreEVLRecipe` is false since it is using the EVL recipe.\r\nThe legacy cost model will not check the tail folding type so it will using `getMaskedMemoryOpCost` instead of `getMemoryOpCost` . And the `MaskedMemoryCost` is slightly smaller than non-mask version." }, { "author": "ElvisWang123", "body": "Open a PR to fix this issue. #109644 \r\n\r\nWe remove the shuffle cost when the value stored by reversed vector is loop invariant." }, { "author": "mshockwave", "body": "CC @fhahn " } ] }
true
null
118850
https://github.com/llvm/llvm-project/issues/118850
crash
9ad22cf0ee9eb686ea9fd76fd9cc41f4c006ccbc
2024-12-05T18:11:28
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "4f7f71b7bccdc38f37b82981e8fa9ceb536a7016", "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": [ [ 168, 174 ] ], "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": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": [ "UnrollState::unrollWidenInductionByUF" ], "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 4f7f71b7bccdc38f37b82981e8fa9ceb536a7016 Author: Florian Hahn <[email protected]> Date: Fri Dec 6 16:28:47 2024 +0000 [VPlan] Compare APInt instead of getSExtValue to fix crash in unroll. getSExtValue assumes the result fits in 64 bits, but this may not be the case for indcutions with wider types. Instead, directly perform the compare on the APInt for the ConstantInt. Fixes https://github.com/llvm/llvm-project/issues/118850. diff --git a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp index f653269713b3..ff6c9295ee20 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp @@ -168,7 +168,7 @@ void UnrollState::unrollWidenInductionByUF( auto *ConstStep = ScalarStep->isLiveIn() ? dyn_cast<ConstantInt>(ScalarStep->getLiveInIRValue()) : nullptr; - if (!ConstStep || ConstStep->getZExtValue() != 1) { + if (!ConstStep || ConstStep->getValue() != 1) { if (TypeInfo.inferScalarType(ScalarStep) != IVTy) { ScalarStep = Builder.createWidenCast(Instruction::Trunc, ScalarStep, IVTy);
[ { "file": "llvm/test/Transforms/LoopVectorize/interleave-with-i65-induction.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s" ], "tests": [ { "test_name": "i65_induction_with_negative_step", "test_body": "define void @i65_induction_with_negative_step(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.i65 = phi i65 [ 0, %entry ], [ %iv.i65.next, %loop ]\n %for = phi i64 [ 0, %entry ], [ %trunc, %loop ]\n %trunc = trunc i65 %iv.i65 to i64\n %gep = getelementptr inbounds i64, ptr %dst, i64 %trunc\n store i64 %for, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %icmp = icmp eq i64 %iv.next, 1000\n %iv.i65.next = add i65 %iv.i65, -1\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' failed.", "body": "To reproduce run the test below with -passes=loop-vectorize\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.ll\"\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-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"aarch64-none-linux-gnu\"\n\ndefine double @wombat() gc \"statepoint-example\" {\nbb:\n br label %bb2\n\nbb1: ; preds = %bb2\n ret double 0.000000e+00\n\nbb2: ; preds = %bb2, %bb\n %phi = phi i64 [ 0, %bb ], [ %add, %bb2 ]\n %phi3 = phi i65 [ 0, %bb ], [ %add5, %bb2 ]\n %phi4 = phi i64 [ 0, %bb ], [ %trunc, %bb2 ]\n %trunc = trunc i65 %phi3 to i64\n store i64 0, ptr addrspace(1) null, align 8\n %add = add i64 %phi, 1\n %icmp = icmp ugt i64 %add, 0\n %add5 = add i65 %phi3, -1\n br i1 %icmp, label %bb2, label %bb1\n}\n```\nReproducer: https://godbolt.org/z/cjEcv8b4Y\n\nStack dump:\n```\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize <source>\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\n #0 0x00000000051b3748 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51b3748)\n #1 0x00000000051b113c SignalHandler(int) Signals.cpp:0:0\n #2 0x000071a06ec42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000071a06ec969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000071a06ec42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000071a06ec287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000071a06ec2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000071a06ec39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x0000000000b2d8a9 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xb2d8a9)\n #9 0x0000000004308ae6 (anonymous namespace)::UnrollState::unrollBlock(llvm::VPBlockBase*) VPlanUnroll.cpp:0:0\n#10 0x000000000430788c (anonymous namespace)::UnrollState::unrollBlock(llvm::VPBlockBase*) VPlanUnroll.cpp:0:0\n#11 0x0000000004309060 llvm::VPlanTransforms::unrollByUF(llvm::VPlan&, unsigned int, llvm::LLVMContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4309060)\n#12 0x0000000004176b76 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+0x4176b76)\n#13 0x000000000418cb6f llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x418cb6f)\n#14 0x000000000418ebd9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x418ebd9)\n#15 0x000000000418f213 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x418f213)\n#16 0x0000000002fcba8e 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+0x2fcba8e)\n#17 0x0000000004fb2700 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb2700)\n#18 0x0000000000e33a9e 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+0xe33a9e)\n#19 0x0000000004fb101b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb101b)\n#20 0x0000000000e3312e 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+0xe3312e)\n#21 0x0000000004fb0a20 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4fb0a20)\n#22 0x0000000000910a1a 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+0x910a1a)\n#23 0x0000000000903099 optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x903099)\n#24 0x000071a06ec29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#25 0x000071a06ec29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#26 0x00000000008fa97e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fa97e)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n", "author": "TatyanaDoubts", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "huang-me", "body": "Hi @TatyanaDoubts, \nHow did you get the IR snippet? \nThe IR you provided is weird. I'll have to check where i65 constant 0 in `%phi3 = phi i65 [ 0, %bb ], [ %add5, %bb2 ]` come from since it seems it's the origin of the problem." }, { "author": "fhahn", "body": "I suspect this was found via a fuzzer, thanks for sharing the test case!" }, { "author": "TatyanaDoubts", "body": "Hi @huang-me, @fhahn, yes this crash was found by the fuzzer generated test. " } ] }
true
null
115149
https://github.com/llvm/llvm-project/issues/115149
miscompilation
0f44d72e0ee74970cf696ff4c791f63e0c3fa9b4
2024-11-06T11:22:14
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "929cbe7f596733f85cd274485acc19442dd34a80", "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": [ [ 545, 551 ] ], "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": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": [ "InstCombinerImpl::foldPHIArgGEPIntoPHI" ], "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 929cbe7f596733f85cd274485acc19442dd34a80 Author: Antonio Frighetto <[email protected]> Date: Tue Nov 12 19:02:04 2024 +0100 [InstCombine] Intersect nowrap flags between geps while folding into phi A miscompilation issue has been addressed with refined checking. Fixes: https://github.com/llvm/llvm-project/issues/115149. diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp index cb5c44730512..1fcf1c570add 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -545,7 +545,8 @@ Instruction *InstCombinerImpl::foldPHIArgGEPIntoPHI(PHINode &PN) { // especially bad when the PHIs are in the header of a loop. bool NeededPhi = false; - GEPNoWrapFlags NW = GEPNoWrapFlags::all(); + // Remember flags of the first phi-operand getelementptr. + GEPNoWrapFlags NW = FirstInst->getNoWrapFlags(); // Scan to see if all operands are the same opcode, and all have one user. for (Value *V : drop_begin(PN.incoming_values())) {
[ { "file": "llvm/test/Transforms/InstCombine/opaque-ptr.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "phi_of_gep_flags_1", "test_body": "define ptr @phi_of_gep_flags_1(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr nusw nuw i32, ptr %p, i64 1\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n ret ptr %phi\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/phi.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "wrong_gep_arg_into_phi", "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 i64 @wrong_gep_arg_into_phi(ptr noundef %ptr) {\nentry:\n %add.ptr = getelementptr i8, ptr %ptr, i64 1\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %entry\n %.pn = phi ptr [ %add.ptr, %entry ], [ %incdec.ptr, %for.cond ]\n %val = load i8, ptr %.pn, align 1\n %cond = icmp ne i8 %val, 0\n %incdec.ptr = getelementptr inbounds nuw i8, ptr %.pn, i64 1\n br i1 %cond, label %for.cond, label %exit\n\nexit: ; preds = %for.cond\n ret i64 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[clang] Miscompile with -O3 and -O0/1/2 since 18.1.0", "body": "When I compiled this code with -O0/1/2, its output is 0. However, with -O3, it returned 143:\r\n\r\n```c\r\nint printf(const char *, ...);\r\nchar a, b;\r\nint c;\r\nchar *e = &b;\r\nint f(char *g, int *k) {\r\n char *d = g + *k;\r\n for (; *d && *d <= ' '; d++)\r\n ;\r\n if (*d)\r\n return 0;\r\n return 1;\r\n}\r\nint l(int g) {\r\n char h[] = {a, a, a};\r\n int i[] = {g};\r\n int j = f(h, i);\r\n return j;\r\n}\r\nlong m() {\r\n *e = 255;\r\n for (; l(b + 1);)\r\n return 0;\r\n for (;;)\r\n ;\r\n}\r\nint main() {\r\n m();\r\n printf(\"%d\\n\", c);\r\n}\r\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/dnvvTPror", "author": "cardigan1008", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [ { "author": "antoniofrighetto", "body": "This looks like a nasty one. Getting the optimized IR via -O3 and setting noinline/optnone to main, we get: https://llvm.godbolt.org/z/vaPvs6d16. \r\n\r\nThis is the initial assembly output with -O1 (which leads to the infinite loop):\r\n\r\n```asm\r\nmain: # @main\r\n push rax\r\n mov rax, qword ptr [e]\r\n mov byte ptr [rax], -1\r\n movsx rax, byte ptr [b]\r\n mov cl, byte ptr [a]\r\n mov byte ptr [rsp + 6], cl\r\n mov byte ptr [rsp + 7], cl\r\n lea rdx, [rsp + 5]\r\n add rdx, rax\r\n mov rax, rdx\r\n.LBB0_1: # %for.cond.i.i.i\r\n add rax, 1\r\n mov cl, byte ptr [rdx + 1]\r\n ...\r\n```\r\nWhereas this is with -O0 (returns 0):\r\n```asm\r\nmain: # @main\r\n sub rsp, 24\r\n mov rax, qword ptr [e]\r\n mov byte ptr [rax], -1\r\n movsx rcx, byte ptr [b]\r\n mov al, byte ptr [a]\r\n mov byte ptr [rsp + 22], al\r\n mov byte ptr [rsp + 23], al\r\n lea rax, [rsp + 21]\r\n add rax, rcx\r\n mov qword ptr [rsp + 8], rax # 8-byte Spill\r\n.LBB0_1: # %for.cond.i.i.i\r\n mov rcx, qword ptr [rsp + 8] # 8-byte Reload\r\n mov rax, rcx\r\n add rax, 1\r\n mov dl, byte ptr [rcx + 1]\r\n```\r\nIn the optimized one, $rdx is set to point to $rsp+0x5, part of the stack slot containing $rax (undef), later dereferenced to set the condition leading to the loop. Initially I thought some bug in regalloc, but to me it seems more something in prologepiloginserter. Function prologue / epilogue seems set up correctly with triple arm64-apple-macosx." }, { "author": "antoniofrighetto", "body": "Looking at the IR better, it seems like InstCombine performs a wrong optimization immediately after inlining `l` into `m`, probably related with default argument conversion done by operator + (which should include integer promotion on types smaller than integer). Alive2 seems to confirm it: https://alive2.llvm.org/ce/z/XAzrip." }, { "author": "antoniofrighetto", "body": "Reduced to:\r\n```llvm\r\n@a = global i8 0, align 1\r\n\r\ndefine i64 @src(i8 noundef %arg) {\r\nentry:\r\n %h.i = alloca [3 x i8], align 1\r\n %conv = sext i8 %arg to i32\r\n %add = add nsw i32 %conv, 1\r\n %2 = load i8, ptr @a, align 1\r\n store i8 %2, ptr %h.i, align 1\r\n %idx.ext.i.i = sext i32 %add to i64\r\n %add.ptr.i.i = getelementptr inbounds i8, ptr %h.i, i64 %idx.ext.i.i\r\n br label %for.cond.i.i\r\n\r\nfor.cond.i.i: ; preds = %for.cond.i.i, %entry\r\n %d.0.i.i = phi ptr [ %add.ptr.i.i, %entry ], [ %incdec.ptr.i.i, %for.cond.i.i ]\r\n %3 = load i8, ptr %d.0.i.i, align 1\r\n %tobool.not.i.i = icmp ne i8 %3, 0\r\n %incdec.ptr.i.i = getelementptr inbounds nuw i8, ptr %d.0.i.i, i64 1\r\n br i1 %tobool.not.i.i, label %for.cond.i.i, label %l.exit\r\n\r\nl.exit: ; preds = %for.cond.i.i\r\n ret i64 0\r\n}\r\n```\r\nWrong sext of add of sext simplified to sext leads to wrong gep offset: https://alive2.llvm.org/ce/z/JaR4j9." }, { "author": "AZero13", "body": "Can we backport this to 19.x?" }, { "author": "antoniofrighetto", "body": "Should be fixed in 929cbe7f596733f85cd274485acc19442dd34a80, thanks for reporting!" }, { "author": "AZero13", "body": "@antoniofrighetto can we please backport this " } ] }
true
null
121432
https://github.com/llvm/llvm-project/issues/121432
miscompilation
b51a082e1afd707f8cf1473e4c49374e7e951d2d
2025-01-01T11:07:27
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "c05599966cd594c15834378f57669719d221c4d4", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 2673, 2680 ] ], "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 c05599966cd594c15834378f57669719d221c4d4 Author: Yingwei Zheng <[email protected]> Date: Mon Jan 6 16:23:46 2025 +0800 [InstCombine] Fix FMF propagation in `copysign Mag, (copysign ?, X) -> copysign Mag, X` (#121574) Closes https://github.com/llvm/llvm-project/issues/121432. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index cdb2c11ef046..5494c70b34b1 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2673,8 +2673,12 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { // Propagate sign argument through nested calls: // copysign Mag, (copysign ?, X) --> copysign Mag, X Value *X; - if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) - return replaceOperand(*II, 1, X); + if (match(Sign, m_Intrinsic<Intrinsic::copysign>(m_Value(), m_Value(X)))) { + Value *CopySign = Builder.CreateCopySign( + Mag, X, + II->getFastMathFlags() & cast<Instruction>(Sign)->getFastMathFlags()); + return replaceInstUsesWith(*II, CopySign); + } // Clear sign-bit of constant magnitude: // copysign -MagC, X --> copysign MagC, X
[ { "file": "llvm/test/Transforms/InstCombine/copysign.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "copysign_sign_arg_mixed", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @copysign_sign_arg_mixed(float %x, float %y, float %z) {\n %s = call ninf nsz float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan nsz float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "copysign_sign_arg", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @copysign_sign_arg(float %x, float %y, float %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call ninf float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "fneg_mag", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @fneg_mag(float %x, float %y) {\n %n = fneg float %x\n %r = call float @llvm.copysign.f32(float %n, float %y)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "copysign_sign_arg_nnan", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\ndefine float @copysign_sign_arg_nnan(float %x, float %y, float %z) {\n %s = call nnan float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "not_known_positive_sign_arg", "test_body": "; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.copysign.f32(float, float) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare float @llvm.maxnum.f32(float, float) #0\n\ndefine float @not_known_positive_sign_arg(float %x, float %y) {\n %max = call float @llvm.maxnum.f32(float %x, float 0.000000e+00)\n %r = call ninf float @llvm.copysign.f32(float %y, float %max)\n ret float %r\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] FMF flags should not be propagated", "body": "Alive2: https://alive2.llvm.org/ce/z/ajCxTh\n```\ndefine float @src1(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call nnan float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt1(float noundef %x, float noundef %y, float noundef %z) {\n %r = call nnan float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n\ndefine float @src2(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call ninf float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt2(float noundef %x, float noundef %y, float noundef %z) {\n %r = call ninf float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n\ndefine float @src3(float noundef %x, float noundef %y, float noundef %z) {\n %s = call float @llvm.copysign.f32(float %y, float %z)\n %r = call nsz float @llvm.copysign.f32(float %x, float %s)\n ret float %r\n}\n\ndefine float @tgt3(float noundef %x, float noundef %y, float noundef %z) {\n %r = call nsz float @llvm.copysign.f32(float %x, float %z)\n ret float %r\n}\n```\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine", "floating-point" ], "comments": [] }
true
null
97452
https://github.com/llvm/llvm-project/issues/97452
crash
5c204b1d2619cbad7b7ad228b62feae08781a6db
2024-07-02T17:49:01
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "2b3b405b09a0d965a4aff1f92958418ddbf1e7f6", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 6813, 6818 ] ], "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 2b3b405b09a0d965a4aff1f92958418ddbf1e7f6 Author: Florian Hahn <[email protected]> Date: Thu Jul 4 11:44:50 2024 +0100 [LV] Don't vectorize first-order recurrence with VF <vscale x 1 x ..> The assertion added as part of https://github.com/llvm/llvm-project/pull/93395 surfaced cases where first-order recurrences are vectorized with <vscale x 1 x ..>. If vscale is 1, then we are unable to extract the penultimate value (second to last lane). Previously this case got mis-compiled, trying to extract from an invalid lane (-1) https://llvm.godbolt.org/z/3adzYYcf9. Fixes https://github.com/llvm/llvm-project/issues/97452. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f9c0c66e6e0a..d7b0240fd8a8 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6813,6 +6813,11 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I, ElementCount VF, // First-order recurrences are replaced by vector shuffles inside the loop. if (VF.isVector() && Legal->isFixedOrderRecurrence(Phi)) { + // For <vscale x 1 x i64>, if vscale = 1 we are unable to extract the + // penultimate value of the recurrence. + // TODO: Consider vscale_range info. + if (VF.isScalable() && VF.getKnownMinValue() == 1) + return InstructionCost::getInvalid(); SmallVector<int> Mask(VF.getKnownMinValue()); std::iota(Mask.begin(), Mask.end(), VF.getKnownMinValue() - 1); return TTI.getShuffleCost(TargetTransformInfo::SK_Splice,
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/first-order-recurrence-scalable-vf1.ll", "commands": [ "opt -p loop-vectorize -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n; Make sure we do not pick <vscale x 1 x i64> as VF for a loop with a\n; first-order recurrence.\ndefine i64 @pr97452_scalable_vf1_for(ptr %src) #0 {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i64 [ 0, %entry ], [ %l, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep, align 8\n %ec = icmp eq i64 %iv, 22\n br i1 %ec, label %exit, label %loop\n\nexit:\n %res = phi i64 [ %for, %loop ]\n ret i64 %res\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl128b,+zvl256b\" }\n;.\n;.", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-scalable-vf1.ll", "commands": [ "opt -p loop-vectorize -scalable-vectorization=on -force-vector-width=1 -force-target-supports-scalable-vectors=true -S %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n\ndefine i64 @pr97452_scalable_vf1_for_live_out(ptr %src) {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i64 [ 0, %entry ], [ %l, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep, align 8\n %ec = icmp eq i64 %iv, 22\n br i1 %ec, label %exit, label %loop\n\nexit:\n %res = phi i64 [ %for, %loop ]\n ret i64 %res\n}\n\n\ndefine void @pr97452_scalable_vf1_for_no_live_out(ptr %src, ptr noalias %dst) {\n;\nentry:\n br label %loop\n\nloop:\n %for = phi i64 [ 0, %entry ], [ %l, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, 1\n %gep = getelementptr inbounds i64, ptr %src, i64 %iv\n %l = load i64, ptr %gep, align 8\n %gep.dst = getelementptr inbounds i64, ptr %dst, i64 %iv\n store i64 %l, ptr %gep.dst\n %ec = icmp eq i64 %iv, 22\n br i1 %ec, label %exit, label %loop\n\nexit:\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[LoopVectorize] Assertion `Offset <= State.VF.getKnownMinValue() && \"invalid offset to extract from\"' failed.", "body": "Reduced testcase:\r\n```llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main() #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %.lcssa17 = phi i64 [ %0, %for.body ]\r\n ret i32 0\r\n\r\nfor.body: ; preds = %for.body, %entry\r\n %0 = phi i64 [ 0, %entry ], [ %1, %for.body ]\r\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\r\n %indvars.iv.next = add i64 %indvars.iv, 1\r\n %1 = load i64, ptr null, align 8\r\n %exitcond.not = icmp eq i64 %indvars.iv, 22\r\n br i1 %exitcond.not, label %for.cond.cleanup, label %for.body\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl128b,+zvl256b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```bash\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll\r\nWARNING: You're attempting to print out a bitcode file.\r\nThis is inadvisable as it may cause display problems. If\r\nyou REALLY want to taste LLVM bitcode first-hand, you\r\ncan force output with the `-f' option.\r\n\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp:569: llvm::Value* llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int): Assertion `Offset <= State.VF.getKnownMinValue() && \"invalid offset to extract from\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000055972ae01800 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ed2800)\r\n #1 0x000055972adfec0f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2ecfc0f)\r\n #2 0x000055972adfed65 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000728161442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007281614969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007281614969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007281614969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000728161442476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007281614287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000072816142871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000728161439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000559729f62d80 llvm::VPInstruction::generatePerPart(llvm::VPTransformState&, unsigned int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2033d80)\r\n#12 0x0000559729f63155 llvm::VPInstruction::execute(llvm::VPTransformState&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2034155)\r\n#13 0x0000559729f2de47 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffee47)\r\n#14 0x0000559729f2e141 llvm::VPIRBasicBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fff141)\r\n#15 0x0000559729f30286 llvm::VPlan::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2001286)\r\n#16 0x0000559729e2380a llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ef480a)\r\n#17 0x0000559729e34a7c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f05a7c)\r\n#18 0x0000559729e36f7e llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f07f7e)\r\n#19 0x0000559729e380a0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1f090a0)\r\n#20 0x0000559728cc6dc6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xd97dc6)\r\n#21 0x000055972ac1ce46 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2cede46)\r\n#22 0x0000559728cc9f56 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xd9af56)\r\n#23 0x000055972ac1bbcb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2cecbcb)\r\n#24 0x0000559728cc6526 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xd97526)\r\n#25 0x000055972ac19d02 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2cead02)\r\n#26 0x0000559728520136 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5f1136)\r\n#27 0x0000559728511d51 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5e2d51)\r\n#28 0x0000728161429d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#29 0x0000728161429e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#30 0x0000728161429e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#31 0x0000559728507b85 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x5d8b85)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nGodbolt: https://godbolt.org/z/ojz8sMa1r\r\n\r\nFound via fuzzer", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "svs-quic", "body": "Bisected to #93395 \r\ncc: @fhahn " }, { "author": "fhahn", "body": "Thanks for the test case. Should be fixed now. The assertion highlighted a case where we previously miscompiled for the case where VF is <vscale x 1 x ..>; in that case we are unable to extract the penultimate value (second-to-last) if vscale = 1" } ] }
true
null
102597
https://github.com/llvm/llvm-project/issues/102597
miscompilation
513c3726ebc0a324f7e5a11d25617bb9557324d6
2024-08-09T11:02:59
[ "llvm/test/Transforms/IndVarSimplify" ]
{ "fix_commit": "3512bcc2e9ab06b0ae2cab78744550b515e54184", "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": [ [ 11961, 11969 ] ], "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::computeConstantDifference" ], "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 3512bcc2e9ab06b0ae2cab78744550b515e54184 Author: Nikita Popov <[email protected]> Date: Mon Aug 12 15:18:32 2024 +0200 [SCEV] Fix incorrect extension in computeConstantDifference() The Mul factor was zero-extended here, resulting in incorrect results for integers larger than 64-bit. As we currently only multiply by 1 or -1, just split this into two cases -- there's no need for a full multiplication here. Fixes https://github.com/llvm/llvm-project/issues/102597. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 9ecdcbe2c5de..318a9d773dc2 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -11961,9 +11961,14 @@ ScalarEvolution::computeConstantDifference(const SCEV *More, const SCEV *Less) { SmallDenseMap<const SCEV *, int, 8> Multiplicity; APInt Diff(BW, 0); auto Add = [&](const SCEV *S, int Mul) { - if (auto *C = dyn_cast<SCEVConstant>(S)) - Diff += C->getAPInt() * Mul; - else + if (auto *C = dyn_cast<SCEVConstant>(S)) { + if (Mul == 1) { + Diff += C->getAPInt(); + } else { + assert(Mul == -1); + Diff -= C->getAPInt(); + } + } else Multiplicity[S] += Mul; }; auto Decompose = [&](const SCEV *S, int Mul) {
[ { "file": "llvm/test/Transforms/IndVarSimplify/pr102597.ll", "commands": [ "opt -S -passes=indvars < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nentry:\n br label %loop\n\nloop: ; preds = %loop.latch, %entry\n %iv = phi i128 [ 3, %entry ], [ %iv.dec, %loop.latch ]\n %tobool = icmp ne i128 %iv, 0\n br i1 %tobool, label %loop.latch, label %if\n\nif: ; preds = %loop\n call void @foo()\n br label %loop.latch\n\nloop.latch: ; preds = %if, %loop\n %iv.dec = add nsw i128 %iv, -1\n %cmp = icmp sgt i128 %iv, 0\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n\ndeclare void @foo()\n", "lli_expected_out": null, "additional_args": "-src-unroll=4 -tgt-unroll=4" } ] } ]
{ "title": "[SCEV] WRONG code ", "body": "```\r\nint printf(const char *, ...);\r\n__int128 a = 3, c;\r\nchar b;\r\nint main() {\r\n c = 3;\r\n for (; c >= 0; c--) {\r\n b = 0;\r\n for (; b <= 3; b++) {\r\n if (c)\r\n break;\r\n a = 0;\r\n }\r\n }\r\n printf(\"%d\\n\", (int)a);\r\n}\r\n\r\n```\r\n\r\nclang -march=z15 -O1 wrong0.i -o a.out\r\n\r\nThis program should print '0' as 'a' is set to zero inside the loop. It now prints '3' instead. A bisect leads to a recent commit: 79af689 \" [SCEV] Handle more adds in computeConstantDifference() (#101339)\".\r\n\r\nSeems like IndVarSimplify has gone wrong with an i128:\r\nGOOD <> BROKEN\r\n```\r\n; *** IR Dump After IndVarSimplifyPass on loo ; *** IR Dump After IndVarSimplifyPass on loo\r\n\r\n; Preheader: ; Preheader:\r\nentry: entry:\r\n br label %for.cond1.preheader br label %for.cond1.preheader\r\n\r\n; Loop: ; Loop:\r\nfor.cond1.preheader: for.cond1.preheader: \r\n %storemerge11 = phi i128 [ 3, %entry ], [ % %storemerge11 = phi i128 [ 3, %entry ], [ %\r\n %tobool = icmp ne i128 %storemerge11, 0 | br i1 true, label %for.inc5, label %if.end.\r\n br i1 %tobool, label %for.inc5, label %if.e <\r\n\r\nif.end.lr.ph: if.end.lr.ph: \r\n store i128 0, ptr @a, align 8, !tbaa !4 store i128 0, ptr @a, align 8, !tbaa !4\r\n br label %if.end br label %if.end\r\n\r\nif.end: if.end: \r\n %storemerge89 = phi i8 [ 0, %if.end.lr.ph ] %storemerge89 = phi i8 [ 0, %if.end.lr.ph ]\r\n %inc = add nuw nsw i8 %storemerge89, 1 %inc = add nuw nsw i8 %storemerge89, 1\r\n %cmp2 = icmp ugt i8 %storemerge89, 2 %cmp2 = icmp ugt i8 %storemerge89, 2\r\n %or.cond = or i1 %tobool, %cmp2 | %or.cond = or i1 true, %cmp2\r\n br i1 %or.cond, label %for.inc5.loopexit, l br i1 %or.cond, label %for.inc5.loopexit, l\r\n\r\nfor.inc5: for.inc5: \r\n %storemerge8.lcssa = phi i8 [ 0, %for.cond1 %storemerge8.lcssa = phi i8 [ 0, %for.cond1\r\n %dec = add nsw i128 %storemerge11, -1 %dec = add nsw i128 %storemerge11, -1\r\n %cmp = icmp ugt i128 %storemerge11, 0 %cmp = icmp ugt i128 %storemerge11, 0\r\n br i1 %cmp, label %for.cond1.preheader, lab br i1 %cmp, label %for.cond1.preheader, lab\r\n\r\nfor.inc5.loopexit: for.inc5.loopexit: \r\n %inc.lcssa = phi i8 [ %inc, %if.end ] %inc.lcssa = phi i8 [ %inc, %if.end ]\r\n br label %for.inc5 br label %for.inc5\r\n\r\n; Exit blocks ; Exit blocks\r\nfor.end6: for.end6: \r\n %storemerge8.lcssa.lcssa = phi i8 [ %storem %storemerge8.lcssa.lcssa = phi i8 [ %storem\r\n store i128 -1, ptr @c, align 8, !tbaa !4 store i128 -1, ptr @c, align 8, !tbaa !4\r\n store i8 %storemerge8.lcssa.lcssa, ptr @b, store i8 %storemerge8.lcssa.lcssa, ptr @b, \r\n %0 = load i128, ptr @a, align 8, !tbaa !4 %0 = load i128, ptr @a, align 8, !tbaa !4\r\n %conv7 = trunc i128 %0 to i32 %conv7 = trunc i128 %0 to i32\r\n %call = call signext i32 (ptr, ...) @printf %call = call signext i32 (ptr, ...) @printf\r\n ret i32 0 ret i32 0\r\n\r\n```", "author": "JonPsson1", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "nikic", "body": "Classic mistake: https://github.com/llvm/llvm-project/blob/2f8f58dd17a11934e8c8ec212b6474f76fb18e61/llvm/lib/Analysis/ScalarEvolution.cpp#L11967 This `* Mul` doesn't do what I wanted it to do :)\r\n\r\nI should really pick up https://github.com/llvm/llvm-project/pull/80309 again to prevent this kind of mistake in the first place." }, { "author": "JonPsson1", "body": "Is this commit self-contained in the sense that I could revert it on my testing machines? Or will you revert / fix soon?" } ] }
true
null
108698
https://github.com/llvm/llvm-project/issues/108698
miscompilation
ba8e4246e2f17030788e8a4954bf5c290332206f
2024-09-14T13:16:53
[ "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "87663fdab9d0e7bcc0b963ea078da9e2eb574908", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/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": [ [ 2597, 2607 ], [ 2628, 2634 ] ], "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::shrinkType" ], "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 87663fdab9d0e7bcc0b963ea078da9e2eb574908 Author: Yingwei Zheng <[email protected]> Date: Sun Sep 15 18:38:06 2024 +0800 [VectorCombine] Don't shrink lshr if the shamt is not less than bitwidth (#108705) Consider the following case: ``` define <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) { %19 = icmp eq <2 x i64> %vec.ind16, zeroinitializer %20 = zext <2 x i1> %19 to <2 x i32> %21 = lshr <2 x i32> %20, %broadcast.splat20 ret <2 x i32> %21 } ``` After https://github.com/llvm/llvm-project/pull/104606, we shrink the lshr into: ``` define <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) { %1 = icmp eq <2 x i64> %vec.ind16, zeroinitializer %2 = trunc <2 x i32> %broadcast.splat20 to <2 x i1> %3 = lshr <2 x i1> %1, %2 %4 = zext <2 x i1> %3 to <2 x i32> ret <2 x i32> %4 } ``` It is incorrect since `lshr i1 X, 1` returns `poison`. This patch adds additional check on the shamt operand. The lshr will get shrunk iff we ensure that the shamt is less than bitwidth of the smaller type. As `computeKnownBits(&I, *DL).countMaxActiveBits() > BW` always evaluates to true for `lshr(zext(X), Y)`, this check will only apply to bitwise logical instructions. Alive2: https://alive2.llvm.org/ce/z/j_RmTa Fixes https://github.com/llvm/llvm-project/issues/108698. diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index d7afe2f426d3..58701bfa60a3 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -2597,11 +2597,19 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) { auto *SmallTy = cast<FixedVectorType>(ZExted->getType()); unsigned BW = SmallTy->getElementType()->getPrimitiveSizeInBits(); - // Check that the expression overall uses at most the same number of bits as - // ZExted - KnownBits KB = computeKnownBits(&I, *DL); - if (KB.countMaxActiveBits() > BW) - return false; + if (I.getOpcode() == Instruction::LShr) { + // Check that the shift amount is less than the number of bits in the + // smaller type. Otherwise, the smaller lshr will return a poison value. + KnownBits ShAmtKB = computeKnownBits(I.getOperand(1), *DL); + if (ShAmtKB.getMaxValue().uge(BW)) + return false; + } else { + // Check that the expression overall uses at most the same number of bits as + // ZExted + KnownBits KB = computeKnownBits(&I, *DL); + if (KB.countMaxActiveBits() > BW) + return false; + } // Calculate costs of leaving current IR as it is and moving ZExt operation // later, along with adding truncates if needed @@ -2628,7 +2636,7 @@ bool VectorCombine::shrinkType(llvm::Instruction &I) { return false; // Check if we can propagate ZExt through its other users - KB = computeKnownBits(UI, *DL); + KnownBits KB = computeKnownBits(UI, *DL); if (KB.countMaxActiveBits() > BW) return false;
[ { "file": "llvm/test/Transforms/VectorCombine/AArch64/shrink-types.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "pr108698", "test_body": "target triple = \"aarch64\"\n\ndefine <2 x i32> @pr108698(<2 x i64> %x, <2 x i32> %y) {\n %cmp = icmp eq <2 x i64> %x, zeroinitializer\n %ext = zext <2 x i1> %cmp to <2 x i32>\n %lshr = lshr <2 x i32> %ext, %y\n ret <2 x i32> %lshr\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "wrong code at -O{2,3} on x86_64-linux-gnu", "body": "It appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier. \r\n\r\nCompiler Explorer: https://godbolt.org/z/EGasYh8x1\r\n\r\n```\r\n[691] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 223e2efa5e886502a9467b7ef700ebce9b7886e8)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[692] % \r\n[692] % clangtk -O1 small.c; ./a.out\r\n[693] % \r\n[693] % clangtk -O2 small.c\r\n[694] % ./a.out\r\nAborted\r\n[695] % \r\n[695] % cat small.c\r\nchar a[8];\r\nint b = 1, c;\r\nint main() {\r\n for (; c < 8; c++)\r\n a[c] = !c >> b;\r\n if (a[0] != 0)\r\n __builtin_abort();\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "miscompilation", "vectorizers" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/5SkPZS\r\n```\r\n; bin/opt -passes=vector-combine test.ll -S\r\n\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) {\r\n %19 = icmp eq <2 x i64> %vec.ind16, zeroinitializer\r\n %20 = zext <2 x i1> %19 to <2 x i32>\r\n %21 = lshr <2 x i32> %20, %broadcast.splat20\r\n ret <2 x i32> %21\r\n}\r\n```\r\n```\r\ndefine <2 x i32> @test(<2 x i64> %vec.ind16, <2 x i32> %broadcast.splat20) {\r\n %1 = icmp eq <2 x i64> %vec.ind16, zeroinitializer\r\n %2 = trunc <2 x i32> %broadcast.splat20 to <2 x i1>\r\n %3 = lshr <2 x i1> %1, %2\r\n %4 = zext <2 x i1> %3 to <2 x i32>\r\n ret <2 x i32> %4\r\n}\r\n```" }, { "author": "dtcxzyw", "body": "Related PR: https://github.com/llvm/llvm-project/pull/104606\r\n" } ] }
true
null
130250
https://github.com/llvm/llvm-project/issues/130250
crash
3ed4daf9a749fe8590ad291f63fabce48fb4135f
2025-03-07T05:51:40
[ "llvm/test/Transforms/PhaseOrdering", "llvm/test/Transforms/VectorCombine" ]
{ "fix_commit": "0ee8f699780569d7a6b94d61cd833285bb67eca1", "components": [ "VectorCombine" ], "bug_location_lineno": { "llvm/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": [ [ 2037, 2043 ], [ 2051, 2074 ] ], "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::foldShuffleOfSelects" ], "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 0ee8f699780569d7a6b94d61cd833285bb67eca1 Author: hanbeom <[email protected]> Date: Sat Mar 8 01:40:26 2025 +0900 [VectorCombine] Fix invalid shuffle cost argument of foldShuffleOfSelects (#130281) In the previous code (#128032), it specified the destination vector as the getShuffleCost argument. Because the shuffle mask specifies the indices of the two vectors specified as elements, the maximum value is twice the size of the source vector. This causes a problem if the destination vector is smaller than the source vector and specify an index in the mask that exceeds the size of the destination vector. Fix the problem by correcting the previous code, which was using wrong argument in the Cost calculation. Fixes #130250 diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp index 4d4a1a6e04d3..019d79567b4a 100644 --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -2037,7 +2037,6 @@ bool VectorCombine::foldShuffleOfSelects(Instruction &I) { m_Mask(Mask)))) return false; - auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType()); auto *C1VecTy = dyn_cast<FixedVectorType>(C1->getType()); auto *C2VecTy = dyn_cast<FixedVectorType>(C2->getType()); if (!C1VecTy || !C2VecTy || C1VecTy != C2VecTy) @@ -2051,24 +2050,26 @@ bool VectorCombine::foldShuffleOfSelects(Instruction &I) { (SI0FOp->getFastMathFlags() != SI1FOp->getFastMathFlags()))) return false; + auto *SrcVecTy = dyn_cast<FixedVectorType>(T1->getType()); + auto *DstVecTy = dyn_cast<FixedVectorType>(I.getType()); auto SK = TargetTransformInfo::SK_PermuteTwoSrc; auto SelOp = Instruction::Select; InstructionCost OldCost = TTI.getCmpSelInstrCost( - SelOp, T1->getType(), C1VecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); - OldCost += TTI.getCmpSelInstrCost(SelOp, T2->getType(), C2VecTy, + SelOp, SrcVecTy, C1VecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); + OldCost += TTI.getCmpSelInstrCost(SelOp, SrcVecTy, C2VecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); - OldCost += TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr, + OldCost += TTI.getShuffleCost(SK, SrcVecTy, Mask, CostKind, 0, nullptr, {I.getOperand(0), I.getOperand(1)}, &I); - auto *C1C2VecTy = cast<FixedVectorType>( - toVectorTy(Type::getInt1Ty(I.getContext()), DstVecTy->getNumElements())); InstructionCost NewCost = - TTI.getShuffleCost(SK, C1C2VecTy, Mask, CostKind, 0, nullptr, {C1, C2}); + TTI.getShuffleCost(SK, C1VecTy, Mask, CostKind, 0, nullptr, {C1, C2}); NewCost += - TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr, {T1, T2}); + TTI.getShuffleCost(SK, SrcVecTy, Mask, CostKind, 0, nullptr, {T1, T2}); NewCost += - TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr, {F1, F2}); - NewCost += TTI.getCmpSelInstrCost(SelOp, DstVecTy, DstVecTy, + TTI.getShuffleCost(SK, SrcVecTy, Mask, CostKind, 0, nullptr, {F1, F2}); + auto *C1C2ShuffledVecTy = cast<FixedVectorType>( + toVectorTy(Type::getInt1Ty(I.getContext()), DstVecTy->getNumElements())); + NewCost += TTI.getCmpSelInstrCost(SelOp, DstVecTy, C1C2ShuffledVecTy, CmpInst::BAD_ICMP_PREDICATE, CostKind); LLVM_DEBUG(dbgs() << "Found a shuffle feeding two selects: " << I
[ { "file": "llvm/test/Transforms/PhaseOrdering/X86/blendv-select.ll", "commands": [ "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -O3 -S -mtriple=x86_64-- -mcpu=x86-64-v4" ], "tests": [ { "test_name": "x86_pblendvb_v8f32_v4f32", "test_body": "define <8 x float> @x86_pblendvb_v8f32_v4f32(<8 x float> %a, <8 x float> %b, <8 x float> %c, <8 x float> %d) {\n %a.bc = bitcast <8 x float> %a to <32 x i8>\n %b.bc = bitcast <8 x float> %b to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = fcmp olt <8 x float> %c, %d\n %sext = sext <8 x i1> %cmp to <8 x i32>\n %sext.bc = bitcast <8 x i32> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <8 x float>\n ret <8 x float> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v32i16_v16i16", "test_body": "define <8 x i64> @x86_pblendvb_v32i16_v16i16(<8 x i64> %a, <8 x i64> %b, <8 x i64> %c, <8 x i64> %d) {\n %a.bc = bitcast <8 x i64> %a to <64 x i8>\n %b.bc = bitcast <8 x i64> %b to <64 x i8>\n %c.bc = bitcast <8 x i64> %c to <32 x i16>\n %d.bc = bitcast <8 x i64> %d to <32 x i16>\n %a.lo = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.lo = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %a.hi = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %b.hi = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %cmp = icmp slt <32 x i16> %c.bc, %d.bc\n %sext = sext <32 x i1> %cmp to <32 x i16>\n %sext.bc = bitcast <32 x i16> %sext to <64 x i8>\n %sext.lo = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sext.hi = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %sel.lo = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.lo, <32 x i8> %b.lo, <32 x i8> %sext.lo)\n %sel.hi = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.hi, <32 x i8> %b.hi, <32 x i8> %sext.hi)\n %concat = shufflevector <32 x i8> %sel.lo, <32 x i8> %sel.hi, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %res = bitcast <64 x i8> %concat to <8 x i64>\n ret <8 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8>, <32 x i8>, <32 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v64i8_v32i8", "test_body": "define <8 x i64> @x86_pblendvb_v64i8_v32i8(<8 x i64> %a, <8 x i64> %b, <8 x i64> %c, <8 x i64> %d) {\n %a.bc = bitcast <8 x i64> %a to <64 x i8>\n %b.bc = bitcast <8 x i64> %b to <64 x i8>\n %c.bc = bitcast <8 x i64> %c to <64 x i8>\n %d.bc = bitcast <8 x i64> %d to <64 x i8>\n %a.lo = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.lo = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %a.hi = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %b.hi = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %cmp = icmp slt <64 x i8> %c.bc, %d.bc\n %sext = sext <64 x i1> %cmp to <64 x i8>\n %sext.lo = shufflevector <64 x i8> %sext, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sext.hi = shufflevector <64 x i8> %sext, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %sel.lo = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.lo, <32 x i8> %b.lo, <32 x i8> %sext.lo)\n %sel.hi = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.hi, <32 x i8> %b.hi, <32 x i8> %sext.hi)\n %concat = shufflevector <32 x i8> %sel.lo, <32 x i8> %sel.hi, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %res = bitcast <64 x i8> %concat to <8 x i64>\n ret <8 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8>, <32 x i8>, <32 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v4f64_v2f64", "test_body": "define <4 x double> @x86_pblendvb_v4f64_v2f64(<4 x double> %a, <4 x double> %b, <4 x double> %c, <4 x double> %d) {\n %a.bc = bitcast <4 x double> %a to <32 x i8>\n %b.bc = bitcast <4 x double> %b to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = fcmp olt <4 x double> %c, %d\n %sext = sext <4 x i1> %cmp to <4 x i64>\n %sext.bc = bitcast <4 x i64> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x double>\n ret <4 x double> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v16i16_v8i16", "test_body": "define <4 x i64> @x86_pblendvb_v16i16_v8i16(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %c.bc = bitcast <4 x i64> %c to <16 x i16>\n %d.bc = bitcast <4 x i64> %d to <16 x i16>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <16 x i16> %c.bc, %d.bc\n %sext = sext <16 x i1> %cmp to <16 x i16>\n %sext.bc = bitcast <16 x i16> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v8i32_v4i32", "test_body": "define <4 x i64> @x86_pblendvb_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %c.bc = bitcast <4 x i64> %c to <8 x i32>\n %d.bc = bitcast <4 x i64> %d to <8 x i32>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <8 x i32> %c.bc, %d.bc\n %sext = sext <8 x i1> %cmp to <8 x i32>\n %sext.bc = bitcast <8 x i32> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v4i64_v2i64", "test_body": "define <4 x i64> @x86_pblendvb_v4i64_v2i64(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <4 x i64> %c, %d\n %sext = sext <4 x i1> %cmp to <4 x i64>\n %sext.bc = bitcast <4 x i64> %sext to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v32i8_v16i8", "test_body": "define <4 x i64> @x86_pblendvb_v32i8_v16i8(<4 x i64> %a, <4 x i64> %b, <4 x i64> %c, <4 x i64> %d) {\n %a.bc = bitcast <4 x i64> %a to <32 x i8>\n %b.bc = bitcast <4 x i64> %b to <32 x i8>\n %c.bc = bitcast <4 x i64> %c to <32 x i8>\n %d.bc = bitcast <4 x i64> %d to <32 x i8>\n %a.lo = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %b.lo = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %a.hi = shufflevector <32 x i8> %a.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.hi = shufflevector <32 x i8> %b.bc, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %cmp = icmp slt <32 x i8> %c.bc, %d.bc\n %sext = sext <32 x i1> %cmp to <32 x i8>\n %sext.lo = shufflevector <32 x i8> %sext, <32 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n %sext.hi = shufflevector <32 x i8> %sext, <32 x i8> poison, <16 x i32> <i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sel.lo = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.lo, <16 x i8> %b.lo, <16 x i8> %sext.lo)\n %sel.hi = tail call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %a.hi, <16 x i8> %b.hi, <16 x i8> %sext.hi)\n %concat = shufflevector <16 x i8> %sel.lo, <16 x i8> %sel.hi, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %res = bitcast <32 x i8> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "x86_pblendvb_v16i32_v8i32", "test_body": "define <8 x i64> @x86_pblendvb_v16i32_v8i32(<8 x i64> %a, <8 x i64> %b, <8 x i64> %c, <8 x i64> %d) {\n %a.bc = bitcast <8 x i64> %a to <64 x i8>\n %b.bc = bitcast <8 x i64> %b to <64 x i8>\n %c.bc = bitcast <8 x i64> %c to <16 x i32>\n %d.bc = bitcast <8 x i64> %d to <16 x i32>\n %a.lo = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %b.lo = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %a.hi = shufflevector <64 x i8> %a.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %b.hi = shufflevector <64 x i8> %b.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %cmp = icmp slt <16 x i32> %c.bc, %d.bc\n %sext = sext <16 x i1> %cmp to <16 x i32>\n %sext.bc = bitcast <16 x i32> %sext to <64 x i8>\n %sext.lo = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31>\n %sext.hi = shufflevector <64 x i8> %sext.bc, <64 x i8> poison, <32 x i32> <i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %sel.lo = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.lo, <32 x i8> %b.lo, <32 x i8> %sext.lo)\n %sel.hi = tail call <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8> %a.hi, <32 x i8> %b.hi, <32 x i8> %sext.hi)\n %concat = shufflevector <32 x i8> %sel.lo, <32 x i8> %sel.hi, <64 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31, i32 32, i32 33, i32 34, i32 35, i32 36, i32 37, i32 38, i32 39, i32 40, i32 41, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 58, i32 59, i32 60, i32 61, i32 62, i32 63>\n %res = bitcast <64 x i8> %concat to <8 x i64>\n ret <8 x i64> %res\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)\ndeclare <32 x i8> @llvm.x86.avx2.pblendvb(<32 x i8>, <32 x i8>, <32 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll", "commands": [ "opt -passes=vector-combine -S %s" ], "tests": [ { "test_name": "bitcast_smax_v8i32_v4i32", "test_body": "target triple = \"aarch64\"\n\ndefine <4 x i64> @bitcast_smax_v8i32_v4i32(<4 x i64> %a, <4 x i64> %b) {\n %a.bc0 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc0 = bitcast <4 x i64> %b to <8 x i32>\n %cmp = icmp slt <8 x i32> %a.bc0, %b.bc0\n %cmp.lo = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %cmp.hi = shufflevector <8 x i1> %cmp, <8 x i1> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %a.bc1 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc1 = bitcast <4 x i64> %b to <8 x i32>\n %a.lo = shufflevector <8 x i32> %a.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %b.lo = shufflevector <8 x i32> %b.bc1, <8 x i32> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n %lo = select <4 x i1> %cmp.lo, <4 x i32> %b.lo, <4 x i32> %a.lo\n %a.bc2 = bitcast <4 x i64> %a to <8 x i32>\n %b.bc2 = bitcast <4 x i64> %b to <8 x i32>\n %a.hi = shufflevector <8 x i32> %a.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %b.hi = shufflevector <8 x i32> %b.bc2, <8 x i32> poison, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %hi = select <4 x i1> %cmp.hi, <4 x i32> %b.hi, <4 x i32> %a.hi\n %concat = shufflevector <4 x i32> %lo, <4 x i32> %hi, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n %res = bitcast <8 x i32> %concat to <4 x i64>\n ret <4 x i64> %res\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/VectorCombine/X86/shuffle-of-selects.ll", "commands": [ "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mcpu=x86-64-v2", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mcpu=x86-64-v3", "opt < %s -passes=vector-combine -S -mtriple=x86_64-- -mcpu=x86-64-v4" ], "tests": [ { "test_name": "src_v8tov16_i16", "test_body": "define <16 x i16> @src_v8tov16_i16(<8 x i1> %a, <8 x i1> %b, <8 x i16> %x, <8 x i16> %y, <8 x i16> %z) {\n %select.xz = select <8 x i1> %a, <8 x i16> %x, <8 x i16> %z\n %select.yx = select <8 x i1> %b, <8 x i16> %y, <8 x i16> %x\n %res = shufflevector <8 x i16> %select.xz, <8 x i16> %select.yx, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\n ret <16 x i16> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v4tov8_float", "test_body": "define <8 x float> @src_v4tov8_float(<4 x i1> %a, <4 x i1> %b, <4 x float> %x, <4 x float> %y, <4 x float> %z) {\n %select.xz = select <4 x i1> %a, <4 x float> %x, <4 x float> %z\n %select.yx = select <4 x i1> %b, <4 x float> %y, <4 x float> %x\n %res = shufflevector <4 x float> %select.xz, <4 x float> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x float> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v4tov8_i16", "test_body": "define <8 x i16> @src_v4tov8_i16(<4 x i1> %a, <4 x i1> %b, <4 x i16> %x, <4 x i16> %y, <4 x i16> %z) {\n %select.xz = select <4 x i1> %a, <4 x i16> %x, <4 x i16> %z\n %select.yx = select <4 x i1> %b, <4 x i16> %y, <4 x i16> %x\n %res = shufflevector <4 x i16> %select.xz, <4 x i16> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x i16> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov4_i64", "test_body": "define <4 x i64> @src_v2tov4_i64(<2 x i1> %a, <2 x i1> %b, <2 x i64> %x, <2 x i64> %y, <2 x i64> %z) {\n %select.xz = select <2 x i1> %a, <2 x i64> %x, <2 x i64> %z\n %select.yx = select <2 x i1> %b, <2 x i64> %y, <2 x i64> %x\n %res = shufflevector <2 x i64> %select.xz, <2 x i64> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x i64> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov2_i64", "test_body": "define <2 x i64> @src_v2tov2_i64(<2 x i1> %a, <2 x i1> %b, <2 x i64> %x, <2 x i64> %y, <2 x i64> %z) {\n %select.xz = select <2 x i1> %a, <2 x i64> %x, <2 x i64> %z\n %select.yx = select <2 x i1> %b, <2 x i64> %y, <2 x i64> %x\n %res = shufflevector <2 x i64> %select.xz, <2 x i64> %select.yx, <2 x i32> <i32 0, i32 3>\n ret <2 x i64> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov4_i32", "test_body": "define <4 x i32> @src_v2tov4_i32(<2 x i1> %a, <2 x i1> %b, <2 x i32> %x, <2 x i32> %y, <2 x i32> %z) {\n %select.xz = select <2 x i1> %a, <2 x i32> %x, <2 x i32> %z\n %select.yx = select <2 x i1> %b, <2 x i32> %y, <2 x i32> %x\n %res = shufflevector <2 x i32> %select.xz, <2 x i32> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x i32> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov2_double", "test_body": "define <2 x double> @src_v2tov2_double(<2 x i1> %a, <2 x i1> %b, <2 x double> %x, <2 x double> %y, <2 x double> %z) {\n %select.xz = select <2 x i1> %a, <2 x double> %x, <2 x double> %z\n %select.yx = select <2 x i1> %b, <2 x double> %y, <2 x double> %x\n %res = shufflevector <2 x double> %select.xz, <2 x double> %select.yx, <2 x i32> <i32 0, i32 3>\n ret <2 x double> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_mask0", "test_body": "define <2 x float> @test_mask0(<4 x i1> %c, <4 x float> %x, <4 x float> %y, <4 x float> %z) {\n %select.xy = select <4 x i1> %c, <4 x float> %x, <4 x float> %y\n %select.yz = select <4 x i1> %c, <4 x float> %y, <4 x float> %z\n %res = shufflevector <4 x float> %select.xy, <4 x float> %select.yz, <2 x i32> <i32 4, i32 7>\n ret <2 x float> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov4_i16", "test_body": "define <4 x i16> @src_v2tov4_i16(<2 x i1> %a, <2 x i1> %b, <2 x i16> %x, <2 x i16> %y, <2 x i16> %z) {\n %select.xz = select <2 x i1> %a, <2 x i16> %x, <2 x i16> %z\n %select.yx = select <2 x i1> %b, <2 x i16> %y, <2 x i16> %x\n %res = shufflevector <2 x i16> %select.xz, <2 x i16> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x i16> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v4tov8_i32", "test_body": "define <8 x i32> @src_v4tov8_i32(<4 x i1> %a, <4 x i1> %b, <4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {\n %select.xz = select <4 x i1> %a, <4 x i32> %x, <4 x i32> %z\n %select.yx = select <4 x i1> %b, <4 x i32> %y, <4 x i32> %x\n %res = shufflevector <4 x i32> %select.xz, <4 x i32> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x i32> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v8tov8_i16", "test_body": "define <8 x i16> @src_v8tov8_i16(<8 x i1> %a, <8 x i1> %b, <8 x i16> %x, <8 x i16> %y, <8 x i16> %z) {\n %select.xz = select <8 x i1> %a, <8 x i16> %x, <8 x i16> %z\n %select.yx = select <8 x i1> %b, <8 x i16> %y, <8 x i16> %x\n %res = shufflevector <8 x i16> %select.xz, <8 x i16> %select.yx, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>\n ret <8 x i16> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov4_float", "test_body": "define <4 x float> @src_v2tov4_float(<2 x i1> %a, <2 x i1> %b, <2 x float> %x, <2 x float> %y, <2 x float> %z) {\n %select.xz = select <2 x i1> %a, <2 x float> %x, <2 x float> %z\n %select.yx = select <2 x i1> %b, <2 x float> %y, <2 x float> %x\n %res = shufflevector <2 x float> %select.xz, <2 x float> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x float> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_mask1", "test_body": "define <2 x float> @test_mask1(<4 x i1> %c, <4 x float> %x, <4 x float> %y, <4 x float> %z) {\n %select.xy = select <4 x i1> %c, <4 x float> %x, <4 x float> %y\n %select.yz = select <4 x i1> %c, <4 x float> %y, <4 x float> %z\n %res = shufflevector <4 x float> %select.xy, <4 x float> %select.yz, <2 x i32> <i32 7, i32 4>\n ret <2 x float> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov4_double", "test_body": "define <4 x double> @src_v2tov4_double(<2 x i1> %a, <2 x i1> %b, <2 x double> %x, <2 x double> %y, <2 x double> %z) {\n %select.xz = select <2 x i1> %a, <2 x double> %x, <2 x double> %z\n %select.yx = select <2 x i1> %b, <2 x double> %y, <2 x double> %x\n %res = shufflevector <2 x double> %select.xz, <2 x double> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x double> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "src_v2tov4_float_nnan", "test_body": "define <4 x float> @src_v2tov4_float_nnan(<2 x i1> %a, <2 x i1> %b, <2 x float> %x, <2 x float> %y, <2 x float> %z) {\n %select.xz = select nnan <2 x i1> %a, <2 x float> %x, <2 x float> %z\n %select.yx = select nnan <2 x i1> %b, <2 x float> %y, <2 x float> %x\n %res = shufflevector <2 x float> %select.xz, <2 x float> %select.yx, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x float> %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "A/F: `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\" after upstream commit 5d1029b", "body": "One of our internal tests recently started hitting an assertion failure when building which I bisected back to 5d1029b4a87f36a394c169b89b26a74d17f7ff01. I was able to reduce the test case to the following code:\n```c++\ntypedef float e __attribute__((__vector_size__(16)));\ne g(e h, e j) { return __builtin_ia32_cmpltps(j, h); }\ne k(float, float l, float n, float) { return {n, l}; }\ne o, p;\ntypedef union q {\n e r;\n} t;\ntypedef union u {\n e r;\n} w;\nunion aa {\n t ab;\n w ac;\n float f[];\n aa(t v) : ab(v) {}\n e ad;\n aa(e v) : ad(v) {}\n};\n#define ae(v) aa(v).ab\n#define af(v) aa(v).ac\n#define ag(a, b, c, d) ae(k(d, c, b, a))\n#define ah(v, ai) aa(v).f[ai]\n#define aj(a, b) af(g(a.r, b.r))\n#define ak(a, b, m) ae(al(a.r, b.r, m.r))\nt am(t an, t abcd) {\n e ao = __builtin_shufflevector(an.r, abcd.r, 0, 4, 1, 5);\n t ap = ae(ao);\n return ap;\n}\ne al(e, e, e aq) {\n e ar = __builtin_ia32_blendvps(o, p, aq);\n return ar;\n}\nfloat as(t v, int s) { return ah(v, s); }\nw at(t a, t b) { return aj(a, b); }\nt au(w aq) {\n t b, a;\n return ak(a, b, aq);\n}\nt av(t an, t abcd) { return am(an, abcd); }\nt aw_x, bl, bq_ay;\nt bf();\nstruct bc {\n t bd;\n bc(t bg) { bd = bg; }\n t be() { return bd; }\n};\nstruct bh {\n t bi;\n int i;\n bh(t bg, int bj) : bi(bg), i(bj) {}\n operator float() {\n float bk = as(bi, i);\n return bk;\n }\n};\nfloat bm_x;\nstruct bm {\n bm(float y, float z) { bl = ag(bm_x, y, z, 0.0f); }\n bm(bc y, bc z) {\n q bn = z.be(), bo(bn), bp = y.be();\n bl = av(bo, bp);\n }\n bh operator[](int bj) { return bh(bl, bj); }\n};\nbc bq() {\n t __trans_tmp_3 = bf();\n u bb = at(bq_ay, aw_x);\n __trans_tmp_3 = au(bb);\n return __trans_tmp_3;\n}\nbm bs() { return bm(bq(), bq()); }\nvoid bx() {\n unsigned char by, bz;\n bm ca = bs();\n bz = ca[1];\n by = ca[2];\n bm(bz, by);\n}\n```\nIf compiled with a compiler that includes 5d1029b4a87f36a394c169b89b26a74d17f7ff01 and with optimizations and AVX enabled, the compiler hits an assertion failure:\n```\n$ ~/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang -c -O2 -mavx repro.cpp\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/lib/IR/Instructions.cpp:1906: bool isSingleSourceMaskImpl(llvm::ArrayRef<int>, int): Assertion `I >= 0 && I < (NumOpElts * 2) && \"Out-of-bounds shuffle mask element\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0. Program arguments: /home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang -c -O2 repro.cpp -mavx\n1. <eof> parser at end of file\n2. Optimizer\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"repro.cpp\"\n4. Running pass \"vector-combine\" on function \"_Z2bxv\"\n #0 0x0000561cf26380ef llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x224f0ef)\n #1 0x0000561cf2635c04 llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x224cc04)\n #2 0x0000561cf2586258 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x00007f5f727e6420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #4 0x00007f5f722b300b raise /build/glibc-FcRMwW/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #5 0x00007f5f72292859 abort /build/glibc-FcRMwW/glibc-2.31/stdlib/abort.c:81:7\n #6 0x00007f5f72292729 get_sysdep_segment_value /build/glibc-FcRMwW/glibc-2.31/intl/loadmsgcat.c:509:8\n #7 0x00007f5f72292729 _nl_load_domain /build/glibc-FcRMwW/glibc-2.31/intl/loadmsgcat.c:970:34\n #8 0x00007f5f722a3fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #9 0x0000561cf203aa46 isSingleSourceMaskImpl(llvm::ArrayRef<int>, int) Instructions.cpp:0:0\n#10 0x0000561cf20436e4 llvm::ShuffleVectorInst::isSelectMask(llvm::ArrayRef<int>, int) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1c5a6e4)\n#11 0x0000561cf116c2b0 llvm::X86TTIImpl::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd832b0)\n#12 0x0000561cf17404ed llvm::TargetTransformInfo::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) const (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x13574ed)\n#13 0x0000561cf42a667a (anonymous namespace)::VectorCombine::foldShuffleOfSelects(llvm::Instruction&) VectorCombine.cpp:0:0\n#14 0x0000561cf42c0e55 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\n#15 0x0000561cf42c1d85 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x3ed8d85)\n#16 0x0000561cf3b8f1a6 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x37a61a6)\n#17 0x0000561cf20deb09 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1cf5b09)\n#18 0x0000561cf11a9906 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xdc0906)\n#19 0x0000561cf20dd372 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1cf4372)\n#20 0x0000561cf11aa2c6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xdc12c6)\n#21 0x0000561cf20dcd91 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x1cf3d91)\n#22 0x0000561cf28d99aa (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#23 0x0000561cf28dd9db clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x24f49db)\n#24 0x0000561cf3021121 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c38121)\n#25 0x0000561cf4a4170c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x465870c)\n#26 0x0000561cf3021548 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c38548)\n#27 0x0000561cf32f80f9 clang::FrontendAction::Execute() (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2f0f0f9)\n#28 0x0000561cf3278f4e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2e8ff4e)\n#29 0x0000561cf33ed2b6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x30042b6)\n#30 0x0000561cf1125ccd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd3cccd)\n#31 0x0000561cf111d5ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#32 0x0000561cf306b3cd void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#33 0x0000561cf2586760 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x219d760)\n#34 0x0000561cf306b9ef clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#35 0x0000561cf302c9c4 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c439c4)\n#36 0x0000561cf302da5e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c44a5e)\n#37 0x0000561cf3035ef5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0x2c4cef5)\n#38 0x0000561cf1122aab clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd39aab)\n#39 0x0000561cf10546bb main (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xc6b6bb)\n#40 0x00007f5f72294083 __libc_start_main /build/glibc-FcRMwW/glibc-2.31/csu/../csu/libc-start.c:342:3\n#41 0x0000561cf111d05e _start (/home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin/clang+0xd3405e)\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\nclang version 21.0.0 (https://github.com/llvm/llvm-project.git 5d1029b4a87f36a394c169b89b26a74d17f7ff01)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/dyung/src/upstream/5d1029b4a87f36a394c169b89b26a74d17f7ff01-linux/bin\nBuild config: +assertions\n```", "author": "dyung", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "ParkHanbum", "body": "Can you help me compile the sample?\nnever mind. I get the crash." }, { "author": "ParkHanbum", "body": "```\ndefine void @test(<4 x i1> %z, <4 x float> %1, <4 x float> %2) {\n%a = select <4 x i1> %z, <4 x float> %1, <4 x float> %2\n%b = select <4 x i1> %z, <4 x float> %1, <4 x float> %2\n%c = shufflevector <4 x float> %a, <4 x float> %b, <2 x i32> <i32 0, i32 5>\nret void\n}\n```\nThe problematic IR is shown above.\n\n```\n * frame #4: 0x00000001043d7fe8 clang++`isIdentityMaskImpl(llvm::ArrayRef<int>, int) (.cold.3) + 36\n frame #5: 0x0000000100fd5334 clang++`llvm::ShuffleVectorInst::isSelectMask(llvm::ArrayRef<int>, int) + 256\n frame #6: 0x0000000100095ff8 clang++`llvm::BasicTTIImplBase<llvm::X86TTIImpl>::improveShuffleKindFromMask(llvm::TargetTransformInfo::ShuffleKind, llvm::ArrayRef<int>, llvm::VectorType*, int&, llvm::VectorType*&) const + 184\n frame #7: 0x000000010033e104 clang++`llvm::X86TTIImpl::getShuffleCost(llvm::TargetTransformInfo::ShuffleKind, llvm::VectorType*, llvm::ArrayRef<int>, llvm::TargetTransformInfo::TargetCostKind, int, llvm::VectorType*, llvm::ArrayRef<llvm::Value const*>, llvm::Instruction const*) + 128\n```\n\nThis is where the crash happens.\n\n\n```\n OldCost += TTI.getShuffleCost(SK, DstVecTy, Mask, CostKind, 0, nullptr,\n {I.getOperand(0), I.getOperand(1)}, &I);\n```\n\nThe problematic IR is shown above.\n\nTo calculate the OldCost, call getShuffleCost.\nThe DstVecTy passed as an argument is `<2 x float>` and the Mask is <i32 0, i32 5>.\n\nThe second Mask specifier is 5, which is greater than NumOpElts * 2 of DstVecTy, so this assertion seems to be thrown.\n(If we increase the Mask to <3 x i32> <i32 0, i32 5, i32 5> or decrease the Mask size to <2 x i32> <i32 0, i32 3>, the error will not occur.)\n\nI will add a fix after further analysis.\n\n\n" }, { "author": "RKSimon", "body": "@ParkHanbum You must use the source type not destination type for getShuffleCost" }, { "author": "ParkHanbum", "body": "@RKSimon I'm sorry, I made a mistake. I'll push up the patch quickly.\n" }, { "author": "RKSimon", "body": "You just need the fix + test coverage - no need to revert the existing patch if you are prompt" } ] }
true
null
106083
https://github.com/llvm/llvm-project/issues/106083
crash
d075debc508898d5f365f8e909c54d6f4edada85
2024-08-26T14:36:57
[ "llvm/test/Transforms/DFAJumpThreading" ]
{ "fix_commit": "d4a38c8ff5c993e14c42895b51a47272fb03a857", "components": [ "DFAJumpThreading" ], "bug_location_lineno": { "llvm/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": [ [ 194, 200 ], [ 202, 207 ], [ 223, 254 ] ], "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": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": [ "unfold" ], "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 d4a38c8ff5c993e14c42895b51a47272fb03a857 Author: Usman Nadeem <[email protected]> Date: Tue Sep 24 08:54:36 2024 -0700 [DFAJumpThreading] Handle select unfolding when user phi is not a dir… (#109511) …ect successor Previously the code assumed that the select instruction is defined in a block that is a direct predecessor of the block where the PHINode uses it. So, we were hitting an assertion when we tried to access the def block as an incoming block for the user phi node. This patch handles that case by using the correct end block and creating a new phi node that aggregates both the values of the select in that end block, and then using that new unfolded phi to overwrite the original user phi node. Fixes #106083 Change-Id: Ie471994cca232318f74a6e6438efa21e561c2dc0 diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp index ef9c264482a6..0e2b5c925a6a 100644 --- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp @@ -194,7 +194,6 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold, SelectInst *SI = SIToUnfold.getInst(); PHINode *SIUse = SIToUnfold.getUse(); BasicBlock *StartBlock = SI->getParent(); - BasicBlock *EndBlock = SIUse->getParent(); BranchInst *StartBlockTerm = dyn_cast<BranchInst>(StartBlock->getTerminator()); @@ -202,6 +201,7 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold, assert(SI->hasOneUse()); if (StartBlockTerm->isUnconditional()) { + BasicBlock *EndBlock = StartBlock->getUniqueSuccessor(); // Arbitrarily choose the 'false' side for a new input value to the PHI. BasicBlock *NewBlock = BasicBlock::Create( SI->getContext(), Twine(SI->getName(), ".si.unfold.false"), @@ -223,32 +223,44 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold, NewBlock->getFirstInsertionPt()); NewPhi->addIncoming(SIOp2, StartBlock); - if (auto *OpSi = dyn_cast<SelectInst>(SIOp1)) - NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, SIUse)); - if (auto *OpSi = dyn_cast<SelectInst>(SIOp2)) - NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, NewPhi)); - - // Update the phi node of SI. - for (unsigned Idx = 0; Idx < SIUse->getNumIncomingValues(); ++Idx) { - if (SIUse->getIncomingBlock(Idx) == StartBlock) - SIUse->setIncomingValue(Idx, SIOp1); + // Update any other PHI nodes in EndBlock. + for (PHINode &Phi : EndBlock->phis()) { + if (SIUse == &Phi) + continue; + Phi.addIncoming(Phi.getIncomingValueForBlock(StartBlock), NewBlock); } - SIUse->addIncoming(NewPhi, NewBlock); - // Update any other PHI nodes in EndBlock. - for (auto II = EndBlock->begin(); PHINode *Phi = dyn_cast<PHINode>(II); - ++II) { - if (Phi != SIUse) - Phi->addIncoming(Phi->getIncomingValueForBlock(StartBlock), NewBlock); + // Update the phi node of SI, which is its only use. + if (EndBlock == SIUse->getParent()) { + SIUse->addIncoming(NewPhi, NewBlock); + SIUse->replaceUsesOfWith(SI, SIOp1); + } else { + PHINode *EndPhi = PHINode::Create(SIUse->getType(), pred_size(EndBlock), + Twine(SI->getName(), ".si.unfold.phi"), + EndBlock->getFirstInsertionPt()); + for (BasicBlock *Pred : predecessors(EndBlock)) { + if (Pred != StartBlock && Pred != NewBlock) + EndPhi->addIncoming(EndPhi, Pred); + } + + EndPhi->addIncoming(SIOp1, StartBlock); + EndPhi->addIncoming(NewPhi, NewBlock); + SIUse->replaceUsesOfWith(SI, EndPhi); + SIUse = EndPhi; } - StartBlockTerm->eraseFromParent(); + if (auto *OpSi = dyn_cast<SelectInst>(SIOp1)) + NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, SIUse)); + if (auto *OpSi = dyn_cast<SelectInst>(SIOp2)) + NewSIsToUnfold->push_back(SelectInstToUnfold(OpSi, NewPhi)); // Insert the real conditional branch based on the original condition. + StartBlockTerm->eraseFromParent(); BranchInst::Create(EndBlock, NewBlock, SI->getCondition(), StartBlock); DTU->applyUpdates({{DominatorTree::Insert, StartBlock, EndBlock}, {DominatorTree::Insert, StartBlock, NewBlock}}); } else { + BasicBlock *EndBlock = SIUse->getParent(); BasicBlock *NewBlockT = BasicBlock::Create( SI->getContext(), Twine(SI->getName(), ".si.unfold.true"), EndBlock->getParent(), EndBlock);
[ { "file": "llvm/test/Transforms/DFAJumpThreading/dfa-jump-threading-transform.ll", "commands": [ "opt -S -passes=dfa-jump-threading %s" ], "tests": [ { "test_name": "test2", "test_body": "define i32 @test2(i32 %init) {\nentry:\n %cmp = icmp eq i32 %init, 0\n %sel = select i1 %cmp, i32 0, i32 2\n br label %loop.1\n\nloop.1: ; preds = %loop.1.backedge, %entry\n %state.1 = phi i32 [ %sel, %entry ], [ %state.1.be2, %loop.1.backedge ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2.backedge, %loop.1\n %state.2 = phi i32 [ %state.1, %loop.1 ], [ %state.2.be, %loop.2.backedge ]\n br label %loop.3\n\nloop.3: ; preds = %case2, %loop.2\n %state = phi i32 [ %state.2, %loop.2 ], [ 3, %case2 ]\n switch i32 %state, label %infloop.i [\n i32 2, label %case2\n i32 3, label %case3\n i32 4, label %case4\n i32 0, label %case0\n i32 1, label %case1\n ]\n\ncase2: ; preds = %loop.3\n br i1 %cmp, label %loop.3, label %loop.1.backedge\n\ncase3: ; preds = %loop.3\n br i1 %cmp, label %loop.2.backedge, label %case4\n\ncase4: ; preds = %case3, %loop.3\n br i1 %cmp, label %loop.2.backedge, label %loop.1.backedge\n\nloop.1.backedge: ; preds = %case4, %case2\n %state.1.be = phi i32 [ 2, %case4 ], [ 4, %case2 ]\n %state.1.be2 = select i1 %cmp, i32 1, i32 %state.1.be\n br label %loop.1\n\nloop.2.backedge: ; preds = %case4, %case3\n %state.2.be = phi i32 [ 3, %case4 ], [ 0, %case3 ]\n br label %loop.2\n\ncase0: ; preds = %loop.3\n br label %exit\n\ncase1: ; preds = %loop.3\n br label %exit\n\ninfloop.i: ; preds = %infloop.i, %loop.3\n br label %infloop.i\n\nexit: ; preds = %case1, %case0\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr106083_select_dead_uses", "test_body": "define void @pr106083_select_dead_uses(i1 %cmp1, i1 %not, ptr %p) {\nbb:\n %spec.select = select i1 %cmp1, i32 0, i32 1\n br label %.loopexit6\n\n.loopexit6: ; preds = %select.unfold, %bb\n br i1 %not, label %select.unfold, label %bb1\n\nbb1: ; preds = %.loopexit6\n %i = load i32, ptr %p, align 4\n %not2 = icmp eq i32 0, 0\n %spec.select7 = select i1 %not2, i32 %spec.select, i32 0\n br label %select.unfold\n\nselect.unfold: ; preds = %bb1, %.loopexit6\n %_2 = phi i32 [ 0, %.loopexit6 ], [ %spec.select7, %bb1 ]\n switch i32 %_2, label %bb2 [\n i32 0, label %.preheader.preheader\n i32 1, label %.loopexit6\n ]\n\n.preheader.preheader: ; preds = %select.unfold\n ret void\n\nbb2: ; preds = %select.unfold\n unreachable\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test1", "test_body": "define i32 @test1(i32 %num) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %count = phi i32 [ 0, %entry ], [ %inc, %for.inc ]\n %state = phi i32 [ 1, %entry ], [ %state.next, %for.inc ]\n switch i32 %state, label %for.inc [\n i32 1, label %case1\n i32 2, label %case2\n ]\n\ncase1: ; preds = %for.body\n br label %for.inc\n\ncase2: ; preds = %for.body\n %cmp = icmp eq i32 %count, 50\n %sel = select i1 %cmp, i32 1, i32 2\n br label %for.inc\n\nfor.inc: ; preds = %case2, %case1, %for.body\n %state.next = phi i32 [ %sel, %case2 ], [ 1, %for.body ], [ 2, %case1 ]\n %inc = add nsw i32 %count, 1\n %cmp.exit = icmp slt i32 %inc, %num\n br i1 %cmp.exit, label %for.body, label %for.end\n\nfor.end: ; preds = %for.inc\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr106083_invalidBBarg_fold", "test_body": "define void @pr106083_invalidBBarg_fold(i1 %cmp1, i1 %cmp2, i1 %not, ptr %d) {\nbb:\n %sel = select i1 %cmp1, i32 0, i32 1\n br label %BB1\n\nBB1: ; preds = %BB1.backedge, %BB7, %bb\n %i = phi i16 [ 0, %BB1.backedge ], [ 0, %bb ], [ 1, %BB7 ]\n br i1 %not, label %BB7, label %BB2\n\nBB2: ; preds = %BB1\n store i16 0, ptr %d, align 2\n %spec.select = select i1 %cmp2, i32 %sel, i32 0\n br label %BB7\n\nBB7: ; preds = %BB2, %BB1\n %d.promoted4 = phi i16 [ 0, %BB1 ], [ 1, %BB2 ]\n %_3 = phi i32 [ 0, %BB1 ], [ %spec.select, %BB2 ]\n switch i32 %_3, label %BB1.backedge [\n i32 0, label %BB1\n i32 1, label %BB8\n ]\n\nBB1.backedge: ; preds = %BB7\n br label %BB1\n\nBB8: ; preds = %BB7\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr78059_bitwidth", "test_body": "define void @pr78059_bitwidth() {\n.split.preheader:\n br label %.split\n\n.split: ; preds = %.split, %.split.preheader\n %0 = phi i128 [ 0, %.split.preheader ], [ -1, %.split ]\n switch i128 %0, label %end [\n i128 -1, label %end\n i128 0, label %.split\n ]\n\nend: ; preds = %.split, %.split\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[DFAJumpThreading] crash since b167ada", "body": "Seeing many assertions that go away if I revert b167ada \"[DFAJumpThreading] Rewrite the way paths are enumerated (#96127)\".\r\n\r\n```\r\nclang-20 -cc1 -triple s390x-unknown-linux-gnu -target-cpu z15 -O3 -w -mllvm -enable-dfa-jump-thread -o /dev/null -emit-llvm -x ir tc_dfa-jt_invalidbbarg.ll\r\n...\r\n10 0x000002aa0a73e544 (anonymous namespace)::DFAJumpThreading::run\r\n...\r\n```\r\n\r\n```\r\nclang-20 -cc1 -triple s390x-unknown-linux-gnu -target-cpu z16 -O3 -w -mllvm -enable-dfa-jump-thread -o /dev/null -emit-llvm -x ir tc_select_mustbedeadnow.ll\r\n...\r\n#10 0x000002aa1b0c0968 llvm::DFAJumpThreadingPass::run\r\n...\r\n\r\n```\r\n[tcs_dfa-jt.tar.gz](https://github.com/user-attachments/files/16750050/tcs_dfa-jt.tar.gz)\r\n", "author": "JonPsson1", "labels": [ "crash", "llvm:transforms" ], "comments": [ { "author": "mikaelholmen", "body": "Perhaps the same assertion I reported here:\r\n https://github.com/llvm/llvm-project/pull/96127#issuecomment-2303862037\r\n?" }, { "author": "JonPsson1", "body": "> Perhaps the same assertion I reported here: [#96127 (comment)](https://github.com/llvm/llvm-project/pull/96127#issuecomment-2303862037) ?\r\n\r\nYes, same assertion, and in addition my second test case above triggered another assertion." } ] }
true
null
106257
https://github.com/llvm/llvm-project/issues/106257
crash
a4989cd603b8e8185e35e3c2b7b48b422d4898be
2024-08-27T17:46:38
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "4b84288f00f3e112045bbc4be4f1539147574ead", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 8648, 8653 ] ], "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 4b84288f00f3e112045bbc4be4f1539147574ead Author: Florian Hahn <[email protected]> Date: Wed Aug 28 19:12:04 2024 +0100 [VPlan] Pass live-ins used as exit values straight to live-out. Live-ins that are used as exit values don't need to be extracted, they can be passed through directly. This fixes a crash when trying to extract from a live-in. Fixes https://github.com/llvm/llvm-project/issues/106257. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 4c68a95b9c26..cb104c4ed2d0 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8648,6 +8648,11 @@ addUsersInExitBlock(VPlan &Plan, // Introduce VPUsers modeling the exit values. for (const auto &[ExitPhi, V] : ExitingValuesToFix) { + // Pass live-in values used by exit phis directly through to the live-out. + if (V->isLiveIn()) { + Plan.addLiveOut(ExitPhi, V); + continue; + } VPValue *Ext = B.createNaryOp( VPInstruction::ExtractFromEnd, {V, Plan.getOrAddLiveIn(ConstantInt::get(
[ { "file": "llvm/test/Transforms/LoopVectorize/extract-from-end-vector-constant.ll", "commands": [ "opt -p loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "exit_value_vector_live_in", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine <2 x i64> @exit_value_vector_live_in(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.1, %loop ]\n %gep = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep, align 2\n %iv.next.1 = add i64 %iv, 1\n %ec = icmp ult i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n %res = phi <2 x i64> [ zeroinitializer, %loop ]\n ret <2 x i64> %res\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "exit_value_scalar_live_in", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i64 @exit_value_scalar_live_in(ptr %dst, i64 %in) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.1, %loop ]\n %gep = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep, align 2\n %iv.next.1 = add i64 %iv, 1\n %ec = icmp ult i64 %iv, 1000\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n %res = phi i64 [ %in, %loop ]\n ret i64 %res\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[LoopVectorize] Assertion `(GeneratedValue->getType()->isVectorTy() == !GeneratesPerFirstLaneOnly || State.VF.isScalar()) && \"scalar value but not only first lane defined\"' failed.", "body": "Testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine fastcc void @g() #0 {\r\nfor.cond1.preheader.us.preheader:\r\n br label %for.cond.cleanup20.us.us.1\r\n\r\nfor.cond.cleanup20.us.us.1: ; preds = %for.cond.cleanup20.us.us.1, %for.cond1.preheader.us.preheader\r\n %indvars.iv.1 = phi i64 [ 0, %for.cond1.preheader.us.preheader ], [ %indvars.iv.next.1, %for.cond.cleanup20.us.us.1 ]\r\n %arrayidx.us.us.1 = getelementptr [0 x i16], ptr null, i64 0, i64 %indvars.iv.1\r\n store i16 0, ptr %arrayidx.us.us.1, align 2\r\n %indvars.iv.next.1 = add i64 %indvars.iv.1, 1\r\n %cmp12.us.us.1 = icmp ult i64 %indvars.iv.1, 1\r\n br i1 %cmp12.us.us.1, label %for.cond.cleanup20.us.us.1, label %for.cond.cleanup14.us.us.1\r\n\r\nfor.cond.cleanup14.us.us.1: ; preds = %for.cond.cleanup20.us.us.1\r\n %.lcssa.1 = phi <2 x i64> [ zeroinitializer, %for.cond.cleanup20.us.us.1 ]\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\nhttps://godbolt.org/z/aoe8vdc1f\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp:732: virtual void llvm::VPInstruction::execute(llvm::VPTransformState&): Assertion `(GeneratedValue->getType()->isVectorTy() == !GeneratesPerFirstLaneOnly || State.VF.isScalar()) && \"scalar value but not only first lane defined\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize -S reduced.ll\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"g\"\r\n #0 0x0000644a7eb61500 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300e500)\r\n #1 0x0000644a7eb5e91f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x300b91f)\r\n #2 0x0000644a7eb5ea75 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000790e6c842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x0000790e6c8969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000790e6c8969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x0000790e6c8969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x0000790e6c842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x0000790e6c8287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x0000790e6c82871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x0000790e6c839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x0000644a7dc8e57a llvm::VPInstruction::execute(llvm::VPTransformState&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x213b57a)\r\n#12 0x0000644a7dc4f617 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fc617)\r\n#13 0x0000644a7dc4f910 llvm::VPIRBasicBlock::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fc910)\r\n#14 0x0000644a7dc51c2d llvm::VPlan::execute(llvm::VPTransformState*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fec2d)\r\n#15 0x0000644a7db37af9 llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe4af9)\r\n#16 0x0000644a7db4afce llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ff7fce)\r\n#17 0x0000644a7db4d101 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffa101)\r\n#18 0x0000644a7db4d777 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffa777)\r\n#19 0x0000644a7c9b0a46 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5da46)\r\n#20 0x0000644a7e96c95f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1995f)\r\n#21 0x0000644a7c9b3bd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe60bd6)\r\n#22 0x0000644a7e96b6db llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e186db)\r\n#23 0x0000644a7c9afe76 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5ce76)\r\n#24 0x0000644a7e96971d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1671d)\r\n#25 0x0000644a7c1d9e36 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x686e36)\r\n#26 0x0000644a7c1cbbc1 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x678bc1)\r\n#27 0x0000790e6c829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#28 0x0000790e6c829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#29 0x0000790e6c829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#30 0x0000644a7c1c1f75 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x66ef75)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nFound via fuzzer", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
108098
https://github.com/llvm/llvm-project/issues/108098
crash
b8239e1201f5871bed5b633b76fa9536672f287f
2024-09-10T21:48:37
[ "llvm/test/Analysis/CostModel", "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "ea83e1c05a5adee5d8f9e680356ee57556ba64a1", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 1182, 1194 ] ], "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": [ "setWideningDecision" ], "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 ea83e1c05a5adee5d8f9e680356ee57556ba64a1 Author: Florian Hahn <[email protected]> Date: Wed Sep 11 21:04:33 2024 +0100 [LV] Assign cost to all interleave members when not interleaving. At the moment, the full cost of all interleave group members is assigned to the instruction at the group's insert position, even if the decision was to not form an interleave group. This can lead to inaccurate cost estimates, e.g. if the instruction at the insert position is dead. If the decision is to not vectorize but scalarize or scather/gather, then the cost will be to total cost for all members. In those cases, assign individual the cost per member, to more closely reflect to choice per instruction. This fixes a divergence between legacy and VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/108098. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 640a7bf3d672..3b6b154b9660 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1182,13 +1182,23 @@ public: InstructionCost Cost) { assert(VF.isVector() && "Expected VF >=2"); /// Broadcast this decicion to all instructions inside the group. - /// But the cost will be assigned to one instruction only. + /// When interleaving, the cost will only be assigned one instruction, the + /// insert position. For other cases, add the appropriate fraction of the + /// total cost to each instruction. This ensures accurate costs are used, + /// even if the insert position instruction is not used. + InstructionCost InsertPosCost = Cost; + InstructionCost OtherMemberCost = 0; + if (W != CM_Interleave) + OtherMemberCost = InsertPosCost = Cost / Grp->getNumMembers(); + ; for (unsigned Idx = 0; Idx < Grp->getFactor(); ++Idx) { if (auto *I = Grp->getMember(Idx)) { if (Grp->getInsertPos() == I) - WideningDecisions[std::make_pair(I, VF)] = std::make_pair(W, Cost); + WideningDecisions[std::make_pair(I, VF)] = + std::make_pair(W, InsertPosCost); else - WideningDecisions[std::make_pair(I, VF)] = std::make_pair(W, 0); + WideningDecisions[std::make_pair(I, VF)] = + std::make_pair(W, OtherMemberCost); } } }
[ { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f32-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x float], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.4\n %v0 = load float, ptr %in0, align 4\n %v1 = load float, ptr %in1, align 4\n %v2 = load float, ptr %in2, align 4\n %v3 = load float, ptr %in3, align 4\n %v4 = load float, ptr %in4, align 4\n %reduce.add.0 = fadd float %v0, %v1\n %reduce.add.1 = fadd float %reduce.add.0, %v2\n %reduce.add.2 = fadd float %reduce.add.1, %v3\n %reduce.add.3 = fadd float %reduce.add.2, %v4\n %reduce.add.3.narrow = fptoui float %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f32-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x float], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.6\n %v0 = load float, ptr %in0, align 4\n %v1 = load float, ptr %in1, align 4\n %v2 = load float, ptr %in2, align 4\n %v3 = load float, ptr %in3, align 4\n %v4 = load float, ptr %in4, align 4\n %v5 = load float, ptr %in5, align 4\n %v6 = load float, ptr %in6, align 4\n %reduce.add.0 = fadd float %v0, %v1\n %reduce.add.1 = fadd float %reduce.add.0, %v2\n %reduce.add.2 = fadd float %reduce.add.1, %v3\n %reduce.add.3 = fadd float %reduce.add.2, %v4\n %reduce.add.4 = fadd float %reduce.add.3, %v5\n %reduce.add.5 = fadd float %reduce.add.4, %v6\n %reduce.add.5.narrow = fptoui float %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f32-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x float], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x float], ptr @A, i64 0, i64 %iv.7\n %v0 = load float, ptr %in0, align 4\n %v1 = load float, ptr %in1, align 4\n %v2 = load float, ptr %in2, align 4\n %v3 = load float, ptr %in3, align 4\n %v4 = load float, ptr %in4, align 4\n %v5 = load float, ptr %in5, align 4\n %v6 = load float, ptr %in6, align 4\n %v7 = load float, ptr %in7, align 4\n %reduce.add.0 = fadd float %v0, %v1\n %reduce.add.1 = fadd float %reduce.add.0, %v2\n %reduce.add.2 = fadd float %reduce.add.1, %v3\n %reduce.add.3 = fadd float %reduce.add.2, %v4\n %reduce.add.4 = fadd float %reduce.add.3, %v5\n %reduce.add.5 = fadd float %reduce.add.4, %v6\n %reduce.add.6 = fadd float %reduce.add.5, %v7\n %reduce.add.6.narrow = fptoui float %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-2.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.0.narrow = fptoui double %reduce.add.0 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.0.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 2\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-3.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.1.narrow = fptoui double %reduce.add.1 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.1.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 3\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-4.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.2.narrow = fptoui double %reduce.add.2 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.2.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 4\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.3.narrow = fptoui double %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-6.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.5\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %v5 = load double, ptr %in5, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.4 = fadd double %reduce.add.3, %v5\n %reduce.add.4.narrow = fptoui double %reduce.add.4 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.4.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 6\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.6\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %v5 = load double, ptr %in5, align 8\n %v6 = load double, ptr %in6, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.4 = fadd double %reduce.add.3, %v5\n %reduce.add.5 = fadd double %reduce.add.4, %v6\n %reduce.add.5.narrow = fptoui double %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-f64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x double], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x double], ptr @A, i64 0, i64 %iv.7\n %v0 = load double, ptr %in0, align 8\n %v1 = load double, ptr %in1, align 8\n %v2 = load double, ptr %in2, align 8\n %v3 = load double, ptr %in3, align 8\n %v4 = load double, ptr %in4, align 8\n %v5 = load double, ptr %in5, align 8\n %v6 = load double, ptr %in6, align 8\n %v7 = load double, ptr %in7, align 8\n %reduce.add.0 = fadd double %v0, %v1\n %reduce.add.1 = fadd double %reduce.add.0, %v2\n %reduce.add.2 = fadd double %reduce.add.1, %v3\n %reduce.add.3 = fadd double %reduce.add.2, %v4\n %reduce.add.4 = fadd double %reduce.add.3, %v5\n %reduce.add.5 = fadd double %reduce.add.4, %v6\n %reduce.add.6 = fadd double %reduce.add.5, %v7\n %reduce.add.6.narrow = fptoui double %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i16-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i16], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.4\n %v0 = load i16, ptr %in0, align 2\n %v1 = load i16, ptr %in1, align 2\n %v2 = load i16, ptr %in2, align 2\n %v3 = load i16, ptr %in3, align 2\n %v4 = load i16, ptr %in4, align 2\n %reduce.add.0 = add i16 %v0, %v1\n %reduce.add.1 = add i16 %reduce.add.0, %v2\n %reduce.add.2 = add i16 %reduce.add.1, %v3\n %reduce.add.3 = add i16 %reduce.add.2, %v4\n %reduce.add.3.narrow = trunc i16 %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i16-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i16], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.6\n %v0 = load i16, ptr %in0, align 2\n %v1 = load i16, ptr %in1, align 2\n %v2 = load i16, ptr %in2, align 2\n %v3 = load i16, ptr %in3, align 2\n %v4 = load i16, ptr %in4, align 2\n %v5 = load i16, ptr %in5, align 2\n %v6 = load i16, ptr %in6, align 2\n %reduce.add.0 = add i16 %v0, %v1\n %reduce.add.1 = add i16 %reduce.add.0, %v2\n %reduce.add.2 = add i16 %reduce.add.1, %v3\n %reduce.add.3 = add i16 %reduce.add.2, %v4\n %reduce.add.4 = add i16 %reduce.add.3, %v5\n %reduce.add.5 = add i16 %reduce.add.4, %v6\n %reduce.add.5.narrow = trunc i16 %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i16-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i16], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i16], ptr @A, i64 0, i64 %iv.7\n %v0 = load i16, ptr %in0, align 2\n %v1 = load i16, ptr %in1, align 2\n %v2 = load i16, ptr %in2, align 2\n %v3 = load i16, ptr %in3, align 2\n %v4 = load i16, ptr %in4, align 2\n %v5 = load i16, ptr %in5, align 2\n %v6 = load i16, ptr %in6, align 2\n %v7 = load i16, ptr %in7, align 2\n %reduce.add.0 = add i16 %v0, %v1\n %reduce.add.1 = add i16 %reduce.add.0, %v2\n %reduce.add.2 = add i16 %reduce.add.1, %v3\n %reduce.add.3 = add i16 %reduce.add.2, %v4\n %reduce.add.4 = add i16 %reduce.add.3, %v5\n %reduce.add.5 = add i16 %reduce.add.4, %v6\n %reduce.add.6 = add i16 %reduce.add.5, %v7\n %reduce.add.6.narrow = trunc i16 %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-4-indices-01uu.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, 0\n %reduce.add.2 = add i32 %reduce.add.1, 0\n %reduce.add.2.narrow = trunc i32 %reduce.add.2 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.2.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv, 4\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.4\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %v2 = load i32, ptr %in2, align 4\n %v3 = load i32, ptr %in3, align 4\n %v4 = load i32, ptr %in4, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, %v2\n %reduce.add.2 = add i32 %reduce.add.1, %v3\n %reduce.add.3 = add i32 %reduce.add.2, %v4\n %reduce.add.3.narrow = trunc i32 %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.6\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %v2 = load i32, ptr %in2, align 4\n %v3 = load i32, ptr %in3, align 4\n %v4 = load i32, ptr %in4, align 4\n %v5 = load i32, ptr %in5, align 4\n %v6 = load i32, ptr %in6, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, %v2\n %reduce.add.2 = add i32 %reduce.add.1, %v3\n %reduce.add.3 = add i32 %reduce.add.2, %v4\n %reduce.add.4 = add i32 %reduce.add.3, %v5\n %reduce.add.5 = add i32 %reduce.add.4, %v6\n %reduce.add.5.narrow = trunc i32 %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i32-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i32], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i32], ptr @A, i64 0, i64 %iv.7\n %v0 = load i32, ptr %in0, align 4\n %v1 = load i32, ptr %in1, align 4\n %v2 = load i32, ptr %in2, align 4\n %v3 = load i32, ptr %in3, align 4\n %v4 = load i32, ptr %in4, align 4\n %v5 = load i32, ptr %in5, align 4\n %v6 = load i32, ptr %in6, align 4\n %v7 = load i32, ptr %in7, align 4\n %reduce.add.0 = add i32 %v0, %v1\n %reduce.add.1 = add i32 %reduce.add.0, %v2\n %reduce.add.2 = add i32 %reduce.add.1, %v3\n %reduce.add.3 = add i32 %reduce.add.2, %v4\n %reduce.add.4 = add i32 %reduce.add.3, %v5\n %reduce.add.5 = add i32 %reduce.add.4, %v6\n %reduce.add.6 = add i32 %reduce.add.5, %v7\n %reduce.add.6.narrow = trunc i32 %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-2.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.0.narrow = trunc i64 %reduce.add.0 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.0.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 2\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-3.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.1.narrow = trunc i64 %reduce.add.1 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.1.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 3\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-4.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.2.narrow = trunc i64 %reduce.add.2 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.2.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 4\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.3.narrow = trunc i64 %reduce.add.3 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-6.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.5\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %v5 = load i64, ptr %in5, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.4 = add i64 %reduce.add.3, %v5\n %reduce.add.4.narrow = trunc i64 %reduce.add.4 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.4.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 6\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.6\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %v5 = load i64, ptr %in5, align 8\n %v6 = load i64, ptr %in6, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.4 = add i64 %reduce.add.3, %v5\n %reduce.add.5 = add i64 %reduce.add.4, %v6\n %reduce.add.5.narrow = trunc i64 %reduce.add.5 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i64], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i64], ptr @A, i64 0, i64 %iv.7\n %v0 = load i64, ptr %in0, align 8\n %v1 = load i64, ptr %in1, align 8\n %v2 = load i64, ptr %in2, align 8\n %v3 = load i64, ptr %in3, align 8\n %v4 = load i64, ptr %in4, align 8\n %v5 = load i64, ptr %in5, align 8\n %v6 = load i64, ptr %in6, align 8\n %v7 = load i64, ptr %in7, align 8\n %reduce.add.0 = add i64 %v0, %v1\n %reduce.add.1 = add i64 %reduce.add.0, %v2\n %reduce.add.2 = add i64 %reduce.add.1, %v3\n %reduce.add.3 = add i64 %reduce.add.2, %v4\n %reduce.add.4 = add i64 %reduce.add.3, %v5\n %reduce.add.5 = add i64 %reduce.add.4, %v6\n %reduce.add.6 = add i64 %reduce.add.5, %v7\n %reduce.add.6.narrow = trunc i64 %reduce.add.6 to i8\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6.narrow, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i8-stride-5.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %in0 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.4\n %v0 = load i8, ptr %in0, align 1\n %v1 = load i8, ptr %in1, align 1\n %v2 = load i8, ptr %in2, align 1\n %v3 = load i8, ptr %in3, align 1\n %v4 = load i8, ptr %in4, align 1\n %reduce.add.0 = add i8 %v0, %v1\n %reduce.add.1 = add i8 %reduce.add.0, %v2\n %reduce.add.2 = add i8 %reduce.add.1, %v3\n %reduce.add.3 = add i8 %reduce.add.2, %v4\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.3, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 5\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i8-stride-7.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %in0 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.6\n %v0 = load i8, ptr %in0, align 1\n %v1 = load i8, ptr %in1, align 1\n %v2 = load i8, ptr %in2, align 1\n %v3 = load i8, ptr %in3, align 1\n %v4 = load i8, ptr %in4, align 1\n %v5 = load i8, ptr %in5, align 1\n %v6 = load i8, ptr %in6, align 1\n %reduce.add.0 = add i8 %v0, %v1\n %reduce.add.1 = add i8 %reduce.add.0, %v2\n %reduce.add.2 = add i8 %reduce.add.1, %v3\n %reduce.add.3 = add i8 %reduce.add.2, %v4\n %reduce.add.4 = add i8 %reduce.add.3, %v5\n %reduce.add.5 = add i8 %reduce.add.4, %v6\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.5, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 7\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-load-i8-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl,+avx512bw --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i8], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in0 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %in1 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.1\n %in2 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.2\n %in3 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.3\n %in4 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.4\n %in5 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.5\n %in6 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.6\n %in7 = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.7\n %v0 = load i8, ptr %in0, align 1\n %v1 = load i8, ptr %in1, align 1\n %v2 = load i8, ptr %in2, align 1\n %v3 = load i8, ptr %in3, align 1\n %v4 = load i8, ptr %in4, align 1\n %v5 = load i8, ptr %in5, align 1\n %v6 = load i8, ptr %in6, align 1\n %v7 = load i8, ptr %in7, align 1\n %reduce.add.0 = add i8 %v0, %v1\n %reduce.add.1 = add i8 %reduce.add.0, %v2\n %reduce.add.2 = add i8 %reduce.add.1, %v3\n %reduce.add.3 = add i8 %reduce.add.2, %v4\n %reduce.add.4 = add i8 %reduce.add.3, %v5\n %reduce.add.5 = add i8 %reduce.add.4, %v6\n %reduce.add.6 = add i8 %reduce.add.5, %v7\n %out = getelementptr inbounds [1024 x i8], ptr @B, i64 0, i64 %iv.0\n store i8 %reduce.add.6, ptr %out, align 1\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-store-f64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x double], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %v.narrow = load i8, ptr %in, align 1\n %v = uitofp i8 %v.narrow to double\n %v0 = fadd double %v, 0.000000e+00\n %v1 = fadd double %v, 1.000000e+00\n %v2 = fadd double %v, 2.000000e+00\n %v3 = fadd double %v, 3.000000e+00\n %v4 = fadd double %v, 4.000000e+00\n %v5 = fadd double %v, 5.000000e+00\n %v6 = fadd double %v, 6.000000e+00\n %v7 = fadd double %v, 7.000000e+00\n %out0 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.0\n %out1 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.1\n %out2 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.2\n %out3 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.3\n %out4 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.4\n %out5 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.5\n %out6 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.6\n %out7 = getelementptr inbounds [1024 x double], ptr @B, i64 0, i64 %iv.7\n store double %v0, ptr %out0, align 8\n store double %v1, ptr %out1, align 8\n store double %v2, ptr %out2, align 8\n store double %v3, ptr %out3, align 8\n store double %v4, ptr %out4, align 8\n store double %v5, ptr %out5, align 8\n store double %v6, ptr %out6, align 8\n store double %v7, ptr %out7, align 8\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/interleaved-store-i64-stride-8.ll", "commands": [ "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+sse2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx2 --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -vectorizer-maximize-bandwidth -S -mattr=+avx512vl --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@A = external global [1024 x i8], align 128\n@B = external global [1024 x i64], align 128\n\ndefine void @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %iv.0 = add nuw nsw i64 %iv, 0\n %iv.1 = add nuw nsw i64 %iv, 1\n %iv.2 = add nuw nsw i64 %iv, 2\n %iv.3 = add nuw nsw i64 %iv, 3\n %iv.4 = add nuw nsw i64 %iv, 4\n %iv.5 = add nuw nsw i64 %iv, 5\n %iv.6 = add nuw nsw i64 %iv, 6\n %iv.7 = add nuw nsw i64 %iv, 7\n %in = getelementptr inbounds [1024 x i8], ptr @A, i64 0, i64 %iv.0\n %v.narrow = load i8, ptr %in, align 1\n %v = zext i8 %v.narrow to i64\n %v0 = add i64 %v, 0\n %v1 = add i64 %v, 1\n %v2 = add i64 %v, 2\n %v3 = add i64 %v, 3\n %v4 = add i64 %v, 4\n %v5 = add i64 %v, 5\n %v6 = add i64 %v, 6\n %v7 = add i64 %v, 7\n %out0 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.0\n %out1 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.1\n %out2 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.2\n %out3 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.3\n %out4 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.4\n %out5 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.5\n %out6 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.6\n %out7 = getelementptr inbounds [1024 x i64], ptr @B, i64 0, i64 %iv.7\n store i64 %v0, ptr %out0, align 8\n store i64 %v1, ptr %out1, align 8\n store i64 %v2, ptr %out2, align 8\n store i64 %v3, ptr %out3, align 8\n store i64 %v4, ptr %out4, align 8\n store i64 %v5, ptr %out5, align 8\n store i64 %v6, ptr %out6, align 8\n store i64 %v7, ptr %out7, align 8\n %iv.next = add nuw nsw i64 %iv.0, 8\n %cmp = icmp ult i64 %iv.next, 1024\n br i1 %cmp, label %for.body, label %for.cond.cleanup\n\nfor.cond.cleanup: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Analysis/CostModel/X86/masked-interleaved-store-i16.ll", "commands": [ "opt -passes=loop-vectorize -enable-interleaved-mem-accesses -prefer-predicate-over-epilogue=predicate-dont-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1", "opt -passes=loop-vectorize -enable-interleaved-mem-accesses -enable-masked-interleaved-mem-accesses -prefer-predicate-over-epilogue=predicate-dont-vectorize -S -mcpu=skx --debug-only=loop-vectorize < %s 2>&1" ], "tests": [ { "test_name": "test2", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test2(ptr noalias nocapture %points, i32 %numPoints, ptr noalias nocapture readonly %x, ptr noalias nocapture readonly %y) {\nentry:\n %cmp15 = icmp sgt i32 %numPoints, 0\n br i1 %cmp15, label %for.body.preheader, label %for.end\n\nfor.body.preheader: ; preds = %entry\n %wide.trip.count = zext i32 %numPoints to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.preheader\n %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]\n %arrayidx = getelementptr inbounds i16, ptr %x, i64 %indvars.iv\n %0 = load i16, ptr %arrayidx, align 2\n %1 = shl nsw i64 %indvars.iv, 2\n %arrayidx2 = getelementptr inbounds i16, ptr %points, i64 %1\n store i16 %0, ptr %arrayidx2, align 2\n %arrayidx4 = getelementptr inbounds i16, ptr %y, i64 %indvars.iv\n %2 = load i16, ptr %arrayidx4, align 2\n %3 = or disjoint i64 %1, 1\n %arrayidx7 = getelementptr inbounds i16, ptr %points, i64 %3\n store i16 %2, ptr %arrayidx7, align 2\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count\n br i1 %exitcond.not, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test1", "test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test1(ptr noalias nocapture %points, ptr noalias nocapture readonly %x, ptr noalias nocapture readonly %y) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]\n %arrayidx = getelementptr inbounds i16, ptr %x, i64 %indvars.iv\n %0 = load i16, ptr %arrayidx, align 2\n %1 = shl nuw nsw i64 %indvars.iv, 2\n %arrayidx2 = getelementptr inbounds i16, ptr %points, i64 %1\n store i16 %0, ptr %arrayidx2, align 2\n %arrayidx4 = getelementptr inbounds i16, ptr %y, i64 %indvars.iv\n %2 = load i16, ptr %arrayidx4, align 2\n %3 = or disjoint i64 %1, 1\n %arrayidx7 = getelementptr inbounds i16, ptr %points, i64 %3\n store i16 %2, ptr %arrayidx7, align 2\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %exitcond.not = icmp eq i64 %indvars.iv.next, 1024\n br i1 %exitcond.not, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/interleaved-vs-scalar.ll", "commands": [ "opt < %s -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize -S --debug-only=loop-vectorize 2>&1" ], "tests": [ { "test_name": "test", "test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64--linux-gnu\"\n\n%pair = type { i8, i8 }\n\ndefine void @test(ptr %p, ptr %q, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr %pair, ptr %p, i64 %i, i32 0\n %tmp1 = load i8, ptr %tmp0, align 1\n %tmp2 = getelementptr %pair, ptr %p, i64 %i, i32 1\n %tmp3 = load i8, ptr %tmp2, align 1\n %add = add i8 %tmp1, %tmp3\n %qi = getelementptr i8, ptr %q, i64 %i\n store i8 %add, ptr %qi, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp eq i64 %i.next, %n\n br i1 %cond, label %for.end, label %for.body\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/AArch64/interleaved_cost.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=2 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=4 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=8 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=16 -debug-only=loop-vectorize -disable-output < %s 2>&1" ], "tests": [ { "test_name": "i8_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i8.2 = type { i8, i8 }\n\ndefine void @i8_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i8, ptr %tmp0, align 1\n %tmp3 = load i8, ptr %tmp1, align 1\n store i8 %tmp2, ptr %tmp0, align 1\n store i8 %tmp3, ptr %tmp1, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i16_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i16.2 = type { i16, i16 }\n\ndefine void @i16_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i16, ptr %tmp0, align 2\n %tmp3 = load i16, ptr %tmp1, align 2\n store i16 %tmp2, ptr %tmp0, align 2\n store i16 %tmp3, ptr %tmp1, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i32_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i32.2 = type { i32, i32 }\n\ndefine void @i32_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i32, ptr %tmp0, align 4\n %tmp3 = load i32, ptr %tmp1, align 4\n store i32 %tmp2, ptr %tmp0, align 4\n store i32 %tmp3, ptr %tmp1, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i64_factor_2", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i64.2 = type { i64, i64 }\n\ndefine void @i64_factor_2(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i64, ptr %tmp0, align 8\n %tmp3 = load i64, ptr %tmp1, align 8\n store i64 %tmp2, ptr %tmp0, align 8\n store i64 %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i64_factor_8", "test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64\"\n\n%i64.8 = type { i64, i64, i64, i64, i64, i64, i64, i64 }\n\ndefine void @i64_factor_8(ptr %data, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.8, ptr %data, i64 %i, i32 2\n %tmp1 = getelementptr inbounds %i64.8, ptr %data, i64 %i, i32 6\n %tmp2 = load i64, ptr %tmp0, align 8\n %tmp3 = load i64, ptr %tmp1, align 8\n store i64 %tmp2, ptr %tmp0, align 8\n store i64 %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/ARM/mve-interleaved-cost.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=2 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=4 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=8 -debug-only=loop-vectorize -disable-output < %s 2>&1", "opt -passes=loop-vectorize -force-vector-width=16 -debug-only=loop-vectorize -disable-output < %s 2>&1" ], "tests": [ { "test_name": "i16_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i16.3 = type { i16, i16, i16 }\n\ndefine void @i16_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i16.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i16, ptr %tmp0, align 2\n %tmp4 = load i16, ptr %tmp1, align 2\n %tmp5 = load i16, ptr %tmp2, align 2\n store i16 %tmp3, ptr %tmp0, align 2\n store i16 %tmp4, ptr %tmp1, align 2\n store i16 %tmp5, ptr %tmp2, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f16_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f16.2 = type { half, half }\n\ndefine void @f16_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f16.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f16.2, ptr %data, i64 %i, i32 1\n %tmp2 = load half, ptr %tmp0, align 2\n %tmp3 = load half, ptr %tmp1, align 2\n store half %tmp2, ptr %tmp0, align 2\n store half %tmp3, ptr %tmp1, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i32_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i32.2 = type { i32, i32 }\n\ndefine void @i32_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i32, ptr %tmp0, align 4\n %tmp3 = load i32, ptr %tmp1, align 4\n store i32 %tmp2, ptr %tmp0, align 4\n store i32 %tmp3, ptr %tmp1, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i64_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i64.4 = type { i64, i64, i64, i64 }\n\ndefine void @i64_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i64.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i64, ptr %tmp0, align 8\n %tmp5 = load i64, ptr %tmp1, align 8\n %tmp6 = load i64, ptr %tmp2, align 8\n %tmp7 = load i64, ptr %tmp3, align 8\n store i64 %tmp4, ptr %tmp0, align 8\n store i64 %tmp5, ptr %tmp1, align 8\n store i64 %tmp6, ptr %tmp2, align 8\n store i64 %tmp7, ptr %tmp3, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f32_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f32.3 = type { float, float, float }\n\ndefine void @f32_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f32.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f32.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f32.3, ptr %data, i64 %i, i32 2\n %tmp3 = load float, ptr %tmp0, align 4\n %tmp4 = load float, ptr %tmp1, align 4\n %tmp5 = load float, ptr %tmp2, align 4\n store float %tmp3, ptr %tmp0, align 4\n store float %tmp4, ptr %tmp1, align 4\n store float %tmp5, ptr %tmp2, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i64_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i64.3 = type { i64, i64, i64 }\n\ndefine void @i64_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i64.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i64, ptr %tmp0, align 8\n %tmp4 = load i64, ptr %tmp1, align 8\n %tmp5 = load i64, ptr %tmp2, align 8\n store i64 %tmp3, ptr %tmp0, align 8\n store i64 %tmp4, ptr %tmp1, align 8\n store i64 %tmp5, ptr %tmp2, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f16_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f16.3 = type { half, half, half }\n\ndefine void @f16_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f16.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f16.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f16.3, ptr %data, i64 %i, i32 2\n %tmp3 = load half, ptr %tmp0, align 2\n %tmp4 = load half, ptr %tmp1, align 2\n %tmp5 = load half, ptr %tmp2, align 2\n store half %tmp3, ptr %tmp0, align 2\n store half %tmp4, ptr %tmp1, align 2\n store half %tmp5, ptr %tmp2, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i8_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i8.3 = type { i8, i8, i8 }\n\ndefine void @i8_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i8.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i8, ptr %tmp0, align 1\n %tmp4 = load i8, ptr %tmp1, align 1\n %tmp5 = load i8, ptr %tmp2, align 1\n store i8 %tmp3, ptr %tmp0, align 1\n store i8 %tmp4, ptr %tmp1, align 1\n store i8 %tmp5, ptr %tmp2, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f32_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f32.2 = type { float, float }\n\ndefine void @f32_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f32.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f32.2, ptr %data, i64 %i, i32 1\n %tmp2 = load float, ptr %tmp0, align 4\n %tmp3 = load float, ptr %tmp1, align 4\n store float %tmp2, ptr %tmp0, align 4\n store float %tmp3, ptr %tmp1, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i8_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i8.4 = type { i8, i8, i8, i8 }\n\ndefine void @i8_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i8.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i8, ptr %tmp0, align 1\n %tmp5 = load i8, ptr %tmp1, align 1\n %tmp6 = load i8, ptr %tmp2, align 1\n %tmp7 = load i8, ptr %tmp3, align 1\n store i8 %tmp4, ptr %tmp0, align 1\n store i8 %tmp5, ptr %tmp1, align 1\n store i8 %tmp6, ptr %tmp2, align 1\n store i8 %tmp7, ptr %tmp3, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i16_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i16.2 = type { i16, i16 }\n\ndefine void @i16_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i16, ptr %tmp0, align 2\n %tmp3 = load i16, ptr %tmp1, align 2\n store i16 %tmp2, ptr %tmp0, align 2\n store i16 %tmp3, ptr %tmp1, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i16_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i16.4 = type { i16, i16, i16, i16 }\n\ndefine void @i16_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i16.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i16, ptr %tmp0, align 2\n %tmp5 = load i16, ptr %tmp1, align 2\n %tmp6 = load i16, ptr %tmp2, align 2\n %tmp7 = load i16, ptr %tmp3, align 2\n store i16 %tmp4, ptr %tmp0, align 2\n store i16 %tmp5, ptr %tmp1, align 2\n store i16 %tmp6, ptr %tmp2, align 2\n store i16 %tmp7, ptr %tmp3, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f64_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f64.3 = type { double, double, double }\n\ndefine void @f64_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f64.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f64.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f64.3, ptr %data, i64 %i, i32 2\n %tmp3 = load double, ptr %tmp0, align 8\n %tmp4 = load double, ptr %tmp1, align 8\n %tmp5 = load double, ptr %tmp2, align 8\n store double %tmp3, ptr %tmp0, align 8\n store double %tmp4, ptr %tmp1, align 8\n store double %tmp5, ptr %tmp2, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i8_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i8.2 = type { i8, i8 }\n\ndefine void @i8_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i8.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i8, ptr %tmp0, align 1\n %tmp3 = load i8, ptr %tmp1, align 1\n store i8 %tmp2, ptr %tmp0, align 1\n store i8 %tmp3, ptr %tmp1, align 1\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i32_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i32.4 = type { i32, i32, i32, i32 }\n\ndefine void @i32_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %i32.4, ptr %data, i64 %i, i32 3\n %tmp4 = load i32, ptr %tmp0, align 4\n %tmp5 = load i32, ptr %tmp1, align 4\n %tmp6 = load i32, ptr %tmp2, align 4\n %tmp7 = load i32, ptr %tmp3, align 4\n store i32 %tmp4, ptr %tmp0, align 4\n store i32 %tmp5, ptr %tmp1, align 4\n store i32 %tmp6, ptr %tmp2, align 4\n store i32 %tmp7, ptr %tmp3, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i32_factor_3", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i32.3 = type { i32, i32, i32 }\n\ndefine void @i32_factor_3(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i32.3, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i32.3, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %i32.3, ptr %data, i64 %i, i32 2\n %tmp3 = load i32, ptr %tmp0, align 4\n %tmp4 = load i32, ptr %tmp1, align 4\n %tmp5 = load i32, ptr %tmp2, align 4\n store i32 %tmp3, ptr %tmp0, align 4\n store i32 %tmp4, ptr %tmp1, align 4\n store i32 %tmp5, ptr %tmp2, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f64_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f64.2 = type { double, double }\n\ndefine void @f64_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f64.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f64.2, ptr %data, i64 %i, i32 1\n %tmp2 = load double, ptr %tmp0, align 8\n %tmp3 = load double, ptr %tmp1, align 8\n store double %tmp2, ptr %tmp0, align 8\n store double %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f16_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f16.4 = type { half, half, half, half }\n\ndefine void @f16_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %f16.4, ptr %data, i64 %i, i32 3\n %tmp4 = load half, ptr %tmp0, align 2\n %tmp5 = load half, ptr %tmp1, align 2\n %tmp6 = load half, ptr %tmp2, align 2\n %tmp7 = load half, ptr %tmp3, align 2\n store half %tmp4, ptr %tmp0, align 2\n store half %tmp5, ptr %tmp1, align 2\n store half %tmp6, ptr %tmp2, align 2\n store half %tmp7, ptr %tmp3, align 2\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "i64_factor_2", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%i64.2 = type { i64, i64 }\n\ndefine void @i64_factor_2(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %i64.2, ptr %data, i64 %i, i32 1\n %tmp2 = load i64, ptr %tmp0, align 8\n %tmp3 = load i64, ptr %tmp1, align 8\n store i64 %tmp2, ptr %tmp0, align 8\n store i64 %tmp3, ptr %tmp1, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f64_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f64.4 = type { double, double, double, double }\n\ndefine void @f64_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %f64.4, ptr %data, i64 %i, i32 3\n %tmp4 = load double, ptr %tmp0, align 8\n %tmp5 = load double, ptr %tmp1, align 8\n %tmp6 = load double, ptr %tmp2, align 8\n %tmp7 = load double, ptr %tmp3, align 8\n store double %tmp4, ptr %tmp0, align 8\n store double %tmp5, ptr %tmp1, align 8\n store double %tmp6, ptr %tmp2, align 8\n store double %tmp7, ptr %tmp3, align 8\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "f32_factor_4", "test_body": "target datalayout = \"e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64\"\ntarget triple = \"thumbv8.1m.main-none-eabi\"\n\n%f32.4 = type { float, float, float, float }\n\ndefine void @f32_factor_4(ptr %data, i64 %n) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ]\n %tmp0 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 0\n %tmp1 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 1\n %tmp2 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 2\n %tmp3 = getelementptr inbounds %f32.4, ptr %data, i64 %i, i32 3\n %tmp4 = load float, ptr %tmp0, align 4\n %tmp5 = load float, ptr %tmp1, align 4\n %tmp6 = load float, ptr %tmp2, align 4\n %tmp7 = load float, ptr %tmp3, align 4\n store float %tmp4, ptr %tmp0, align 4\n store float %tmp5, ptr %tmp1, align 4\n store float %tmp6, ptr %tmp2, align 4\n store float %tmp7, ptr %tmp3, align 4\n %i.next = add nuw nsw i64 %i, 1\n %cond = icmp slt i64 %i.next, %n\n br i1 %cond, label %for.body, label %for.end\n\nfor.end: ; preds = %for.body\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+mve.fp\" }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll", "commands": [ "opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s" ], "tests": [ { "test_name": "dead_load", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n", "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) #1 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.exiting\n\nthen: ; preds = %loop.header\n %gep = getelementptr inbounds i32, ptr %b, i32 %iv\n store i1 false, ptr %a, align 1\n store i32 0, ptr %gep, align 4\n br label %loop.exiting\n\nloop.exiting: ; preds = %then, %loop.header\n %iv.next = add i32 %iv, 1\n %umax = tail call i16 @llvm.umax.i16(i16 %x, i16 111)\n %umax.ext = zext i16 %umax to i32\n %sub = sub i32 770, %umax.ext\n %ec = icmp slt i32 %iv, %sub\n br i1 %ec, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop.exiting\n br label %loop.header\n\nexit: ; preds = %loop.exiting\n br label %return\n\nreturn: ; preds = %exit\n ret i32 0\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\nattributes #1 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "gather_interleave_group_with_dead_insert_pos", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @gather_interleave_group_with_dead_insert_pos(i64 %N, ptr noalias %src, ptr noalias %dst) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ]\n %gep.src.0 = getelementptr i8, ptr %src, i64 %iv\n %l.dead = load i8, ptr %gep.src.0, align 1\n %iv.1 = add i64 %iv, 1\n %gep.src.1 = getelementptr i8, ptr %src, i64 %iv.1\n %l.1 = load i8, ptr %gep.src.1, align 1\n %ext = zext i8 %l.1 to i32\n %gep.dst = getelementptr i32, ptr %dst, i64 %iv\n store i32 %ext, ptr %gep.dst, align 4\n %iv.next = add nsw i64 %iv, 4\n %ec = icmp slt i64 %iv, %N\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_phi_in_latch_redundant", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_phi_in_latch_redundant(ptr %dst, i32 %a) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %not.a = xor i32 %a, -1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i32 [ %not.a, %then ], [ 0, %loop.header ]\n %gep = getelementptr i32, ptr %dst, i64 %iv\n store i32 %p, ptr %gep, align 4\n %iv.next = add i64 %iv, 9\n %ec = icmp slt i64 %iv, 322\n br i1 %ec, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "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 } ] }, { "file": "llvm/test/Transforms/LoopVectorize/SystemZ/mem-interleaving-costs-03.ll", "commands": [ "opt -mtriple=s390x-unknown-linux -mcpu=z16 -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-width=4 -disable-output < %s 2>&1" ], "tests": [ { "test_name": "fun", "test_body": "define noundef i32 @fun(i32 %argc, ptr nocapture readnone %argv) {\nentry:\n %l_4774.i = alloca [4 x [2 x i128]], align 8\n call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %l_4774.i)\n br label %for.cond4.preheader.i\n\nfor.cond4.preheader.i: ; preds = %for.cond4.preheader.i, %entry\n %indvars.iv8.i = phi i64 [ 0, %entry ], [ %indvars.iv.next9.i, %for.cond4.preheader.i ]\n %arrayidx10.i = getelementptr inbounds [4 x [2 x i128]], ptr %l_4774.i, i64 0, i64 %indvars.iv8.i, i64 0\n store i128 8721036757475490113, ptr %arrayidx10.i, align 8\n %arrayidx10.i.c = getelementptr inbounds [4 x [2 x i128]], ptr %l_4774.i, i64 0, i64 %indvars.iv8.i, i64 1\n store i128 8721036757475490113, ptr %arrayidx10.i.c, align 8\n %indvars.iv.next9.i = add nuw nsw i64 %indvars.iv8.i, 1\n %exitcond.not.i = icmp eq i64 %indvars.iv.next9.i, 4\n br i1 %exitcond.not.i, label %func_1.exit, label %for.cond4.preheader.i\n\nfunc_1.exit: ; preds = %for.cond4.preheader.i\n %arrayidx195.i = getelementptr inbounds [4 x [2 x i128]], ptr %l_4774.i, i64 0, i64 1\n %0 = load i128, ptr %arrayidx195.i, align 8\n %cmp200.i = icmp ne i128 %0, 0\n %conv202.i = zext i1 %cmp200.i to i64\n %call203.i = tail call i64 @safe_sub_func_int64_t_s_s(i64 noundef %conv202.i, i64 noundef 9139899272418802852)\n call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %l_4774.i)\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %func_1.exit\n br label %for.cond\n}\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0\n\ndeclare dso_local i64 @safe_sub_func_int64_t_s_s(i64, i64)\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using: 15106c26662a WITH commits from #107894 cherry-picked on top.\r\n```\r\n> git log --oneline\r\n2bfba9bc7d37 (HEAD -> main) !fixup add TODO\r\n28acd6af75ff Add initial loop-invariant code motion transform.\r\n15106c26662a (origin/main, origin/HEAD) [flang][runtime] Fix odd \"invalid descriptor\" runtime crash\r\n```\r\nTestcase:\r\n```c\r\nchar a;\r\nextern int b[];\r\nshort c;\r\nchar d[1];\r\nvoid checksum() {\r\n for (long e = 0; e < 3;)\r\n for (long f = 0; e < 3; e = 709692)\r\n for (; f < c; f += 4) {\r\n a = d[f];\r\n b[f] = d[f - 1];\r\n }\r\n}\r\n```\r\n`clang -march=rv64gcv -O3 red.c`\r\n\r\nTestcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @g(i64 %conv) #0 {\r\nentry:\r\n br label %for.body8.us23\r\n\r\nfor.body8.us23: ; preds = %for.body8.us23, %entry\r\n %f.121.us24 = phi i64 [ %add.us30, %for.body8.us23 ], [ 0, %entry ]\r\n %arrayidx.us25 = getelementptr [1 x i8], ptr null, i64 0, i64 %f.121.us24\r\n %0 = load i8, ptr %arrayidx.us25, align 1\r\n %sub.us26 = add i64 %f.121.us24, 1\r\n %arrayidx9.us27 = getelementptr [1 x i8], ptr null, i64 0, i64 %sub.us26\r\n %1 = load i8, ptr %arrayidx9.us27, align 1\r\n %conv10.us28 = zext i8 %1 to i32\r\n %arrayidx11.us29 = getelementptr [0 x i32], ptr null, i64 0, i64 %f.121.us24\r\n store i32 %conv10.us28, ptr null, align 4\r\n %add.us30 = add nsw i64 %f.121.us24, 4\r\n %cmp6.us31 = icmp slt i64 %f.121.us24, %conv\r\n br i1 %cmp6.us31, label %for.body8.us23, label %for.cond.cleanup.split.us\r\n\r\nfor.cond.cleanup.split.us: ; preds = %for.body8.us23\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt --passes loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7394: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt --passes loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"g\"\r\n #0 0x00005fabff5a9d80 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3072d80)\r\n #1 0x00005fabff5a718f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x307018f)\r\n #2 0x00005fabff5a72e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007fe3d2042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007fe3d20969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007fe3d20969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007fe3d20969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007fe3d2042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007fe3d20287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007fe3d202871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007fe3d2039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005fabfe550a26 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2019a26)\r\n#12 0x00005fabfe5678fb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20308fb)\r\n#13 0x00005fabfe56a911 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2033911)\r\n#14 0x00005fabfe56af87 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2033f87)\r\n#15 0x00005fabfd3adf96 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe76f96)\r\n#16 0x00005fabff3b51ef llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e7e1ef)\r\n#17 0x00005fabfd3b11c6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe7a1c6)\r\n#18 0x00005fabff3b357b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e7c57b)\r\n#19 0x00005fabfd3ad376 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe76376)\r\n#20 0x00005fabff3b40dd llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e7d0dd)\r\n#21 0x00005fabfcbd49db llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x69d9db)\r\n#22 0x00005fabfcbc6701 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x68f701)\r\n#23 0x00007fe3d2029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007fe3d2029e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007fe3d2029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005fabfcbbcc65 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x685c65)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/TTchhsf9h\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/107473\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
106641
https://github.com/llvm/llvm-project/issues/106641
crash
c8568f09577e9332d15edf98beb5376dc8d0672e
2024-08-29T23:08:58
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "f0e34f381866b82a26241f7e9aa5964f0dd11ebd", "components": [ "LoopVectorize" ], "bug_location_lineno": { "llvm/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": [ [ 7147, 7153 ], [ 7250, 7259 ], [ 7284, 7299 ], [ 7364, 7371 ] ], "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::computeBestVF", "LoopVectorizationPlanner::precomputeCosts", "planContainsAdditionalSimplifications" ], "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 f0e34f381866b82a26241f7e9aa5964f0dd11ebd Author: Florian Hahn <[email protected]> Date: Fri Aug 30 11:29:29 2024 +0100 [VPlan] Don't skip optimizable truncs in planContainsAdditionalSimps. A optimizable cast can also be removed by VPlan simplifications. Remove the restriction from planContainsAdditionalSimplifications, as this causes it to miss relevant simplifications, triggering false positives for the cost decision verification. Also adds debug output for printing additional cost-precomputations. Fixes https://github.com/llvm/llvm-project/issues/106641. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6babfd1eee91..fa05b8dd2242 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7147,7 +7147,12 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF, if (!OrigLoop->contains(CondI) || !CostCtx.SkipCostComputation.insert(CondI).second) continue; - Cost += CostCtx.getLegacyCost(CondI, VF); + InstructionCost CondICost = CostCtx.getLegacyCost(CondI, VF); + LLVM_DEBUG({ + dbgs() << "Cost of " << CondICost << " for VF " << VF + << ": exit condition instruction " << *CondI << "\n"; + }); + Cost += CondICost; for (Value *Op : CondI->operands()) { auto *OpI = dyn_cast<Instruction>(Op); if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) { @@ -7250,10 +7255,9 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, /// not have corresponding recipes in \p Plan and are not marked to be ignored /// in \p CostCtx. This means the VPlan contains simplification that the legacy /// cost-model did not account for. -static bool -planContainsAdditionalSimplifications(VPlan &Plan, ElementCount VF, - VPCostContext &CostCtx, Loop *TheLoop, - LoopVectorizationCostModel &CM) { +static bool planContainsAdditionalSimplifications(VPlan &Plan, + VPCostContext &CostCtx, + Loop *TheLoop) { // First collect all instructions for the recipes in Plan. auto GetInstructionForCost = [](const VPRecipeBase *R) -> Instruction * { if (auto *S = dyn_cast<VPSingleDefRecipe>(R)) @@ -7284,16 +7288,13 @@ planContainsAdditionalSimplifications(VPlan &Plan, ElementCount VF, // Return true if the loop contains any instructions that are not also part of // the VPlan or are skipped for VPlan-based cost computations. This indicates // that the VPlan contains extra simplifications. - return any_of( - TheLoop->blocks(), [&SeenInstrs, VF, &CostCtx, &CM](BasicBlock *BB) { - return any_of(*BB, [&SeenInstrs, VF, &CostCtx, &CM](Instruction &I) { - if (isa<PHINode>(&I)) - return false; - return !SeenInstrs.contains(&I) && - !CostCtx.skipCostComputation(&I, true) && - !CM.canTruncateToMinimalBitwidth(&I, VF); - }); - }); + return any_of(TheLoop->blocks(), [&SeenInstrs, &CostCtx](BasicBlock *BB) { + return any_of(*BB, [&SeenInstrs, &CostCtx](Instruction &I) { + if (isa<PHINode>(&I)) + return false; + return !SeenInstrs.contains(&I) && !CostCtx.skipCostComputation(&I, true); + }); + }); } #endif @@ -7364,8 +7365,7 @@ VectorizationFactor LoopVectorizationPlanner::computeBestVF() { precomputeCosts(BestPlan, BestFactor.Width, CostCtx); assert((BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), - BestFactor.Width, CostCtx, - OrigLoop, CM)) && + CostCtx, OrigLoop)) && " VPlan cost model and legacy cost model disagreed"); assert((BestFactor.Width.isScalar() || BestFactor.ScalarCost > 0) && "when vectorizing, the scalar cost must be computed.");
[ { "file": "llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-cost.ll", "commands": [ "opt -p loop-vectorize -mattr=+v -S %s" ], "tests": [ { "test_name": "truncate_to_i1_used_by_branch", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @truncate_to_i1_used_by_branch(i8 %x, ptr %dst) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %f.039 = phi i8 [ 0, %entry ], [ %add, %loop.latch ]\n %0 = or i8 23, %x\n %extract.t = trunc i8 %0 to i1\n br i1 %extract.t, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n store i8 0, ptr %dst, align 1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %add = add i8 %f.039, 1\n %conv = sext i8 %f.039 to i32\n %cmp = icmp slt i32 %conv, 1\n br i1 %cmp, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+64bit,+v,+zvl256b\" }\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_pr98413_sext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_sext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = sext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_pr98413_zext_removed", "test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine void @test_pr98413_zext_removed(ptr %src, ptr noalias %dst, i64 %x) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.src = getelementptr inbounds i16, ptr %src, i64 %iv\n %l = load i16, ptr %gep.src, align 8\n %ext.l = zext i16 %l to i64\n %and = and i64 %x, %ext.l\n %trunc.and = trunc i64 %and to i8\n %gep.dst = getelementptr inbounds i8, ptr %dst, i64 %iv\n store i8 %trunc.and, ptr %gep.dst, align 1\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv, 96\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.", "body": "Tested using c4906588ce47de33d59bcd95f3e82ce2c3e61c23\r\n\r\nTestcase:\r\n```c\r\n_Bool a;\r\nchar b;\r\nunsigned char c;\r\nvoid d(_Bool e[][6]) {\r\n for (signed char f = 0; f < c; f += 3)\r\n for (_Bool g = ({\r\n __typeof__(0) h = e[1][2];\r\n e[f][f] > h ?: h;\r\n });\r\n g; g = b)\r\n for (_Bool i = 0; i < (0 >= 0); i = 1)\r\n a = 0;\r\n}\r\n```\r\nhttps://godbolt.org/z/Eab8s5e1K\r\n\r\nReduced LLVM IR Testcase:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @d() #0 {\r\nentry:\r\n br label %for.body\r\n\r\nfor.cond.cleanup.loopexit: ; preds = %for.cond.cleanup14\r\n ret void\r\n\r\nfor.body: ; preds = %for.cond.cleanup14, %entry\r\n %f.039 = phi i8 [ %add, %for.cond.cleanup14 ], [ 0, %entry ]\r\n %0 = or i8 0, 0\r\n %extract.t = trunc i8 %0 to i1\r\n br i1 %extract.t, label %for.body22.lr.ph, label %for.cond.cleanup14\r\n\r\nfor.body22.lr.ph: ; preds = %for.body\r\n store i8 0, ptr null, align 1\r\n br label %for.cond.cleanup14\r\n\r\nfor.cond.cleanup14: ; preds = %for.body22.lr.ph, %for.body\r\n %add = add i8 %f.039, 1\r\n %conv = sext i8 %f.039 to i32\r\n %cmp = icmp slt i32 %conv, 1\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup.loopexit\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7365: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"d\"\r\n #0 0x000064cd5b412560 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301e560)\r\n #1 0x000064cd5b40f96f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x301b96f)\r\n #2 0x000064cd5b40fac5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000072ec5a042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000072ec5a0969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000072ec5a0969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000072ec5a0969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000072ec5a042476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000072ec5a0287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000072ec5a02871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000072ec5a039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000064cd5a3dd109 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe9109)\r\n#12 0x000064cd5a3f3ccb llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fffccb)\r\n#13 0x000064cd5a3f6ce1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2002ce1)\r\n#14 0x000064cd5a3f7357 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2003357)\r\n#15 0x000064cd592541b6 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe601b6)\r\n#16 0x000064cd5b21d41f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2941f)\r\n#17 0x000064cd59257346 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe63346)\r\n#18 0x000064cd5b21c19b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e2819b)\r\n#19 0x000064cd592535e6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5f5e6)\r\n#20 0x000064cd5b21a1dd llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e261dd)\r\n#21 0x000064cd58a7c106 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x688106)\r\n#22 0x000064cd58a6de91 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679e91)\r\n#23 0x000072ec5a029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x000072ec5a029e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x000072ec5a029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x000064cd58a64245 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x670245)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/EzdEYKW7c\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: #106417\r\n\r\ncc @fhahn", "author": "patrick-rivos", "labels": [ "vectorizers", "crash" ], "comments": [] }
true
null
120615
https://github.com/llvm/llvm-project/issues/120615
crash
e3fe41cdf5583d3a2f7454c76fa5cadccdccaf22
2024-12-19T18:18:18
[ "llvm/test/Analysis/ScalarEvolution" ]
{ "fix_commit": "f035351af785b7349ab7bcd55149c781ceca24cb", "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": [ [ 15765, 15770 ] ], "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::collectFromBlock" ], "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 f035351af785b7349ab7bcd55149c781ceca24cb Author: Julian Nagele <[email protected]> Date: Tue Dec 31 10:24:48 2024 +0100 [SCEV] Make sure starting block is marked as visited when recursively collecting loop guards. (#120749) When `collectFromBlock` is called without a predecessor (in particular for loops that don't have a unique predecessor outside the loop) we never start climbing the predecessor chain, and thus don't mark the starting block as visited. Fixes https://github.com/llvm/llvm-project/issues/120615. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 8ab56025546e..b5668a14a4a2 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -15765,6 +15765,7 @@ void ScalarEvolution::LoopGuards::collectFromBlock( // original header. // TODO: share this logic with isLoopEntryGuardedByCond. unsigned NumCollectedConditions = 0; + VisitedBlocks.insert(Block); std::pair<const BasicBlock *, const BasicBlock *> Pair(Pred, Block); for (; Pair.first; Pair = SE.getPredecessorWithUniqueSuccessorForBB(Pair.first)) {
[ { "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": "pr120615", "test_body": "define void @pr120615() {\nentry:\n br label %header\n\nbb: ; No predecessors!\n br label %header\n\nheader: ; preds = %header, %bb, %entry\n %0 = phi i32 [ %1, %header ], [ 0, %bb ], [ 0, %entry ]\n %1 = add i32 %0, 1\n %icmp = icmp slt i32 %0, 0\n br i1 %icmp, label %header, label %exit\n\nexit: ; preds = %header\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SCEV] Segfault in SCEV LoopGuards", "body": "For the following IR:\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 void @foo() {\n.split.us120:\n br label %.split.us120.split.split.us.split.split.us.split.split.us.split\n\n.split.us120.split.split.us.split.split.us.split.split.us.split: ; preds = %.noexc7.us.us.us.us.us, %.split.us120\n br label %.noexc7.us.us.us.us.us\n\n.lr.ph.us.us.us.us407: ; No predecessors!\n switch i32 0, label %.split142.us.split.us.split.us [\n i32 0, label %.split160.us.split.us.split.us\n i32 1, label %.noexc7.us.us.us.us.us\n ]\n\n.noexc7.us.us.us.us.us: ; preds = %.noexc7.us.us.us.us.us, %.lr.ph.us.us.us.us407, %.split.us120.split.split.us.split.split.us.split.split.us.split\n %0 = phi i32 [ %1, %.noexc7.us.us.us.us.us ], [ 0, %.lr.ph.us.us.us.us407 ], [ 0, %.split.us120.split.split.us.split.split.us.split.split.us.split ]\n %1 = add i32 %0, 1\n %.not.i3.us.us.us.us384.us = icmp slt i32 %0, 0\n br i1 %.not.i3.us.us.us.us384.us, label %.noexc7.us.us.us.us.us, label %.split.us120.split.split.us.split.split.us.split.split.us.split\n\n.split142.us.split.us.split.us: ; preds = %.lr.ph.us.us.us.us407\n ret void\n\n.split160.us.split.us.split.us: ; preds = %.lr.ph.us.us.us.us407\n ret void\n}\n```\n`opt` crashes when run using `-passes=nary-reassociate --scalar-evolution-use-expensive-range-sharpening`\n\ngodbolt: https://godbolt.org/z/xPv4TMMo8\n\nBacktrace (truncated due to length limits):\n```\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=nary-reassociate --scalar-evolution-use-expensive-range-sharpening <source>\n1.\tRunning pass \"function(nary-reassociate)\" on module \"<source>\"\n2.\tRunning pass \"nary-reassociate\" on function \"foo\"\n #0 0x0000000005257198 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5257198)\n #1 0x0000000005254b9c SignalHandler(int) Signals.cpp:0:0\n #2 0x00007f9ab9c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00000000051640cb llvm::hash_value(llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51640cb)\n #4 0x00000000051641a9 llvm::DenseMapInfo<llvm::APInt, void>::getHashValue(llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x51641a9)\n #5 0x0000000004ed726b bool llvm::DenseMapBase<llvm::DenseMap<llvm::APInt, std::unique_ptr<llvm::ConstantInt, std::default_delete<llvm::ConstantInt>>, llvm::DenseMapInfo<llvm::APInt, void>, llvm::detail::DenseMapPair<llvm::APInt, std::unique_ptr<llvm::ConstantInt, std::default_delete<llvm::ConstantInt>>>>, llvm::APInt, std::unique_ptr<llvm::ConstantInt, std::default_delete<llvm::ConstantInt>>, llvm::DenseMapInfo<llvm::APInt, void>, llvm::detail::DenseMapPair<llvm::APInt, std::unique_ptr<llvm::ConstantInt, std::default_delete<llvm::ConstantInt>>>>::LookupBucketFor<llvm::APInt>(llvm::APInt const&, llvm::detail::DenseMapPair<llvm::APInt, std::unique_ptr<llvm::ConstantInt, std::default_delete<llvm::ConstantInt>>>*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed726b)\n #6 0x0000000004edb996 llvm::ConstantInt::get(llvm::LLVMContext&, llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4edb996)\n #7 0x0000000004eeba30 llvm::ConstantInt::get(llvm::Type*, llvm::APInt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eeba30)\n #8 0x0000000004eb6172 llvm::ConstantFoldBinaryInstruction(unsigned int, llvm::Constant*, llvm::Constant*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4eb6172)\n #9 0x0000000004ee9f2e llvm::ConstantExpr::get(unsigned int, llvm::Constant*, llvm::Constant*, unsigned int, llvm::Type*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ee9f2e)\n #10 0x00000000049427fb llvm::ScalarEvolution::getNegativeSCEV(llvm::SCEV const*, llvm::SCEV::NoWrapFlags) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x49427fb)\n #11 0x00000000049429c4 llvm::ScalarEvolution::getMinusSCEV(llvm::SCEV const*, llvm::SCEV const*, llvm::SCEV::NoWrapFlags, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x49429c4)\n #12 0x0000000004950e7a llvm::ScalarEvolution::LoopGuards::collectFromBlock(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::BasicBlock const*, llvm::BasicBlock const*, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4950e7a)\n #13 0x00000000049524c2 llvm::ScalarEvolution::LoopGuards::collectFromPHI(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::PHINode const&, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, llvm::SmallDenseMap<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards, 4u, llvm::DenseMapInfo<llvm::BasicBlock const*, void>, llvm::detail::DenseMapPair<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards>>&, unsigned int)::'lambda'(unsigned int)::operator()(unsigned int) const ScalarEvolution.cpp:0:0\n #14 0x0000000004952702 llvm::ScalarEvolution::LoopGuards::collectFromPHI(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::PHINode const&, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, llvm::SmallDenseMap<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards, 4u, llvm::DenseMapInfo<llvm::BasicBlock const*, void>, llvm::detail::DenseMapPair<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards>>&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4952702)\n #15 0x0000000004951839 llvm::ScalarEvolution::LoopGuards::collectFromBlock(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::BasicBlock const*, llvm::BasicBlock const*, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4951839)\n #16 0x0000000004952c7d llvm::ScalarEvolution::applyLoopGuards(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4952c7d)\n #17 0x0000000004952fb0 llvm::ScalarEvolution::getRangeForAffineNoSelfWrappingAR(llvm::SCEVAddRecExpr const*, llvm::SCEV const*, unsigned int, llvm::ScalarEvolution::RangeSignHint) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4952fb0)\n #18 0x000000000492888d llvm::ScalarEvolution::getRangeRef(llvm::SCEV const*, llvm::ScalarEvolution::RangeSignHint, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x492888d)\n #19 0x0000000004942b52 llvm::ScalarEvolution::isKnownPredicateViaConstantRanges(llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4942b52)\n #20 0x0000000004942e18 llvm::ScalarEvolution::isKnownViaNonRecursiveReasoning(llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4942e18)\n #21 0x0000000004943799 llvm::ScalarEvolution::getMinMaxExpr(llvm::SCEVTypes, llvm::SmallVectorImpl<llvm::SCEV const*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4943799)\n #22 0x0000000004943f1a llvm::ScalarEvolution::getSMinExpr(llvm::SCEV const*, llvm::SCEV const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4943f1a)\n #23 0x0000000004951128 llvm::ScalarEvolution::LoopGuards::collectFromBlock(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::BasicBlock const*, llvm::BasicBlock const*, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4951128)\n...\n#255 0x00000000049524c2 llvm::ScalarEvolution::LoopGuards::collectFromPHI(llvm::ScalarEvolution&, llvm::ScalarEvolution::LoopGuards&, llvm::PHINode const&, llvm::SmallPtrSetImpl<llvm::BasicBlock const*>&, llvm::SmallDenseMap<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards, 4u, llvm::DenseMapInfo<llvm::BasicBlock const*, void>, llvm::detail::DenseMapPair<llvm::BasicBlock const*, llvm::ScalarEvolution::LoopGuards>>&, unsigned int)::'lambda'(unsigned int)::operator()(unsigned int) const ScalarEvolution.cpp:0:0\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\n\nStack exhaustion via some recursion error maybe?", "author": "danilaml", "labels": [ "llvm:SCEV", "crash-on-valid" ], "comments": [ { "author": "danilaml", "body": "@juliannagele possibly due to https://github.com/llvm/llvm-project/pull/113915 (from backtrace)" }, { "author": "fhahn", "body": "Likely the same as https://github.com/llvm/llvm-project/issues/120237" }, { "author": "juliannagele", "body": "Related, but slightly different, should be fixed here https://github.com/llvm/llvm-project/pull/120749." } ] }
true
null
121581
https://github.com/llvm/llvm-project/issues/121581
miscompilation
95c5c5d4badf7c2128d098be325356e15c2197be
2025-01-03T16:31:11
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "fac46469977da9c4e9c6eeaac21103c971190577", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 747, 752 ], [ 764, 770 ], [ 804, 810 ] ], "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::foldGEPICmp" ], "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 fac46469977da9c4e9c6eeaac21103c971190577 Author: Yingwei Zheng <[email protected]> Date: Sat Jan 4 17:23:57 2025 +0800 [InstCombine] Check no wrap flags before folding icmp of GEPs with same indices (#121628) Alive2: https://alive2.llvm.org/ce/z/Dr3Sbe Closes https://github.com/llvm/llvm-project/issues/121581. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index d6fdade25559..8b23583c5106 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -747,6 +747,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, ConstantExpr::getPointerBitCastOrAddrSpaceCast( cast<Constant>(RHS), Base->getType())); } else if (GEPOperator *GEPRHS = dyn_cast<GEPOperator>(RHS)) { + GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags(); + // If the base pointers are different, but the indices are the same, just // compare the base pointer. if (PtrBase != GEPRHS->getOperand(0)) { @@ -764,7 +766,8 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, // If all indices are the same, just compare the base pointers. Type *BaseType = GEPLHS->getOperand(0)->getType(); - if (IndicesTheSame && CmpInst::makeCmpResultType(BaseType) == I.getType()) + if (IndicesTheSame && + CmpInst::makeCmpResultType(BaseType) == I.getType() && CanFold(NW)) return new ICmpInst(Cond, GEPLHS->getOperand(0), GEPRHS->getOperand(0)); // If we're comparing GEPs with two base pointers that only differ in type @@ -804,7 +807,6 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, return transformToIndexedCompare(GEPLHS, RHS, Cond, DL, *this); } - GEPNoWrapFlags NW = GEPLHS->getNoWrapFlags() & GEPRHS->getNoWrapFlags(); if (GEPLHS->getNumOperands() == GEPRHS->getNumOperands() && GEPLHS->getSourceElementType() == GEPRHS->getSourceElementType()) { // If the GEPs only differ by one index, compare it.
[ { "file": "llvm/test/Transforms/InstCombine/icmp-gep.ll", "commands": [ "opt -passes=instcombine -S < %s" ], "tests": [ { "test_name": "pointer_icmp_aligned_with_offset_negative", "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 @pointer_icmp_aligned_with_offset_negative(ptr align 8 %a, ptr align 8 %a2) {\n %gep = getelementptr i8, ptr %a, i64 8\n %cmp = icmp eq ptr %gep, %a2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "gep_diff_base_same_indices_nuw_nusw", "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 @gep_diff_base_same_indices_nuw_nusw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "gep_diff_base_same_indices", "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 @gep_diff_base_same_indices(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr i8, ptr %x, i64 %z\n %gep2 = getelementptr i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "gep_diff_base_same_indices_nusw", "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 @gep_diff_base_same_indices_nusw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nusw i8, ptr %x, i64 %z\n %gep2 = getelementptr nusw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "gep_diff_base_same_indices_nuw", "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 @gep_diff_base_same_indices_nuw(ptr %x, ptr %y, i64 %z) {\n %gep1 = getelementptr nuw i8, ptr %x, i64 %z\n %gep2 = getelementptr nuw i8, ptr %y, i64 %z\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] Incorrect fold of the comparison of GEPs", "body": "Alive2: https://alive2.llvm.org/ce/z/HRsqeW\n```\ndefine i1 @test(ptr %x, ptr %y) {\n %gep1 = getelementptr i8, ptr %x, i32 1\n %gep2 = getelementptr i8, ptr %y, i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n```\n```\n\n----------------------------------------\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %gep1 = gep ptr %x, 1 x i32 1\n %gep2 = gep ptr %y, 1 x i32 1\n %cmp = icmp ult ptr %gep1, %gep2\n ret i1 %cmp\n}\n=>\ndefine i1 @test(ptr %x, ptr %y) {\n#0:\n %cmp = icmp ult ptr %x, %y\n ret i1 %cmp\n}\nTransformation doesn't verify!\n\nERROR: Value mismatch\n\nExample:\nptr %x = pointer(non-local, block_id=0, offset=-1) / Address=#xf\nptr %y = null\n\nSource:\nptr %gep1 = null\nptr %gep2 = pointer(non-local, block_id=0, offset=1) / Address=#x1\ni1 %cmp = #x1 (1)\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 1\talign: 2\talloc type: 0\talive: true\taddress: 2\nBlock 2 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 3\n\nTarget:\ni1 %cmp = #x0 (0)\nSource value: #x1 (1)\nTarget value: #x0 (0)\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
114191
https://github.com/llvm/llvm-project/issues/114191
miscompilation
e577f14b670ee2ae6bb717133310b215be4331b3
2024-10-30T07:41:28
[ "llvm/test/Transforms/InstCombine", "llvm/test/Transforms/InstSimplify" ]
{ "fix_commit": "a77dedcacb4c5eb221395b69877981dd6ad98989", "components": [ "IR", "InstCombine", "InstructionSimplify" ], "bug_location_lineno": { "llvm/lib/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": [ [ 102, 107 ] ], "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": [ [ 1095, 1113 ] ], "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": [ [ 902, 912 ] ], "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [ [ 1158, 1186 ], [ 1189, 1194 ], [ 2138, 2166 ] ], "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": [ "simplifyDivRem" ], "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": [ "llvm::ConstantFoldBinaryInstruction" ], "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": [ "InstCombinerImpl::commonIDivTransforms", "InstCombinerImpl::commonIRemTransforms", "foldIDivShl" ], "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 a77dedcacb4c5eb221395b69877981dd6ad98989 Author: Yingwei Zheng <[email protected]> Date: Fri Nov 1 22:56:22 2024 +0800 [InstSimplify][InstCombine][ConstantFold] Move vector div/rem by zero fold to InstCombine (#114280) Previously we fold `div/rem X, C` into `poison` if any element of the constant divisor `C` is zero or undef. However, it is incorrect when threading udiv over an vector select: https://alive2.llvm.org/ce/z/3Ninx5 ``` define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) { %sel = select <2 x i1> %x, <2 x i32> <i32 -1, i32 -1>, <2 x i32> <i32 0, i32 1> %div = udiv <2 x i32> <i32 42, i32 -7>, %sel ret <2 x i32> %div } ``` In this case, `threadBinOpOverSelect` folds `udiv <i32 42, i32 -7>, <i32 -1, i32 -1>` and `udiv <i32 42, i32 -7>, <i32 0, i32 1>` into `zeroinitializer` and `poison`, respectively. One solution is to introduce a new flag indicating that we are threading over a vector select. But it requires to modify both `InstSimplify` and `ConstantFold`. However, this optimization doesn't provide benefits to real-world programs: https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/IR/ConstantFold.cpp.html#L908 https://dtcxzyw.github.io/llvm-opt-benchmark/coverage/data/zyw/opt-ci/actions-runner/_work/llvm-opt-benchmark/llvm-opt-benchmark/llvm/llvm-project/llvm/lib/Analysis/InstructionSimplify.cpp.html#L1107 This patch moves the fold into InstCombine to avoid breaking numerous existing tests. Fixes #114191 and #113866 (only poison-safety issue). diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index d08be1e55c85..2cb2612bf611 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1095,19 +1095,6 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0, if (match(Op1, m_Zero())) return PoisonValue::get(Ty); - // If any element of a constant divisor fixed width vector is zero or undef - // the behavior is undefined and we can fold the whole op to poison. - auto *Op1C = dyn_cast<Constant>(Op1); - auto *VTy = dyn_cast<FixedVectorType>(Ty); - if (Op1C && VTy) { - unsigned NumElts = VTy->getNumElements(); - for (unsigned i = 0; i != NumElts; ++i) { - Constant *Elt = Op1C->getAggregateElement(i); - if (Elt && (Elt->isNullValue() || Q.isUndefValue(Elt))) - return PoisonValue::get(Ty); - } - } - // poison / X -> poison // poison % X -> poison if (isa<PoisonValue>(Op0)) diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 07dfbc41e79b..c2780faee403 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -902,11 +902,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, Constant *ExtractIdx = ConstantInt::get(Ty, i); Constant *LHS = ConstantExpr::getExtractElement(C1, ExtractIdx); Constant *RHS = ConstantExpr::getExtractElement(C2, ExtractIdx); - - // If any element of a divisor vector is zero, the whole op is poison. - if (Instruction::isIntDivRem(Opcode) && RHS->isNullValue()) - return PoisonValue::get(VTy); - Constant *Res = ConstantExpr::isDesirableBinOp(Opcode) ? ConstantExpr::get(Opcode, LHS, RHS) : ConstantFoldBinaryInstruction(Opcode, LHS, RHS); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 7a060cdab2d3..adbd9186c59c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -102,6 +102,7 @@ public: Instruction *visitSRem(BinaryOperator &I); Instruction *visitFRem(BinaryOperator &I); bool simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I); + Instruction *commonIDivRemTransforms(BinaryOperator &I); Instruction *commonIRemTransforms(BinaryOperator &I); Instruction *commonIDivTransforms(BinaryOperator &I); Instruction *visitUDiv(BinaryOperator &I); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index b9c165da906d..f85a3c936513 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1158,29 +1158,39 @@ static Value *foldIDivShl(BinaryOperator &I, InstCombiner::BuilderTy &Builder) { return nullptr; } -/// This function implements the transforms common to both integer division -/// instructions (udiv and sdiv). It is called by the visitors to those integer -/// division instructions. -/// Common integer divide transforms -Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) { - if (Instruction *Phi = foldBinopWithPhiOperands(I)) - return Phi; - +/// Common integer divide/remainder transforms +Instruction *InstCombinerImpl::commonIDivRemTransforms(BinaryOperator &I) { + assert(I.isIntDivRem() && "Unexpected instruction"); Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - bool IsSigned = I.getOpcode() == Instruction::SDiv; + + // If any element of a constant divisor fixed width vector is zero or undef + // the behavior is undefined and we can fold the whole op to poison. + auto *Op1C = dyn_cast<Constant>(Op1); Type *Ty = I.getType(); + auto *VTy = dyn_cast<FixedVectorType>(Ty); + if (Op1C && VTy) { + unsigned NumElts = VTy->getNumElements(); + for (unsigned i = 0; i != NumElts; ++i) { + Constant *Elt = Op1C->getAggregateElement(i); + if (Elt && (Elt->isNullValue() || isa<UndefValue>(Elt))) + return replaceInstUsesWith(I, PoisonValue::get(Ty)); + } + } + + if (Instruction *Phi = foldBinopWithPhiOperands(I)) + return Phi; // The RHS is known non-zero. if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I)) return replaceOperand(I, 1, V); - // Handle cases involving: [su]div X, (select Cond, Y, Z) - // This does not apply for fdiv. + // Handle cases involving: div/rem X, (select Cond, Y, Z) if (simplifyDivRemOfSelectWithZeroOp(I)) return &I; // If the divisor is a select-of-constants, try to constant fold all div ops: - // C / (select Cond, TrueC, FalseC) --> select Cond, (C / TrueC), (C / FalseC) + // C div/rem (select Cond, TrueC, FalseC) --> select Cond, (C div/rem TrueC), + // (C div/rem FalseC) // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds. if (match(Op0, m_ImmConstant()) && match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) { @@ -1189,6 +1199,21 @@ Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) { return R; } + return nullptr; +} + +/// This function implements the transforms common to both integer division +/// instructions (udiv and sdiv). It is called by the visitors to those integer +/// division instructions. +/// Common integer divide transforms +Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) { + if (Instruction *Res = commonIDivRemTransforms(I)) + return Res; + + Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); + bool IsSigned = I.getOpcode() == Instruction::SDiv; + Type *Ty = I.getType(); + const APInt *C2; if (match(Op1, m_APInt(C2))) { Value *X; @@ -2138,29 +2163,11 @@ static Instruction *simplifyIRemMulShl(BinaryOperator &I, /// remainder instructions. /// Common integer remainder transforms Instruction *InstCombinerImpl::commonIRemTransforms(BinaryOperator &I) { - if (Instruction *Phi = foldBinopWithPhiOperands(I)) - return Phi; + if (Instruction *Res = commonIDivRemTransforms(I)) + return Res; Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); - // The RHS is known non-zero. - if (Value *V = simplifyValueKnownNonZero(I.getOperand(1), *this, I)) - return replaceOperand(I, 1, V); - - // Handle cases involving: rem X, (select Cond, Y, Z) - if (simplifyDivRemOfSelectWithZeroOp(I)) - return &I; - - // If the divisor is a select-of-constants, try to constant fold all rem ops: - // C % (select Cond, TrueC, FalseC) --> select Cond, (C % TrueC), (C % FalseC) - // TODO: Adapt simplifyDivRemOfSelectWithZeroOp to allow this and other folds. - if (match(Op0, m_ImmConstant()) && - match(Op1, m_Select(m_Value(), m_ImmConstant(), m_ImmConstant()))) { - if (Instruction *R = FoldOpIntoSelect(I, cast<SelectInst>(Op1), - /*FoldWithMultiUse*/ true)) - return R; - } - if (isa<Constant>(Op1)) { if (Instruction *Op0I = dyn_cast<Instruction>(Op0)) { if (SelectInst *SI = dyn_cast<SelectInst>(Op0I)) {
[ { "file": "llvm/test/Transforms/InstCombine/div.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "udiv_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sdiv_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @sdiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = sdiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "udiv_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @udiv_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = udiv <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/rem.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "urem_constant_dividend_select_of_constants_divisor_vec_ub1", "test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec_ub1(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 0, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "urem_constant_dividend_select_of_constants_divisor_vec", "test_body": "define <2 x i8> @urem_constant_dividend_select_of_constants_divisor_vec(i1 %b) {\n %s = select i1 %b, <2 x i8> <i8 12, i8 -5>, <2 x i8> <i8 -4, i8 4>\n %r = urem <2 x i8> <i8 42, i8 -42>, %s\n ret <2 x i8> %r\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/vector-udiv.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "vec_select_udiv_poison", "test_body": "define <2 x i32> @vec_select_udiv_poison(<2 x i1> %x) {\n %sel = select <2 x i1> %x, <2 x i32> splat (i32 -1), <2 x i32> <i32 0, i32 1>\n %div = udiv <2 x i32> <i32 42, i32 -7>, %sel\n ret <2 x i32> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_v4i32_zext_shl_const_pow2", "test_body": "define <4 x i32> @test_v4i32_zext_shl_const_pow2(<4 x i32> %a0, <4 x i16> %a1) {\n %1 = shl <4 x i16> <i16 4, i16 8, i16 16, i16 32>, %a1\n %2 = zext <4 x i16> %1 to <4 x i32>\n %3 = udiv <4 x i32> %a0, %2\n ret <4 x i32> %3\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstSimplify/div.ll", "commands": [ "opt < %s -passes=instsimplify -S" ], "tests": [ { "test_name": "udiv_zero_elt_vec", "test_body": "define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sdiv_zero_elt_vec", "test_body": "define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "udiv_poison_elt_vec", "test_body": "define <2 x i8> @udiv_poison_elt_vec(<2 x i8> %x) {\n %div = udiv <2 x i8> %x, <i8 poison, i8 42>\n ret <2 x i8> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sdiv_zero_elt_vec_constfold", "test_body": "define <2 x i8> @sdiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = sdiv <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sdiv_poison_elt_vec", "test_body": "define <2 x i8> @sdiv_poison_elt_vec(<2 x i8> %x) {\n %div = sdiv <2 x i8> %x, <i8 -42, i8 poison>\n ret <2 x i8> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "udiv_zero_elt_vec_constfold", "test_body": "define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {\n %div = udiv <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %div\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "zero_dividend_vector_poison_elt", "test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = sdiv <2 x i32> <i32 0, i32 poison>, %A\n ret <2 x i32> %B\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstSimplify/rem.ll", "commands": [ "opt < %s -passes=instsimplify -S" ], "tests": [ { "test_name": "srem_zero_elt_vec_constfold", "test_body": "define <2 x i8> @srem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = srem <2 x i8> <i8 1, i8 2>, <i8 0, i8 -42>\n ret <2 x i8> %rem\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "urem_zero_elt_vec", "test_body": "define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 0, i8 42>\n ret <2 x i8> %rem\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "urem_zero_elt_vec_constfold", "test_body": "define <2 x i8> @urem_zero_elt_vec_constfold(<2 x i8> %x) {\n %rem = urem <2 x i8> <i8 1, i8 2>, <i8 42, i8 0>\n ret <2 x i8> %rem\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "srem_undef_elt_vec", "test_body": "define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 undef>\n ret <2 x i8> %rem\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "urem_undef_elt_vec", "test_body": "define <2 x i8> @urem_undef_elt_vec(<2 x i8> %x) {\n %rem = urem <2 x i8> %x, <i8 undef, i8 42>\n ret <2 x i8> %rem\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "zero_dividend_vector_poison_elt", "test_body": "define <2 x i32> @zero_dividend_vector_poison_elt(<2 x i32> %A) {\n %B = urem <2 x i32> <i32 poison, i32 0>, %A\n ret <2 x i32> %B\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "srem_zero_elt_vec", "test_body": "define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {\n %rem = srem <2 x i8> %x, <i8 -42, i8 0>\n ret <2 x i8> %rem\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] miscompilation of `or` of vectors", "body": "Alive2 report: https://alive2.llvm.org/ce/z/LyM8sY\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = udiv <2 x i32> { 42, 4294967289 }, %#1\r\n ret <2 x i32> %#2\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.3(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 0, 0 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #x00000000 (0), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #x00000000 (0), #x00000000 (0) >\r\n\r\n\r\n----------------------------------------\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n %sext = sext <2 x i1> %y to <2 x i32>\r\n %#1 = or <2 x i32> %sext, { 0, 1 }\r\n %#2 = sdiv <2 x i32> { 42, 4294967289 }, %#1\r\n %#3 = udiv exact <2 x i32> %#2, %#2\r\n %#4 = or <2 x i32> %#2, %#2\r\n ret <2 x i32> %#4\r\n}\r\n=>\r\ndefine <2 x i32> @or_sext_to_sel_constant_vec.2(<2 x i1> %y) {\r\n#0:\r\n ret <2 x i32> { 4294967254, 7 }\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n<2 x i1> %y = < #x1 (1), #x0 (0) >\r\n\r\nSource:\r\n<2 x i32> %sext = < #xffffffff (4294967295, -1), #x00000000 (0) >\r\n<2 x i32> %#1 = < #xffffffff (4294967295, -1), #x00000001 (1) >\r\n<2 x i32> %#2 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n<2 x i32> %#3 = < #x00000001 (1), #x00000001 (1) >\r\n<2 x i32> %#4 = < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\n\r\nTarget:\r\nSource value: < #xffffffd6 (4294967254, -42), #xfffffff9 (4294967289, -7) >\r\nTarget value: < #xffffffd6 (4294967254, -42), #x00000007 (7) >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 2 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:instcombine", "llvm:analysis" ], "comments": [ { "author": "dtcxzyw", "body": "@bongjunj Feel free to ping me if you find new InstCombine miscompilation bugs without involving undef values/NaN payloads." }, { "author": "dtcxzyw", "body": "https://github.com/llvm/llvm-project/blob/eac2c182c6f852fc187af9952250a43d6fb17b28/llvm/lib/Analysis/InstructionSimplify.cpp#L1098-L1109\r\n\r\nWe cannot do this simplification when threading udiv over selects.\r\n " } ] }
true
null
80597
https://github.com/llvm/llvm-project/issues/80597
crash
8f4d8945536e9fc45db0e349b91c2f4b3a9cae29
2024-02-04T14:06:35
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "cb8d83a77c25e529f58eba17bb1ec76069a04e90", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 802, 807 ] ], "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 cb8d83a77c25e529f58eba17bb1ec76069a04e90 Author: Yingwei Zheng <[email protected]> Date: Tue Feb 6 01:29:38 2024 +0800 [InstCombine] Fix assertion failure in issue80597 (#80614) The assertion in #80597 failed when we were trying to compute known bits of a value in an unreachable BB. https://github.com/llvm/llvm-project/blob/859b09da08c2a47026ba0a7d2f21b7dca705864d/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L749-L810 In this case, `SignBits` is 30 (deduced from instr info), but `Known` is `10000101010111010011110101000?0?00000000000000000000000000000000` (deduced from dom cond). Setting high bits of `lshr Known, 1` will lead to conflict. This patch masks out high bits of `Known.Zero` to address this problem. Fixes #80597. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index a8a5f9831e15..79873a9b4cbb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -802,6 +802,9 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask, return InsertNewInstWith(LShr, I->getIterator()); } else if (Known.One[BitWidth-ShiftAmt-1]) { // New bits are known one. Known.One |= HighBits; + // SignBits may be out-of-sync with Known.countMinSignBits(). Mask out + // high bits of Known.Zero to avoid conflicts. + Known.Zero &= ~HighBits; } } else { computeKnownBits(I, Known, Depth, CxtI);
[ { "file": "llvm/test/Transforms/InstCombine/pr80597.ll", "commands": [ "opt -S -passes=instcombine < %s" ], "tests": [ { "test_name": "pr80597", "test_body": "define i64 @pr80597(i1 %cond) {\nentry:\n %add = select i1 %cond, i64 0, i64 4294967293\n %add8 = shl i64 %add, 32\n %sext1 = add i64 %add8, 8836839514384105472\n %cmp = icmp ult i64 %sext1, -34359738368\n br i1 %cmp, label %if.then, label %if.else\n\nif.else: ; preds = %entry\n %sext2 = or i64 %add8, 8836839522974040064\n %ashr = ashr i64 %sext2, 1\n ret i64 %ashr\n\nif.then: ; preds = %entry\n ret i64 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "llvm crash: Assertion `!LHSKnown.hasConflict() && \"Bits known to be one AND zero?\"' failed.", "body": "llvm crashes in `instcombine`\r\n\r\nBisected to d77067d08a3f56dc2d0e6c95bd2852c943df743a, which was committed by @nikic \r\n\r\nCompiler explorer: https://godbolt.org/z/e4jrvf5Wr\r\n\r\n```console\r\n% cat reduced.ll\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main(i1 %.b.i) {\r\nentry:\r\n %add.i = select i1 %.b.i, i64 0, i64 4294967293\r\n %add8.i = shl i64 %add.i, 32\r\n %sext.2.i = add i64 %add8.i, 8836839514384105472\r\n %cmp11.2.i = icmp ult i64 %sext.2.i, -34359738368\r\n br i1 %cmp11.2.i, label %return.loopexit.i, label %for.inc.2.i\r\n\r\nfor.inc.2.i: ; preds = %entry\r\n %sext.4.i = or i64 %add8.i, 8836839522974040064\r\n %conv9.4.i = ashr i64 %sext.4.i, 1\r\n %cmp11.4.i = icmp ult i64 %conv9.4.i, 0\r\n br i1 %cmp11.4.i, label %return.loopexit.i, label %return.loopexit.i\r\n\r\nreturn.loopexit.i: ; preds = %for.inc.2.i, %for.inc.2.i, %entry\r\n ret i32 0\r\n}\r\n%\r\n% opt -disable-output -passes=instcombine reduced.ll\r\nopt: /tmp/tmpzoi34eaf/tmporhhh5ti/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp:246: llvm::Value* llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Value*, llvm::APInt, llvm::KnownBits&, unsigned int, llvm::Instruction*): Assertion `!LHSKnown.hasConflict() && \"Bits known to be one AND zero?\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt -disable-output -passes=instcombine reduced.ll\r\n #0 0x00007f7698f4558f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x93858f)\r\n #1 0x00007f7698f42ab4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7698222090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)\r\n #3 0x00007f769822200b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007f7698201859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007f7698201729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007f7698201729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007f7698212fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x00007f769a44445d llvm::InstCombinerImpl::SimplifyDemandedUseBits(llvm::Value*, llvm::APInt, llvm::KnownBits&, unsigned int, llvm::Instruction*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1e3745d)\r\n #9 0x00007f769a444d25 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&, llvm::KnownBits&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1e37d25)\r\n#10 0x00007f769a4459c5 llvm::InstCombinerImpl::SimplifyDemandedInstructionBits(llvm::Instruction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1e389c5)\r\n#11 0x00007f769a38cdc3 llvm::InstCombinerImpl::visitOr(llvm::BinaryOperator&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1d7fdc3)\r\n#12 0x00007f769a3537b1 llvm::InstCombinerImpl::run() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1d467b1)\r\n#13 0x00007f769a355002 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, llvm::LoopInfo*, llvm::InstCombineOptions const&) (.isra.0) InstructionCombining.cpp:0:0\r\n#14 0x00007f769a355fbb llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x1d48fbb)\r\n#15 0x00007f769bea5916 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x3898916)\r\n#16 0x00007f769916239d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0xb5539d)\r\n#17 0x00007f769be9e506 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x3891506)\r\n#18 0x00007f7699160c2d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0xb53c2d)\r\n#19 0x00007f769bea5556 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0x3898556)\r\n#20 0x00007f769915eb5d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/../lib/libLLVM-18git.so+0xb51b5d)\r\n#21 0x000055c7b779e395 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt+0x26395)\r\n#22 0x000055c7b7791e8a main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt+0x19e8a)\r\n#23 0x00007f7698203083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#24 0x000055c7b7792a5e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-d77067d08a3f56dc2d0e6c95bd2852c943df743a/bin/opt+0x1aa5e)\r\n[1] 880216 abort -disable-output -passes=instcombine reduced.ll\r\n%\r\n```\r\n\r\nThe above test case was reduced from\r\n```C\r\nlong a, i;\r\nstatic long b = -4;\r\nchar c;\r\nint d;\r\nstatic int *e = &d, *h = &d;\r\nstatic long *f = &b, *g = &b;\r\nint j() {\r\n for (; a;) {\r\n c = 0;\r\n for (; c <= 6; c++) {\r\n unsigned long k = 1;\r\n i = -8;\r\n *h = i >= (int)k + (int)*f + c + 2057487030 + k;\r\n if (*e)\r\n break;\r\n }\r\n return 0;\r\n }\r\n *g = 0;\r\n return 0;\r\n}\r\nint main() { j(); }\r\n```", "author": "shao-hua-li", "labels": [ "release:backport", "llvm:instcombine", "crash-on-valid" ], "comments": [ { "author": "dtcxzyw", "body": "Minimal reproduction: https://godbolt.org/z/5bzaqP65P" }, { "author": "dtcxzyw", "body": "Reopen this issue to backport the fix to the 18.X release.\r\n" } ] }
true
null
111040
https://github.com/llvm/llvm-project/issues/111040
crash
b3e0bd3d284dec705386b1efcae40dd51b763010
2024-10-03T18:42:52
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "45b526afa26e76e0c351e947ac8f0e4b55aa760b", "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": [ [ 6196, 6206 ] ], "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::setVectorizedCallDecision" ], "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 45b526afa26e76e0c351e947ac8f0e4b55aa760b Author: Florian Hahn <[email protected]> Date: Sun Oct 6 10:34:37 2024 +0100 [LV] Honor uniform-after-vectorization in setVectorizedCallDecision. The legacy cost model always computes the cost for uniforms as cost of VF = 1, but VPWidenCallRecipes would be created, as setVectorizedCallDecisions would not consider uniform calls. Fix setVectorizedCallDecision to set to Scalarize, if the call is uniform-after-vectorization. This fixes a bug in VPlan construction uncovered by the VPlan-based cost model. Fixes https://github.com/llvm/llvm-project/issues/111040. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6e082b1c134d..35c042b3ab7f 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6196,11 +6196,12 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) { getScalarizationOverhead(CI, VF, CostKind); ScalarCost = ScalarCallCost * VF.getKnownMinValue() + ScalarizationCost; - // Honor ForcedScalars decision. + // Honor ForcedScalars and UniformAfterVectorization decisions. // TODO: For calls, it might still be more profitable to widen. Use // VPlan-based cost model to compare different options. - if (VF.isVector() && ForcedScalar != ForcedScalars.end() && - ForcedScalar->second.contains(CI)) { + if (VF.isVector() && ((ForcedScalar != ForcedScalars.end() && + ForcedScalar->second.contains(CI)) || + isUniformAfterVectorization(CI, VF))) { setCallWideningDecision(CI, VF, CM_Scalarize, nullptr, Intrinsic::not_intrinsic, std::nullopt, ScalarCost);
[ { "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, 0\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 } ] } ]
{ "title": "[clang] Assertion failed in LoopVectorize.cpp:7401", "body": "When I compiled the code with -O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\nstatic uint8_t b = 188;\r\nvoid c();\r\nlong d(int e, int p2, short j) {\r\n long f = 0, a = 1;\r\n unsigned long g;\r\n int h;\r\n if (e < 0 || j < 0)\r\n return 1;\r\n h = 0;\r\n for (; h < p2; h++) {\r\n a *= j + 1;\r\n g = e * a;\r\n f += g % (j + 1);\r\n }\r\n if (f < 0)\r\n return 0;\r\n return f;\r\n}\r\nvoid i();\r\nint64_t k() {\r\n uint32_t l[][8][10] = {0, 4, 7, 1, 4, 3446557846};\r\n int64_t m[10];\r\n int h;\r\n for (h = 0; c + h < 10; h++)\r\n m[(int)d(5, l[0][0][5] - 3446557842, b - 187) + h] = 1;\r\n i(m);\r\n uint8_t *n = &b;\r\n uint8_t **o;\r\n o[0] = &n;\r\n}\r\n```\r\n\r\nThe crash is:\r\n```\r\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7401: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n```\r\n\r\nDetails can be found here: https://godbolt.org/z/hqP8vMG7b\r\n", "author": "cardigan1008", "labels": [ "regression", "vectorizers", "crash" ], "comments": [ { "author": "shafik", "body": "This is a regression in trunk: https://godbolt.org/z/a53x7oxhq" } ] }
true
null
91434
https://github.com/llvm/llvm-project/issues/91434
crash
932f0de43a9e334e161a69a50bd6b01cd51e238e
2024-05-08T06:10:09
[ "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "83d9aa27680b6a7f3556fcf13ada70b4be95bab2", "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": [ [ 171, 176 ] ], "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 83d9aa27680b6a7f3556fcf13ada70b4be95bab2 Author: Pietro Ghiglio <[email protected]> Date: Wed May 15 15:03:21 2024 +0200 [VPlan] Add scalar inferencing support for addrspace cast (#92107) Fixes https://github.com/llvm/llvm-project/issues/91434 PR: https://github.com/llvm/llvm-project/pull/92107 diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp index 5f93339083f0..efe8c21874a3 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp @@ -171,6 +171,7 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPReplicateRecipe *R) { case Instruction::ICmp: case Instruction::FCmp: return IntegerType::get(Ctx, 1); + case Instruction::AddrSpaceCast: case Instruction::Alloca: case Instruction::BitCast: case Instruction::Trunc:
[ { "file": "llvm/test/Transforms/LoopVectorize/as_cast.ll", "commands": [ "opt -passes=loop-vectorize %s -force-vector-width=1 -force-vector-interleave=2 -S -o -" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @foo(ptr addrspace(1) %in) {\nentry:\n br label %loop\n\nloop:\n %iter = phi i64 [ %next, %loop ], [ 0, %entry ]\n %ascast = addrspacecast ptr addrspace(1) %in to ptr\n %next = add i64 %iter, 1\n %arrayidx = getelementptr inbounds i64, ptr %ascast, i64 %next\n store i64 %next, ptr %arrayidx, align 4\n\n; check that we find the two interleaved blocks with ascast, gep and store:\n\n\n %cmp = icmp eq i64 %next, 7\n br i1 %cmp, label %exit, label %loop\n\n; check that we branch to the exit block\n\nexit:\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[Loop Vectorizer] Unhandled opcode UNREACHABLE executed at llvm/llvm-project/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp:208!", "body": "```\r\nopt -passes=loop-vectorize before-loop-vectorize.ll\r\n\r\nUnhandled opcode\r\nUNREACHABLE executed at /llvm/llvm-project/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp:208!\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: /llvm/llvm-project/build/bin/opt -passes=loop-vectorize before-loop-vectorize.ll\r\n #0 0x0000000003167161 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/llvm/llvm-project/build/bin/opt+0x3167161)\r\n #1 0x00000000031646c4 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fcb77b7bdb0 __restore_rt (/lib64/libc.so.6+0x59db0)\r\n #3 0x00007fcb77bc842c __pthread_kill_implementation (/lib64/libc.so.6+0xa642c)\r\n #4 0x00007fcb77b7bd06 gsignal (/lib64/libc.so.6+0x59d06)\r\n #5 0x00007fcb77b4e7d3 abort (/lib64/libc.so.6+0x2c7d3)\r\n #6 0x00000000030ac16a (/llvm/llvm-project/build/bin/opt+0x30ac16a)\r\n #7 0x00000000022ffc8d llvm::VPTypeAnalysis::inferScalarTypeForRecipe(llvm::VPReplicateRecipe const*) (/llvm/llvm-project/build/bin/opt+0x22ffc8d)\r\n #8 0x00000000022ff04c llvm::VPTypeAnalysis::inferScalarType(llvm::VPValue const*) (/llvm/llvm-project/build/bin/opt+0x22ff04c)\r\n #9 0x00000000021cb7f4 llvm::InnerLoopVectorizer::scalarizeInstruction(llvm::Instruction const*, llvm::VPReplicateRecipe*, llvm::VPIteration const&, llvm::VPTransformState&) (/llvm/llvm-project/build/bin/opt+0x21cb7f4)\r\n#10 0x00000000021cecb5 llvm::VPReplicateRecipe::execute(llvm::VPTransformState&) (/llvm/llvm-project/build/bin/opt+0x21cecb5)\r\n#11 0x00000000022f834f llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22f834f)\r\n#12 0x00000000022f0130 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22f0130)\r\n#13 0x00000000022f03d8 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22f03d8)\r\n#14 0x00000000022fb806 llvm::VPlan::execute(llvm::VPTransformState*) (/llvm/llvm-project/build/bin/opt+0x22fb806)\r\n#15 0x00000000021e983b 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*) (/llvm/llvm-project/build/bin/opt+0x21e983b)\r\n#16 0x00000000021fbbe0 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/llvm/llvm-project/build/bin/opt+0x21fbbe0)\r\n#17 0x00000000021fde5e 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*) (/llvm/llvm-project/build/bin/opt+0x21fde5e)\r\n#18 0x00000000021fef78 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x21fef78)\r\n#19 0x0000000001125c8e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x1125c8e)\r\n#20 0x0000000002f8671a llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x2f8671a)\r\n#21 0x000000000082c95e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/llvm/llvm-project/build/bin/opt+0x82c95e)\r\n#22 0x0000000002f853cd llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/llvm/llvm-project/build/bin/opt+0x2f853cd)\r\n#23 0x000000000082da6e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/llvm/llvm-project/build/bin/opt+0x82da6e)\r\n#24 0x0000000002f832cc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/llvm/llvm-project/build/bin/opt+0x2f832cc)\r\n#25 0x00000000007a0d5d 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/llvm-project/build/bin/opt+0x7a0d5d)\r\n#26 0x0000000000793a7c optMain (/llvm/llvm-project/build/bin/opt+0x793a7c)\r\n#27 0x00007fcb77b66e50 __libc_start_call_main (/lib64/libc.so.6+0x44e50)\r\n#28 0x00007fcb77b66efc __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x44efc)\r\n#29 0x0000000000789e15 _start (/llvm/llvm-project/build/bin/opt+0x789e15)\r\nAborted (core dumped)\r\n```\r\nInput IR file before-loop-vectorize.ll is:\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\n%\"class.sycl::_V1::range\" = type { %\"class.sycl::_V1::detail::array\" }\r\n%\"class.sycl::_V1::detail::array\" = type { [1 x i64] }\r\n\r\n$_ZTSN4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EE = comdat any\r\n\r\n$_ZTSZZ12foo_parallelRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlNS0_2idILi1EEEE_ = comdat any\r\n\r\n$_ZTSZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlvE_ = comdat any\r\n\r\n; Function Attrs: convergent norecurse nounwind\r\ndefine weak_odr dso_local spir_kernel void @_ZTSN4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EE(ptr noundef byval(%\"class.sycl::_V1::range\") align 8 %_arg_UserRange, ptr addrspace(1) noundef align 4 %_arg_acc, ptr noundef byval(%\"class.sycl::_V1::range\") align 8 %_arg_acc3) local_unnamed_addr #0 comdat !srcloc !7 !kernel_arg_buffer_location !8 !kernel_arg_runtime_aligned !9 !kernel_arg_exclusive_ptr !9 !sycl_fixed_targets !10 !sycl_kernel_omit_args !11 {\r\nentry:\r\n %0 = load i64, ptr %_arg_UserRange, align 8\r\n %agg.tmp7.sroa.0.0.copyload = load i64, ptr %_arg_acc3, align 8\r\n %add.ptr.i = getelementptr inbounds float, ptr addrspace(1) %_arg_acc, i64 %agg.tmp7.sroa.0.0.copyload\r\n %call.i = tail call i64 @_Z21__spirv_WorkgroupId_xv() #5, !noalias !12\r\n %call1.i = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !12\r\n %mul.i = mul i64 %call1.i, %call.i\r\n %call2.i = tail call i64 @_Z27__spirv_LocalInvocationId_xv() #5, !noalias !12\r\n %add.i = add i64 %mul.i, %call2.i\r\n %call3.i = tail call i64 @_Z22__spirv_GlobalOffset_xv() #5, !noalias !12\r\n %add4.i = add i64 %add.i, %call3.i\r\n %call.i1 = tail call i64 @_Z23__spirv_NumWorkgroups_xv() #5, !noalias !12\r\n %call1.i2 = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !12\r\n %mul.i3 = mul i64 %call1.i2, %call.i1\r\n %call.i.i.i9.i.i = tail call noundef i64 @_Z22__spirv_GlobalOffset_xv() #6, !noalias !12\r\n %cmp6.not.i.not.i = icmp ult i64 %add4.i, %0\r\n br i1 %cmp6.not.i.not.i, label %for.body.i.preheader, label %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit\r\n\r\nfor.body.i.preheader: ; preds = %entry\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %for.body.i.preheader, %for.body.i\r\n %Gen.sroa.0.019.i = phi i64 [ %add.i.i, %for.body.i ], [ %add4.i, %for.body.i.preheader ]\r\n %conv.i.i = uitofp i64 %Gen.sroa.0.019.i to float\r\n %arrayidx.i.i = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %Gen.sroa.0.019.i\r\n %arrayidx.ascast.i.i = addrspacecast ptr addrspace(1) %arrayidx.i.i to ptr\r\n store float %conv.i.i, ptr %arrayidx.ascast.i.i, align 4, !tbaa !17\r\n %add.i.i = add i64 %Gen.sroa.0.019.i, %mul.i3\r\n %cmp6.i.not.i = icmp ult i64 %add.i.i, %0\r\n br i1 %cmp6.i.not.i, label %for.body.i, label %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit.loopexit, !llvm.loop !21\r\n\r\n_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit.loopexit: ; preds = %for.body.i\r\n br label %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit\r\n\r\n_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit: ; preds = %_ZNK4sycl3_V16detail18RoundedRangeKernelINS0_4itemILi1ELb1EEELi1EZZ12foo_parallelRNS0_5queueERNS0_6bufferIfLi1ENS1_17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESD_EUlNS0_2idILi1EEEE_EclES4_.exit.loopexit, %entry\r\n ret void\r\n}\r\n\r\n; Function Attrs: convergent nounwind\r\ndeclare dso_local noundef i64 @_Z22__spirv_GlobalOffset_xv() local_unnamed_addr #1\r\n\r\n; Function Attrs: convergent norecurse nounwind\r\ndefine weak_odr dso_local spir_kernel void @_ZTSZZ12foo_parallelRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlNS0_2idILi1EEEE_(ptr addrspace(1) noundef align 4 %_arg_acc, ptr noundef byval(%\"class.sycl::_V1::range\") align 8 %_arg_acc3) local_unnamed_addr #0 comdat !srcloc !23 !kernel_arg_buffer_location !24 !kernel_arg_runtime_aligned !25 !kernel_arg_exclusive_ptr !25 !sycl_fixed_targets !10 !sycl_kernel_omit_args !26 {\r\nentry:\r\n %agg.tmp6.sroa.0.0.copyload = load i64, ptr %_arg_acc3, align 8\r\n %add.ptr.i = getelementptr inbounds float, ptr addrspace(1) %_arg_acc, i64 %agg.tmp6.sroa.0.0.copyload\r\n %call.i = tail call i64 @_Z21__spirv_WorkgroupId_xv() #5, !noalias !27\r\n %call1.i = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !27\r\n %mul.i = mul i64 %call1.i, %call.i\r\n %call2.i = tail call i64 @_Z27__spirv_LocalInvocationId_xv() #5, !noalias !27\r\n %add.i = add i64 %mul.i, %call2.i\r\n %call3.i = tail call i64 @_Z22__spirv_GlobalOffset_xv() #5, !noalias !27\r\n %add4.i = add i64 %add.i, %call3.i\r\n %call.i1 = tail call i64 @_Z23__spirv_NumWorkgroups_xv() #5, !noalias !27\r\n %call1.i2 = tail call i64 @_Z23__spirv_WorkgroupSize_xv() #5, !noalias !27\r\n %call.i.i.i9.i.i = tail call noundef i64 @_Z22__spirv_GlobalOffset_xv() #6, !noalias !27\r\n %cmp.i.i = icmp ult i64 %add4.i, 2147483648\r\n tail call void @llvm.assume(i1 %cmp.i.i)\r\n %conv.i = uitofp i64 %add4.i to float\r\n %arrayidx.i = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %add4.i\r\n %arrayidx.ascast.i = addrspacecast ptr addrspace(1) %arrayidx.i to ptr\r\n store float %conv.i, ptr %arrayidx.ascast.i, align 4, !tbaa !17\r\n ret void\r\n}\r\n\r\n; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\r\ndeclare void @llvm.assume(i1 noundef) #2\r\n\r\n; Function Attrs: mustprogress norecurse nounwind\r\ndefine weak_odr dso_local spir_kernel void @_ZTSZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_EUlvE_(i64 noundef %_arg_n, ptr addrspace(1) noundef align 4 %_arg_acc, ptr noundef byval(%\"class.sycl::_V1::range\") align 8 %_arg_acc3) local_unnamed_addr #3 comdat !srcloc !32 !kernel_arg_buffer_location !8 !kernel_arg_runtime_aligned !9 !kernel_arg_exclusive_ptr !9 !sycl_fixed_targets !10 !sycl_kernel_omit_args !11 {\r\nentry:\r\n %agg.tmp6.sroa.0.0.copyload = load i64, ptr %_arg_acc3, align 8\r\n %add.ptr.i = getelementptr inbounds float, ptr addrspace(1) %_arg_acc, i64 %agg.tmp6.sroa.0.0.copyload\r\n %cmp.i12.not = icmp eq i64 %_arg_n, 0\r\n br i1 %cmp.i12.not, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit, label %for.body.i.preheader\r\n\r\nfor.body.i.preheader: ; preds = %entry\r\n %xtraiter = and i64 %_arg_n, 7\r\n %0 = icmp ult i64 %_arg_n, 8\r\n br i1 %0, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, label %for.body.i.preheader.new\r\n\r\nfor.body.i.preheader.new: ; preds = %for.body.i.preheader\r\n %unroll_iter = and i64 %_arg_n, -8\r\n br label %for.body.i\r\n\r\nfor.body.i: ; preds = %for.body.i, %for.body.i.preheader.new\r\n %i.0.i13 = phi i64 [ 0, %for.body.i.preheader.new ], [ %inc.i.7, %for.body.i ]\r\n %conv.i = uitofp i64 %i.0.i13 to float\r\n %arrayidx.i = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %i.0.i13\r\n %arrayidx.ascast.i = addrspacecast ptr addrspace(1) %arrayidx.i to ptr\r\n store float %conv.i, ptr %arrayidx.ascast.i, align 4, !tbaa !17\r\n %inc.i = or disjoint i64 %i.0.i13, 1\r\n %conv.i.1 = uitofp i64 %inc.i to float\r\n %arrayidx.i.1 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i\r\n %arrayidx.ascast.i.1 = addrspacecast ptr addrspace(1) %arrayidx.i.1 to ptr\r\n store float %conv.i.1, ptr %arrayidx.ascast.i.1, align 4, !tbaa !17\r\n %inc.i.1 = or disjoint i64 %i.0.i13, 2\r\n %conv.i.2 = uitofp i64 %inc.i.1 to float\r\n %arrayidx.i.2 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.1\r\n %arrayidx.ascast.i.2 = addrspacecast ptr addrspace(1) %arrayidx.i.2 to ptr\r\n store float %conv.i.2, ptr %arrayidx.ascast.i.2, align 4, !tbaa !17\r\n %inc.i.2 = or disjoint i64 %i.0.i13, 3\r\n %conv.i.3 = uitofp i64 %inc.i.2 to float\r\n %arrayidx.i.3 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.2\r\n %arrayidx.ascast.i.3 = addrspacecast ptr addrspace(1) %arrayidx.i.3 to ptr\r\n store float %conv.i.3, ptr %arrayidx.ascast.i.3, align 4, !tbaa !17\r\n %inc.i.3 = or disjoint i64 %i.0.i13, 4\r\n %conv.i.4 = uitofp i64 %inc.i.3 to float\r\n %arrayidx.i.4 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.3\r\n %arrayidx.ascast.i.4 = addrspacecast ptr addrspace(1) %arrayidx.i.4 to ptr\r\n store float %conv.i.4, ptr %arrayidx.ascast.i.4, align 4, !tbaa !17\r\n %inc.i.4 = or disjoint i64 %i.0.i13, 5\r\n %conv.i.5 = uitofp i64 %inc.i.4 to float\r\n %arrayidx.i.5 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.4\r\n %arrayidx.ascast.i.5 = addrspacecast ptr addrspace(1) %arrayidx.i.5 to ptr\r\n store float %conv.i.5, ptr %arrayidx.ascast.i.5, align 4, !tbaa !17\r\n %inc.i.5 = or disjoint i64 %i.0.i13, 6\r\n %conv.i.6 = uitofp i64 %inc.i.5 to float\r\n %arrayidx.i.6 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.5\r\n %arrayidx.ascast.i.6 = addrspacecast ptr addrspace(1) %arrayidx.i.6 to ptr\r\n store float %conv.i.6, ptr %arrayidx.ascast.i.6, align 4, !tbaa !17\r\n %inc.i.6 = or disjoint i64 %i.0.i13, 7\r\n %conv.i.7 = uitofp i64 %inc.i.6 to float\r\n %arrayidx.i.7 = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %inc.i.6\r\n %arrayidx.ascast.i.7 = addrspacecast ptr addrspace(1) %arrayidx.i.7 to ptr\r\n store float %conv.i.7, ptr %arrayidx.ascast.i.7, align 4, !tbaa !17\r\n %inc.i.7 = add nuw i64 %i.0.i13, 8\r\n %niter.ncmp.7 = icmp eq i64 %inc.i.7, %unroll_iter\r\n br i1 %niter.ncmp.7, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, label %for.body.i, !llvm.loop !33\r\n\r\n_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa: ; preds = %for.body.i, %for.body.i.preheader\r\n %i.0.i13.unr = phi i64 [ 0, %for.body.i.preheader ], [ %unroll_iter, %for.body.i ]\r\n %lcmp.mod.not = icmp eq i64 %xtraiter, 0\r\n br i1 %lcmp.mod.not, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit, label %for.body.i.epil\r\n\r\nfor.body.i.epil: ; preds = %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, %for.body.i.epil\r\n %i.0.i13.epil = phi i64 [ %inc.i.epil, %for.body.i.epil ], [ %i.0.i13.unr, %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa ]\r\n %epil.iter = phi i64 [ %epil.iter.next, %for.body.i.epil ], [ 0, %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa ]\r\n %conv.i.epil = uitofp i64 %i.0.i13.epil to float\r\n %arrayidx.i.epil = getelementptr inbounds float, ptr addrspace(1) %add.ptr.i, i64 %i.0.i13.epil\r\n %arrayidx.ascast.i.epil = addrspacecast ptr addrspace(1) %arrayidx.i.epil to ptr\r\n store float %conv.i.epil, ptr %arrayidx.ascast.i.epil, align 4, !tbaa !17\r\n %inc.i.epil = add nuw nsw i64 %i.0.i13.epil, 1\r\n %epil.iter.next = add nuw nsw i64 %epil.iter, 1\r\n %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter\r\n br i1 %epil.iter.cmp.not, label %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit, label %for.body.i.epil, !llvm.loop !34\r\n\r\n_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit: ; preds = %for.body.i.epil, %_ZZZ15foo_single_taskRN4sycl3_V15queueERNS0_6bufferIfLi1ENS0_6detail17aligned_allocatorIfEEvEEmENKUlRNS0_7handlerEE_clESA_ENKUlvE_clEv.exit.loopexit.unr-lcssa, %entry\r\n ret void\r\n}\r\n\r\n; Function Attrs: convergent nounwind\r\ndeclare dso_local i64 @_Z21__spirv_WorkgroupId_xv() local_unnamed_addr #4\r\n\r\n; Function Attrs: convergent nounwind\r\ndeclare dso_local i64 @_Z23__spirv_WorkgroupSize_xv() local_unnamed_addr #4\r\n\r\n; Function Attrs: convergent nounwind\r\ndeclare dso_local i64 @_Z27__spirv_LocalInvocationId_xv() local_unnamed_addr #4\r\n\r\n; Function Attrs: convergent nounwind\r\ndeclare dso_local i64 @_Z23__spirv_NumWorkgroups_xv() local_unnamed_addr #4\r\n\r\nattributes #0 = { convergent norecurse nounwind \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"sycl-module-id\"=\"native_cpu.cpp\" \"sycl-optlevel\"=\"2\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" \"uniform-work-group-size\"=\"true\" }\r\nattributes #1 = { convergent nounwind \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\r\nattributes #3 = { mustprogress norecurse nounwind \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"sycl-module-id\"=\"native_cpu.cpp\" \"sycl-optlevel\"=\"2\" \"sycl-single-task\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" \"uniform-work-group-size\"=\"true\" }\r\nattributes #4 = { convergent nounwind \"frame-pointer\"=\"all\" \"no-builtins\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+avx,+avx2,+avx512f,+cmov,+crc32,+cx8,+evex512,+f16c,+fma,+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave\" \"tune-cpu\"=\"generic\" }\r\nattributes #5 = { convergent nobuiltin nounwind \"no-builtins\" }\r\nattributes #6 = { convergent nounwind }\r\n\r\n!opencl.spir.version = !{!0}\r\n!spirv.Source = !{!1}\r\n!llvm.ident = !{!2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2}\r\n!llvm.module.flags = !{!3, !4, !5, !6}\r\n\r\n!0 = !{i32 1, i32 2}\r\n!1 = !{i32 4, i32 100000}\r\n!2 = !{!\"clang version 19.0.0git (https://github.com/intel/llvm.git f56d7d7ffd798e78146510bef7ba02575d53bbb2)\"}\r\n!3 = !{i32 1, !\"wchar_size\", i32 4}\r\n!4 = !{i32 1, !\"is-native-cpu\", i32 1}\r\n!5 = !{i32 7, !\"uwtable\", i32 2}\r\n!6 = !{i32 7, !\"frame-pointer\", i32 2}\r\n!7 = !{i32 8377463}\r\n!8 = !{i32 -1, i32 -1, i32 -1}\r\n!9 = !{i1 false, i1 true, i1 false}\r\n!10 = !{}\r\n!11 = !{i1 false, i1 false, i1 true, i1 true, i1 false}\r\n!12 = !{!13, !15}\r\n!13 = distinct !{!13, !14, !\"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv: %agg.result\"}\r\n!14 = distinct !{!14, !\"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv\"}\r\n!15 = distinct !{!15, !16, !\"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE: %agg.result\"}\r\n!16 = distinct !{!16, !\"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE\"}\r\n!17 = !{!18, !18, i64 0}\r\n!18 = !{!\"float\", !19, i64 0}\r\n!19 = !{!\"omnipotent char\", !20, i64 0}\r\n!20 = !{!\"Simple C++ TBAA\"}\r\n!21 = distinct !{!21, !22}\r\n!22 = !{!\"llvm.loop.mustprogress\"}\r\n!23 = !{i32 738}\r\n!24 = !{i32 -1, i32 -1}\r\n!25 = !{i1 true, i1 false}\r\n!26 = !{i1 false, i1 true, i1 true, i1 false}\r\n!27 = !{!28, !30}\r\n!28 = distinct !{!28, !29, !\"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv: %agg.result\"}\r\n!29 = distinct !{!29, !\"_ZN4sycl3_V16detail7Builder7getItemILi1ELb1EEENSt9enable_ifIXT0_EKNS0_4itemIXT_EXT0_EEEE4typeEv\"}\r\n!30 = distinct !{!30, !31, !\"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE: %agg.result\"}\r\n!31 = distinct !{!31, !\"_ZN4sycl3_V16detail7Builder10getElementILi1ELb1EEEDTcl7getItemIXT_EXT0_EEEEPNS0_4itemIXT_EXT0_EEE\"}\r\n!32 = !{i32 1035}\r\n!33 = distinct !{!33, !22}\r\n!34 = distinct !{!34, !35}\r\n!35 = !{!\"llvm.loop.unroll.disable\"}\r\n\r\n```", "author": "wenju-he", "labels": [ "vectorizers", "crash" ], "comments": [ { "author": "PietroGhg", "body": "Hi, this should be addressed by https://github.com/llvm/llvm-project/pull/92107" } ] }
true
null
98675
https://github.com/llvm/llvm-project/issues/98675
crash
22b7b84860d39da71964c9b329937f2ee1d875ba
2024-07-12T18:26:47
[ "llvm/test/Transforms/MemCpyOpt" ]
{ "fix_commit": "99685a54d1322694847f59386a548b3696a43fc3", "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": [ [ 1188, 1196 ] ], "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 99685a54d1322694847f59386a548b3696a43fc3 Author: Yingwei Zheng <[email protected]> Date: Sat Jul 13 04:27:07 2024 +0800 [MemCpyOpt] Use `dyn_cast` to fix assertion failure in `processMemCpyMemCpyDependence` (#98686) Fixes https://github.com/llvm/llvm-project/issues/98675. diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 1c65219585e5..4063762c88a2 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1188,9 +1188,9 @@ bool MemCpyOptPass::processMemCpyMemCpyDependence(MemCpyInst *M, if (MDestOffset == MForwardOffset) CopySource = M->getDest(); else { - NewCopySource = cast<Instruction>(Builder.CreateInBoundsPtrAdd( - CopySource, Builder.getInt64(MForwardOffset))); - CopySource = NewCopySource; + CopySource = Builder.CreateInBoundsPtrAdd( + CopySource, Builder.getInt64(MForwardOffset)); + NewCopySource = dyn_cast<Instruction>(CopySource); } // We need to update `MCopyLoc` if an offset exists. MCopyLoc = MCopyLoc.getWithNewPtr(CopySource);
[ { "file": "llvm/test/Transforms/MemCpyOpt/memcpy-memcpy-offset.ll", "commands": [ "opt < %s -passes=memcpyopt -S -verify-memoryssa" ], "tests": [ { "test_name": "do_not_forward_offset_and_store", "test_body": "define void @do_not_forward_offset_and_store(ptr %src, ptr %dest) {\n %cpy_tmp = alloca [9 x i8], align 1\n call void @llvm.memcpy.p0.p0.i64(ptr align 1 %cpy_tmp, ptr align 1 %src, i64 7, i1 false)\n %src_offset = getelementptr inbounds i8, ptr %src, i64 1\n store i8 1, ptr %src_offset, align 1\n %cpy_tmp_offset = getelementptr inbounds i8, ptr %cpy_tmp, i64 1\n call void @llvm.memcpy.p0.p0.i64(ptr align 1 %dest, ptr align 1 %cpy_tmp_offset, i64 5, 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": "pr98675", "test_body": "@buf = external global [32 x i8]\n\ndefine void @pr98675(ptr noalias %p1, ptr noalias %p2) {\n call void @llvm.memcpy.p0.p0.i64(ptr %p1, ptr @buf, i64 26, i1 false)\n %gep = getelementptr i8, ptr %p1, i64 10\n call void @llvm.memmove.p0.p0.i64(ptr %p2, ptr %gep, 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\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\ndeclare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr 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] Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.", "body": "Detected by https://github.com/dtcxzyw/llvm-opt-benchmark/issues/935.\r\n\r\nReproducer: \r\n```\r\n; bin/opt -passes=memcpyopt -S test.ll\r\n@b = external global [32 x i8]\r\n\r\ndefine void @_Z15TestBasicStringIN5eastl12basic_stringIc17CountingAllocatorEEEiv(ptr %call.i.i.i12866) {\r\n %a = alloca [32 x i8], align 1\r\n call void @llvm.memcpy.p0.p0.i64(ptr %call.i.i.i12866, ptr @b, i64 26, i1 false)\r\n %.sroa.gep22184 = getelementptr i8, ptr %call.i.i.i12866, i64 10\r\n call void @llvm.memmove.p0.p0.i64(ptr %a, ptr %.sroa.gep22184, i64 1, i1 false)\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = Instruction; From = Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: bin/opt -passes=memcpyopt reduced.ll\r\n1. Running pass \"function(memcpyopt)\" on module \"reduced.ll\"\r\n2. Running pass \"memcpyopt\" on function \"_Z15TestBasicStringIN5eastl12basic_stringIc17CountingAllocatorEEEiv\"\r\n #0 0x00007e04ebe0c9c2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x20c9c2)\r\n #1 0x00007e04ebe0988f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.19.0git+0x20988f)\r\n #2 0x00007e04ebe099d5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007e04eb842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007e04eb8969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007e04eb8969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007e04eb8969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007e04eb842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007e04eb8287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007e04eb82871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007e04eb839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00007e04e5ab5dfa llvm::MemCpyOptPass::processMemCpyMemCpyDependence(llvm::MemCpyInst*, llvm::MemCpyInst*, llvm::BatchAAResults&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.19.0git+0x2b5dfa)\r\n#12 0x00007e04e5abd2aa llvm::MemCpyOptPass::processMemCpy(llvm::MemCpyInst*, llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, false>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.19.0git+0x2bd2aa)\r\n#13 0x00007e04e5abd9c4 llvm::MemCpyOptPass::iterateOnFunction(llvm::Function&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.19.0git+0x2bd9c4)\r\n#14 0x00007e04e5abdcce llvm::MemCpyOptPass::runImpl(llvm::Function&, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::AssumptionCache*, llvm::DominatorTree*, llvm::PostDominatorTree*, llvm::MemorySSA*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.19.0git+0x2bdcce)\r\n#15 0x00007e04e5abe15c llvm::MemCpyOptPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.19.0git+0x2be15c)\r\n#16 0x00007e04e74cde55 llvm::detail::PassModel<llvm::Function, llvm::MemCpyOptPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.19.0git+0xcde55)\r\n#17 0x00007e04e474b7b2 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x34b7b2)\r\n#18 0x00007e04eaad5065 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xd5065)\r\n#19 0x00007e04e474a40e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x34a40e)\r\n#20 0x00007e04eaad5985 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.19.0git+0xd5985)\r\n#21 0x00007e04e47483da llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.19.0git+0x3483da)\r\n#22 0x00007e04ec103267 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x2d267)\r\n#23 0x00007e04ec10f212 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.19.0git+0x39212)\r\n#24 0x00007e04eb829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#25 0x00007e04eb829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#26 0x00007e04eb829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#27 0x00005df852081095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\nThis issue is caused by https://github.com/llvm/llvm-project/commit/fa2421392802025e842454a31ed50dbfab643130.\r\nhttps://github.com/llvm/llvm-project/blob/d1dc5047f1127d64eb82eec976fabaa2d9d20c11/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp#L1191-L1192\r\n`Builder.CreateInBoundsPtrAdd` may return `GetElementPtrConstantExpr`.\r\n\r\ncc @nikic @DianQK \r\n\r\n", "author": "dtcxzyw", "labels": [ "crash-on-valid", "llvm:transforms" ], "comments": [ { "author": "DianQK", "body": "It looks similar to https://lab.llvm.org/buildbot/#/builders/41/builds/587. I really shouldn't have merged the code before going to bed :3" } ] }
true
null
105120
https://github.com/llvm/llvm-project/issues/105120
crash
6ec3130a38e6982a61e7fa74bd5223c95c0bb918
2024-08-20T17:04:34
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e31252bf54dedadfe78b36d07ea6084156faa38a", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7227, 7232 ], [ 7238, 7247 ] ], "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 e31252bf54dedadfe78b36d07ea6084156faa38a Author: Alexey Bataev <[email protected]> Date: Wed Aug 21 11:47:00 2024 -0700 [SLP]Fix PR105120: fix the order of phi nodes vectorization. The operands of the phi nodes should be vectorized in the same order, in which they were created, otherwise the compiler may crash when trying to correctly build dependency for nodes with non-schedulable instructions for gather/buildvector nodes. Fixes https://github.com/llvm/llvm-project/issues/105120 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index dee6d688b1b9..848e0de20e7b 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7227,6 +7227,22 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, unsigned ShuffleOrOp = S.isAltShuffle() ? (unsigned) Instruction::ShuffleVector : S.getOpcode(); + auto CreateOperandNodes = [&](TreeEntry *TE, const auto &Operands) { + // Postpone PHI nodes creation + SmallVector<unsigned> PHIOps; + for (unsigned I : seq<unsigned>(Operands.size())) { + ArrayRef<Value *> Op = Operands[I]; + if (Op.empty()) + continue; + InstructionsState S = getSameOpcode(Op, *TLI); + if (S.getOpcode() != Instruction::PHI || S.isAltShuffle()) + buildTree_rec(Op, Depth + 1, {TE, I}); + else + PHIOps.push_back(I); + } + for (unsigned I : PHIOps) + buildTree_rec(Operands[I], Depth + 1, {TE, I}); + }; switch (ShuffleOrOp) { case Instruction::PHI: { auto *PH = cast<PHINode>(VL0); @@ -7238,10 +7254,12 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, // Keeps the reordered operands to avoid code duplication. PHIHandler Handler(*DT, PH, VL); Handler.buildOperands(); - for (unsigned I : seq<unsigned>(0, PH->getNumOperands())) + for (unsigned I : seq<unsigned>(PH->getNumOperands())) TE->setOperand(I, Handler.getOperands(I)); - for (unsigned I : seq<unsigned>(0, PH->getNumOperands())) - buildTree_rec(Handler.getOperands(I), Depth + 1, {TE, I}); + SmallVector<ArrayRef<Value *>> Operands(PH->getNumOperands()); + for (unsigned I : seq<unsigned>(PH->getNumOperands())) + Operands[I] = Handler.getOperands(I); + CreateOperandNodes(TE, Operands); return; } case Instruction::ExtractValue:
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/phi-nodes-as-operand-reorder.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb3, %bb\n %phi = phi i32 [ 0, %bb ], [ %add5, %bb3 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb3 ]\n br i1 false, label %bb6, label %bb3\n\nbb3: ; preds = %bb1\n %add = add i32 0, 0\n %add4 = add i32 0, 0\n %add5 = add i32 %phi, 0\n br i1 false, label %bb6, label %bb1\n\nbb6: ; preds = %bb3, %bb1\n %phi7 = phi i32 [ %phi2, %bb1 ], [ %add4, %bb3 ]\n %phi8 = phi i32 [ %phi, %bb1 ], [ %add5, %bb3 ]\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Instruction does not dominate all uses! LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run the test below with -passes slp-vectorizer -slp-threshold=-99999\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb3, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %add5, %bb3 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb3 ]\r\n br i1 false, label %bb6, label %bb3\r\n\r\nbb3: ; preds = %bb1\r\n %add = add i32 0, 0\r\n %add4 = add i32 0, 0\r\n %add5 = add i32 %phi, 0\r\n br i1 false, label %bb6, label %bb1\r\n\r\nbb6: ; preds = %bb3, %bb1\r\n %phi7 = phi i32 [ %phi2, %bb1 ], [ %add4, %bb3 ]\r\n %phi8 = phi i32 [ %phi, %bb1 ], [ %add5, %bb3 ]\r\n ret void\r\n}\r\n```\r\nReproducer: https://godbolt.org/z/W96s5a1cb\r\n\r\n```\r\nInstruction does not dominate all uses!\r\n %2 = shufflevector <2 x i32> %0, <2 x i32> <i32 0, i32 poison>, <2 x i32> <i32 2, i32 1>\r\n %1 = add <2 x i32> zeroinitializer, %2\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"verify\" on module \"<source>\"\r\n #0 0x0000000004f84b88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f84b88)\r\n #1 0x0000000004f822fc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000074dcb3642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000074dcb36969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000074dcb3642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000074dcb36287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b7cc5 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004ebea18 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ebea18)\r\n #8 0x0000000004dbae20 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4dbae20)\r\n #9 0x00000000008dbbde llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8dbbde)\r\n#10 0x0000000004d7ebb0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7ebb0)\r\n#11 0x00000000008e6912 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e6912)\r\n#12 0x00000000008d97ec optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d97ec)\r\n#13 0x000074dcb3629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x000074dcb3629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008d127e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d127e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "llvm:crash" ], "comments": [ { "author": "alexey-bataev", "body": "Yes" } ] }
true
null
118467
https://github.com/llvm/llvm-project/issues/118467
miscompilation
73731d6873b6fb0757c3065aaf2452eaccd0eebc
2024-12-03T10:44:21
[ "llvm/test/Transforms/AggressiveInstCombine" ]
{ "fix_commit": "f68b0e36997322eeda8fd199ea80deb1b49c5410", "components": [ "AggressiveInstCombine" ], "bug_location_lineno": { "llvm/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": [ [ 803, 810 ] ], "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": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": [ "foldConsecutiveLoads" ], "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 f68b0e36997322eeda8fd199ea80deb1b49c5410 Author: Antonio Frighetto <[email protected]> Date: Wed Dec 4 10:15:11 2024 +0100 [AggressiveInstCombine] Use APInt and avoid truncation when folding loads A miscompilation issue has been addressed with improved handling. Fixes: https://github.com/llvm/llvm-project/issues/118467. diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp index b5b561797f75..45ee2d472a11 100644 --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -803,8 +803,7 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL, APInt Offset1(DL.getIndexTypeSizeInBits(Load1Ptr->getType()), 0); Load1Ptr = Load1Ptr->stripAndAccumulateConstantOffsets( DL, Offset1, /* AllowNonInbounds */ true); - Load1Ptr = Builder.CreatePtrAdd(Load1Ptr, - Builder.getInt32(Offset1.getZExtValue())); + Load1Ptr = Builder.CreatePtrAdd(Load1Ptr, Builder.getInt(Offset1)); } // Generate wider load. NewLoad = Builder.CreateAlignedLoad(WiderType, Load1Ptr, LI1->getAlign(),
[ { "file": "llvm/test/Transforms/AggressiveInstCombine/X86/or-load.ll", "commands": [ "opt < %s -passes=aggressive-instcombine -mtriple x86_64-none-eabi -mattr=avx2 -data-layout=\"e-n64\" -S", "opt < %s -passes=aggressive-instcombine -mtriple x86_64-none-eabi -mattr=avx2 -data-layout=\"E-n64\" -S" ], "tests": [ { "test_name": "loadcombine_consecutive_idx_64", "test_body": "define i32 @loadcombine_consecutive_idx_64(ptr %data) {\nentry:\n %arrayidx = getelementptr inbounds nuw i8, ptr %data, i64 2149675577\n %val = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %val to i32\n %arrayidx.2 = getelementptr inbounds nuw i8, ptr %data, i64 2149675576\n %val.2 = load i8, ptr %arrayidx.2, align 1\n %conv.2 = zext i8 %val.2 to i32\n %shl = shl nuw nsw i32 %conv, 8\n %or = or disjoint i32 %shl, %conv.2\n ret i32 %or\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Invalid LLVM IR code generated on x86-64 with a very simple sample (crash the generated executable code)", "body": "Below is a very simple program that's loading 16 bits table value into a 32 bits variable from a 8 bits table.\nOn **x86-64** with **-O2** or **-O3** flags, this program works fine with LLVM 16.0.0 and below, but since LLVM 17.0.0, the LLVM IR and the generated assembly code are using a wrong calculated offset on the table (doesn't occurs on LLVM armv8 whatever the version).\nAs you can see below, the offset in the table which is supposed to be **2149675576** (**0x80217238**) has its 32 upper bits inverted for **-2145291720** (**0xFFFFFFFF80217238**).\n\n```c\n\n#include <stdint.h>\n\n// Load 16 bits into 32 bits value from data offset 0x80217238\n\nuint32_t Test(const uint8_t* data)\n{ \n uint32_t a, b, c; \n\tb = 0xFFFF8022 << 16;\n b += 0xFFFFE808; \n a = data[b + 0xFFFF8A31];\n c = data[b + 0xFFFF8A30];\n c &= ~0x0000FF00;\n c |= ((a << 8) | (a >> 24)) & 0x0000FF00;\n\treturn c;\n}\n\n```\n\nLLVM IR with LLVM 16.0.0 (from Compiler Explorer)\n```ll\ndefine dso_local noundef i32 @Test(unsigned char const*)(ptr nocapture noundef readonly %data) local_unnamed_addr {\nentry:\n %arrayidx4 = getelementptr inbounds i8, ptr %data, i64 2149675576\n %0 = load i16, ptr %arrayidx4, align 1\n %1 = zext i16 %0 to i32\n ret i32 %1\n}\n\ndeclare void @llvm.dbg.value(metadata, metadata, metadata) #1\n```\nLLVM IR with LLVM 19.1.0 and trunk (from Compiler Explorer)\n```ll\ndefine dso_local noundef range(i32 0, 65536) i32 @Test(unsigned char const*)(ptr nocapture noundef readonly %data) local_unnamed_addr {\nentry:\n %0 = getelementptr i8, ptr %data, i64 -2145291720\n %1 = load i16, ptr %0, align 1\n %2 = zext i16 %1 to i32\n ret i32 %2\n}\n```\n\n\n\n\n\n", "author": "dje64240", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "topperc", "body": "opt-bisect suggests AggressiveInstCominer. There were two separate loads that got merged. The resulting GEP had an index of `i32 -2145291720` with trunk and `i64 2149675576` with clang 16. Those would be the same number if GEP zero extended indices instead of sign extending." }, { "author": "antoniofrighetto", "body": "Alive2: https://alive2.llvm.org/ce/z/G5CgkD." }, { "author": "AZero13", "body": "> opt-bisect suggests AggressiveInstCominer. There were two separate loads that got merged. The resulting GEP had an index of `i32 -2145291720` with trunk and `i64 2149675576` with clang 16. Those would be the same number if GEP zero extended indices instead of sign extending.\n\nSee my PR for 19.x " } ] }
true
null
114371
https://github.com/llvm/llvm-project/issues/114371
crash
71cfa381ef8c4fe659c67e8b2901d767e10f2aff
2024-10-31T07:26:11
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "e7080fd735d02590cdce1bef97a7f64a34145b15", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 16127, 16137 ] ], "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 e7080fd735d02590cdce1bef97a7f64a34145b15 Author: Alexey Bataev <[email protected]> Date: Thu Oct 31 09:26:53 2024 -0700 [SLP]Extra check if the intruction matked for removal, must be replaced in reduction ops If the instruction is vectorized and it is a part of the reduced values gather/buildvector node, it should replaced in reduced operation instructions before removal properly, to avoid compiler crash. Fixes #114371 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 268546fe99e1..593964177ad7 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -16127,11 +16127,13 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues, if (IE->Idx != 0 && !(VectorizableTree.front()->isGather() && !IE->UserTreeIndices.empty() && - any_of(IE->UserTreeIndices, - [&](const EdgeInfo &EI) { - return EI.UserTE == VectorizableTree.front().get() && - EI.EdgeIdx == UINT_MAX; - })) && + (ValueToGatherNodes.lookup(I).contains( + VectorizableTree.front().get()) || + any_of(IE->UserTreeIndices, + [&](const EdgeInfo &EI) { + return EI.UserTE == VectorizableTree.front().get() && + EI.EdgeIdx == UINT_MAX; + }))) && !(GatheredLoadsEntriesFirst.has_value() && IE->Idx >= *GatheredLoadsEntriesFirst && VectorizableTree.front()->isGather() &&
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/external-reduced-value-vectorized.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(ptr %c, i16 %a, i16 %0) {\nentry:\n %tobool = icmp ne i16 %a, 0\n %1 = zext i1 %tobool to i16\n %cmp3 = icmp ugt i16 %0, %1\n %2 = and i1 %tobool, %cmp3\n %tobool.1 = icmp ne i16 %a, 0\n %3 = zext i1 %tobool.1 to i16\n %cmp3.1 = icmp ugt i16 %0, %3\n %4 = and i1 %tobool.1, %cmp3.1\n %5 = select i1 %2, i1 %4, i1 false\n %tobool.2 = icmp ne i16 %a, 0\n %6 = zext i1 %tobool.2 to i16\n %cmp3.2 = icmp ugt i16 %0, %6\n %7 = and i1 %tobool.2, %cmp3.2\n %8 = select i1 %5, i1 %7, i1 false\n %tobool.3 = icmp ne i16 %a, 0\n %9 = zext i1 %tobool.3 to i16\n %cmp3.3 = icmp ugt i16 %a, %9\n %10 = icmp ult i16 %a, -2\n %11 = and i1 %10, %cmp3.3\n %12 = select i1 %8, i1 %11, i1 false\n %13 = zext i1 %12 to i32\n store i32 %13, ptr %c, align 4\n ret i32 0\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 `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' 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/5Tca1zsE8\r\n\r\n```\r\n[507] % clangtk -v\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git fdc78120bde1426b223196bec645b6f27fc60f0e)\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[508] % \r\n[508] % clangtk -O2 small.c\r\nclang-20: /local/suz-local/software/clangbuild/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, 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/20241031-clangtk-m64-O3-build-070121/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241031-clangtk-m64-O3-build-070121/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-2a4e26.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 \"slp-vectorizer\" on function \"main\"\r\n #0 0x000055e84bc23a6f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4428a6f)\r\n #1 0x000055e84bc21274 SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007efe85a5c420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #3 0x00007efe8549300b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #4 0x00007efe85472859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #5 0x00007efe85472729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #6 0x00007efe85472729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #7 0x00007efe85483fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #8 0x000055e84d68990f void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5e8e90f)\r\n #9 0x000055e84d6e6d28 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5eebd28)\r\n#10 0x000055e84d6f8d01 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x000055e84d6fbb89 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-20+0x5f00b89)\r\n#12 0x000055e84d7004ab llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#13 0x000055e84d704d60 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5f09d60)\r\n#14 0x000055e84d70b5a0 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 0x000055e84d70c273 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5f11273)\r\n#16 0x000055e84d17e016 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-20+0x5983016)\r\n#17 0x000055e84b5aa8b1 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+0x3daf8b1)\r\n#18 0x000055e84909b826 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+0x18a0826)\r\n#19 0x000055e84b5a921d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x3dae21d)\r\n#20 0x000055e84909a226 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+0x189f226)\r\n#21 0x000055e84b5a8c51 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+0x3dadc51)\r\n#22 0x000055e84bedd2d3 (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#23 0x000055e84bee0aca 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+0x46e5aca)\r\n#24 0x000055e84c5df37c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4de437c)\r\n#25 0x000055e84e4e0fac clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x6ce5fac)\r\n#26 0x000055e84c5df798 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x4de4798)\r\n#27 0x000055e84c8a7649 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x50ac649)\r\n#28 0x000055e84c823e7e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5028e7e)\r\n#29 0x000055e84c993f46 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x5198f46)\r\n#30 0x000055e848c544f5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x14594f5)\r\n#31 0x000055e848c4c01a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#32 0x000055e848c4ffd7 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1454fd7)\r\n#33 0x000055e848b3a78b main (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x133f78b)\r\n#34 0x00007efe85474083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#35 0x000055e848c4baae _start (/local/suz-local/software/local/clang-trunk/bin/clang-20+0x1450aae)\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 fdc78120bde1426b223196bec645b6f27fc60f0e)\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-8056bb.c\r\nclangtk: note: diagnostic msg: /tmp/small-8056bb.sh\r\nclangtk: note: diagnostic msg: \r\n\r\n********************\r\n[509] % \r\n[509] % cat small.c\r\nshort a;\r\nint b, d;\r\nunsigned short c;\r\nint main() {\r\n b = 0;\r\n for (; b < 5; b++) {\r\n a--;\r\n d |= (3 - (((!a) < 1) < c && a)) & c;\r\n }\r\n return 0;\r\n}\r\n```\r\n\r\n", "author": "zhendongsu", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
113462
https://github.com/llvm/llvm-project/issues/113462
crash
3605d9a456185f4af78c01a2684b822b57bca9b0
2024-10-23T14:33:27
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "b65b2b4ab60763515694c740935989f908a03312", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 9840, 9852 ] ], "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": [ "computeExtractCost" ], "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 b65b2b4ab60763515694c740935989f908a03312 Author: Alexey Bataev <[email protected]> Date: Wed Oct 23 12:03:38 2024 -0700 [SLP]Expand vector to the whole register size in extracts adjustment Need to expand the number of elements to the whole register to correctly process estimation and avoid compiler crash. Fixes #113462 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d824c40c401d..889c4d94ba5e 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -9840,13 +9840,14 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { ::getShuffleCost(TTI, *RegShuffleKind, getWidenedType(ScalarTy, EltsPerVector), SubMask); } + const unsigned BaseVF = getFullVectorNumberOfElements( + *R.TTI, VL.front()->getType(), alignTo(NumElts, EltsPerVector)); for (unsigned Idx : Indices) { - assert((Idx + EltsPerVector) <= alignTo(NumElts, EltsPerVector) && + assert((Idx + EltsPerVector) <= BaseVF && "SK_ExtractSubvector index out of range"); - Cost += ::getShuffleCost( - TTI, TTI::SK_ExtractSubvector, - getWidenedType(ScalarTy, alignTo(NumElts, EltsPerVector)), {}, - CostKind, Idx, getWidenedType(ScalarTy, EltsPerVector)); + Cost += ::getShuffleCost(TTI, TTI::SK_ExtractSubvector, + getWidenedType(ScalarTy, BaseVF), {}, CostKind, + Idx, getWidenedType(ScalarTy, EltsPerVector)); } // Second attempt to check, if just a permute is better estimated than // subvector extract.
[ { "file": "llvm/test/Transforms/SLPVectorizer/partial-register-extract.ll", "commands": [ "opt -S --passes=slp-vectorizer < %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\ndeclare void @callee(i32, i64)\n\ndefine i32 @main(i32 %g_274.promoted2477.i.i.i, ptr %p) {\nentry:\n %g_274.promoted2477.i.i.i1 = load i32, ptr %p, align 4\n br i1 false, label %for.inc347.i.i.i, label %for.cond159.preheader.i.i.i\n\nfor.cond159.preheader.i.i.i: ; preds = %entry\n %tobool239.not.us.i.i.i.not = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\n %tobool239.not.us.i.1.i.i = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\n %tobool239.not.us.i.3.i.i = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\n %0 = or i1 %tobool239.not.us.i.3.i.i, %tobool239.not.us.i.1.i.i\n %tobool239.not.us.i.4.i.i = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\n %inc34.i21362404.us.v.i.4.i.i = select i1 %tobool239.not.us.i.4.i.i, i64 0, i64 0\n %tobool239.not.us.i.5.i.i = icmp eq i32 0, 0\n %inc34.i21362404.us.v.i.5.i.i = select i1 %tobool239.not.us.i.5.i.i, i64 0, i64 0\n %inc34.i21362404.us.i.5.i.i = or i64 %inc34.i21362404.us.v.i.4.i.i, %inc34.i21362404.us.v.i.5.i.i\n %1 = or i1 %tobool239.not.us.i.5.i.i, %tobool239.not.us.i.4.i.i\n %inc34.i21362404.us.v.i.6.i.i = select i1 false, i64 0, i64 0\n %inc34.i21362404.us.i.6.i.i = or i64 %inc34.i21362404.us.i.5.i.i, %inc34.i21362404.us.v.i.6.i.i\n %tobool239.not.us.i.7.i.i = icmp eq i32 0, 0\n %inc34.i21362404.us.v.i.7.i.i = select i1 false, i64 0, i64 0\n %inc34.i21362404.us.i.7.i.i = or i64 %inc34.i21362404.us.i.6.i.i, %inc34.i21362404.us.v.i.7.i.i\n %inc34.i21362404.us.v.i.8.i.i = select i1 false, i64 0, i64 0\n %inc34.i21362404.us.i.8.i.i = or i64 %inc34.i21362404.us.i.7.i.i, %inc34.i21362404.us.v.i.8.i.i\n %inc34.i21362404.us.v.i.9.i.i = select i1 false, i64 0, i64 0\n %inc34.i21362404.us.i.9.i.i = or i64 %inc34.i21362404.us.i.8.i.i, %inc34.i21362404.us.v.i.9.i.i\n %tobool239.not.us.i.10.i.i = icmp eq i32 0, 0\n %tobool239.not.us.i.11.i.i = icmp eq i32 0, 0\n %2 = or i1 %tobool239.not.us.i.11.i.i, %tobool239.not.us.i.10.i.i\n %tobool239.not.us.i.12.i.i = icmp eq i32 %g_274.promoted2477.i.i.i, 0\n %3 = or i1 %tobool239.not.us.i.12.i.i, %2\n %tobool239.not.us.i.13.i.i = icmp eq i32 0, 0\n %tobool239.not.us.i.14.i.i = icmp eq i32 0, 0\n %4 = or i1 %tobool239.not.us.i.14.i.i, %tobool239.not.us.i.13.i.i\n %tobool239.not.us.i.16.i.i = icmp eq i32 0, 0\n %tobool239.not.us.i.17.i.i = icmp eq i32 0, 0\n %5 = or i1 %tobool239.not.us.i.17.i.i, %tobool239.not.us.i.16.i.i\n %tobool239.not.us.i.18.i.i = icmp eq i32 0, 0\n %6 = or i1 %tobool239.not.us.i.18.i.i, %5\n %tobool239.not.us.i.19.i.i = icmp eq i32 0, 0\n %tobool239.not.us.i.20.i.i = icmp eq i32 0, 0\n %7 = or i1 %tobool239.not.us.i.20.i.i, %tobool239.not.us.i.19.i.i\n %tobool239.not.us.i.21.i.i = icmp eq i32 0, 0\n %8 = or i1 %tobool239.not.us.i.21.i.i, %7\n %tobool239.not.us.i.22.i.i = icmp eq i32 0, 0\n %tobool239.not.us.i.23.i.i = icmp eq i32 0, 0\n %9 = or i1 %tobool239.not.us.i.23.i.i, %tobool239.not.us.i.22.i.i\n %tobool239.not.us.i.24.i.i = icmp eq i32 0, 0\n %10 = or i1 %tobool239.not.us.i.24.i.i, %9\n %11 = select i1 %10, i1 true, i1 %8\n %12 = select i1 %11, i1 true, i1 %6\n %13 = select i1 %12, i1 true, i1 %4\n %14 = select i1 %13, i1 true, i1 %3\n %15 = select i1 %14, i1 true, i1 %tobool239.not.us.i.7.i.i\n %16 = select i1 %15, i1 true, i1 %1\n %17 = or i1 %0, %tobool239.not.us.i.i.i.not\n %18 = select i1 %16, i1 true, i1 %17\n %and252.us.i.24.i.i = select i1 %18, i32 0, i32 0\n br label %for.inc347.i.i.i\n\nfor.inc347.i.i.i: ; preds = %for.cond159.preheader.i.i.i, %entry\n %g_202.promoted.i.i.i = phi i32 [ %and252.us.i.24.i.i, %for.cond159.preheader.i.i.i ], [ 0, %entry ]\n %.us-phi24612468.i.i.i = phi i64 [ %inc34.i21362404.us.i.9.i.i, %for.cond159.preheader.i.i.i ], [ 0, %entry ]\n call void @callee(i32 %g_202.promoted.i.i.i, i64 %.us-phi24612468.i.i.i)\n ret i32 0\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[SLPVectorizer] Assertion `(Idx + EltsPerVector) <= alignTo(NumElts, EltsPerVector) && \"SK_ExtractSubvector index out of range\"' failed.", "body": "Reproducer: https://godbolt.org/z/fxYWYnWKs\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\ndeclare void @callee(i32, i64)\r\n\r\ndefine i32 @main(i32 %g_274.promoted2477.i.i.i, ptr %p) {\r\nentry:\r\n %g_274.promoted2477.i.i.i1 = load i32, ptr %p, align 4\r\n br i1 false, label %for.inc347.i.i.i, label %for.cond159.preheader.i.i.i\r\n\r\nfor.cond159.preheader.i.i.i: ; preds = %entry\r\n %tobool239.not.us.i.i.i.not = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\r\n %tobool239.not.us.i.1.i.i = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\r\n %tobool239.not.us.i.3.i.i = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\r\n %0 = or i1 %tobool239.not.us.i.3.i.i, %tobool239.not.us.i.1.i.i\r\n %tobool239.not.us.i.4.i.i = icmp eq i32 %g_274.promoted2477.i.i.i1, 0\r\n %inc34.i21362404.us.v.i.4.i.i = select i1 %tobool239.not.us.i.4.i.i, i64 0, i64 0\r\n %tobool239.not.us.i.5.i.i = icmp eq i32 0, 0\r\n %inc34.i21362404.us.v.i.5.i.i = select i1 %tobool239.not.us.i.5.i.i, i64 0, i64 0\r\n %inc34.i21362404.us.i.5.i.i = or i64 %inc34.i21362404.us.v.i.4.i.i, %inc34.i21362404.us.v.i.5.i.i\r\n %1 = or i1 %tobool239.not.us.i.5.i.i, %tobool239.not.us.i.4.i.i\r\n %inc34.i21362404.us.v.i.6.i.i = select i1 false, i64 0, i64 0\r\n %inc34.i21362404.us.i.6.i.i = or i64 %inc34.i21362404.us.i.5.i.i, %inc34.i21362404.us.v.i.6.i.i\r\n %tobool239.not.us.i.7.i.i = icmp eq i32 0, 0\r\n %inc34.i21362404.us.v.i.7.i.i = select i1 false, i64 0, i64 0\r\n %inc34.i21362404.us.i.7.i.i = or i64 %inc34.i21362404.us.i.6.i.i, %inc34.i21362404.us.v.i.7.i.i\r\n %inc34.i21362404.us.v.i.8.i.i = select i1 false, i64 0, i64 0\r\n %inc34.i21362404.us.i.8.i.i = or i64 %inc34.i21362404.us.i.7.i.i, %inc34.i21362404.us.v.i.8.i.i\r\n %inc34.i21362404.us.v.i.9.i.i = select i1 false, i64 0, i64 0\r\n %inc34.i21362404.us.i.9.i.i = or i64 %inc34.i21362404.us.i.8.i.i, %inc34.i21362404.us.v.i.9.i.i\r\n %tobool239.not.us.i.10.i.i = icmp eq i32 0, 0\r\n %tobool239.not.us.i.11.i.i = icmp eq i32 0, 0\r\n %2 = or i1 %tobool239.not.us.i.11.i.i, %tobool239.not.us.i.10.i.i\r\n %tobool239.not.us.i.12.i.i = icmp eq i32 %g_274.promoted2477.i.i.i, 0\r\n %3 = or i1 %tobool239.not.us.i.12.i.i, %2\r\n %tobool239.not.us.i.13.i.i = icmp eq i32 0, 0\r\n %tobool239.not.us.i.14.i.i = icmp eq i32 0, 0\r\n %4 = or i1 %tobool239.not.us.i.14.i.i, %tobool239.not.us.i.13.i.i\r\n %tobool239.not.us.i.16.i.i = icmp eq i32 0, 0\r\n %tobool239.not.us.i.17.i.i = icmp eq i32 0, 0\r\n %5 = or i1 %tobool239.not.us.i.17.i.i, %tobool239.not.us.i.16.i.i\r\n %tobool239.not.us.i.18.i.i = icmp eq i32 0, 0\r\n %6 = or i1 %tobool239.not.us.i.18.i.i, %5\r\n %tobool239.not.us.i.19.i.i = icmp eq i32 0, 0\r\n %tobool239.not.us.i.20.i.i = icmp eq i32 0, 0\r\n %7 = or i1 %tobool239.not.us.i.20.i.i, %tobool239.not.us.i.19.i.i\r\n %tobool239.not.us.i.21.i.i = icmp eq i32 0, 0\r\n %8 = or i1 %tobool239.not.us.i.21.i.i, %7\r\n %tobool239.not.us.i.22.i.i = icmp eq i32 0, 0\r\n %tobool239.not.us.i.23.i.i = icmp eq i32 0, 0\r\n %9 = or i1 %tobool239.not.us.i.23.i.i, %tobool239.not.us.i.22.i.i\r\n %tobool239.not.us.i.24.i.i = icmp eq i32 0, 0\r\n %10 = or i1 %tobool239.not.us.i.24.i.i, %9\r\n %11 = select i1 %10, i1 true, i1 %8\r\n %12 = select i1 %11, i1 true, i1 %6\r\n %13 = select i1 %12, i1 true, i1 %4\r\n %14 = select i1 %13, i1 true, i1 %3\r\n %15 = select i1 %14, i1 true, i1 %tobool239.not.us.i.7.i.i\r\n %16 = select i1 %15, i1 true, i1 %1\r\n %17 = or i1 %0, %tobool239.not.us.i.i.i.not\r\n %18 = select i1 %16, i1 true, i1 %17\r\n %and252.us.i.24.i.i = select i1 %18, i32 0, i32 0\r\n br label %for.inc347.i.i.i\r\n\r\nfor.inc347.i.i.i: ; preds = %for.cond159.preheader.i.i.i, %entry\r\n %g_202.promoted.i.i.i = phi i32 [ %and252.us.i.24.i.i, %for.cond159.preheader.i.i.i ], [ 0, %entry ]\r\n %.us-phi24612468.i.i.i = phi i64 [ %inc34.i21362404.us.i.9.i.i, %for.cond159.preheader.i.i.i ], [ 0, %entry ]\r\n call void @callee(i32 %g_202.promoted.i.i.i, i64 %.us-phi24612468.i.i.i)\r\n ret i32 0\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:9844: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::computeExtractCost(llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<int>, llvm::ArrayRef<std::optional<llvm::TargetTransformInfo::ShuffleKind> >, unsigned int): Assertion `(Idx + EltsPerVector) <= alignTo(NumElts, EltsPerVector) && \"SK_ExtractSubvector index out of range\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\r\n #0 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 0x00007ed1b9642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007ed1b96969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007ed1b9642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007ed1b96287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007ed1b962871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007ed1b9639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000413c75f llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::computeExtractCost(llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<int>, llvm::ArrayRef<std::optional<llvm::TargetTransformInfo::ShuffleKind>>, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x413c75f)\r\n #9 0x0000000004140d8b llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::adjustExtracts(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::MutableArrayRef<int>, llvm::ArrayRef<std::optional<llvm::TargetTransformInfo::ShuffleKind>>, unsigned int, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4140d8b)\r\n#10 0x000000000417b42a 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+0x417b42a)\r\n#11 0x000000000417cae7 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+0x417cae7)\r\n#12 0x00000000041b6e11 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41b6e11)\r\n#13 0x00000000041bc5df (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#14 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#15 0x00000000041c431b llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#16 0x00000000041c856e llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c856e)\r\n#17 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#18 0x00000000041cfedb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41cfedb)\r\n#19 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#20 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#21 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#22 0x0000000004ed81ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed81ae)\r\n#23 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#24 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#25 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#26 0x00000000008fce7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce7c)\r\n#27 0x00007ed1b9629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#28 0x00007ed1b9629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#29 0x00000000008f493e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f493e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\n\r\nllvm version: 8a9921f5692ab33451d11454b40a023ca0965a69\r\n", "author": "dtcxzyw", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
93152
https://github.com/llvm/llvm-project/issues/93152
crash
d3ce1078186389ce39505f06c2a0100dce9187a5
2024-05-23T08:42:34
[ "llvm/test/Transforms/LowerSwitch" ]
{ "fix_commit": "67aec0cd62d607b4e5b7198769be061454ce67b3", "components": [ "LowerSwitch" ], "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": [ [ 208, 214 ] ], "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": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": [ "NewLeafBlock" ], "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 67aec0cd62d607b4e5b7198769be061454ce67b3 Author: Peter Rong <[email protected]> Date: Mon May 27 10:58:22 2024 -0700 [LowerSwitch] Use unsigned integer for range comparison (#93237) Commit 1db51d8eb2 switched from int64_t to `APInt` to prevent high precision integer overflow. However, when comparing the "range" of switch cases, we should switch to unsigned integer to prevent overflow. This patch fixes https://github.com/llvm/llvm-project/issues/93152. Some test cases are added. Signed-off-by: Peter Rong <[email protected]> diff --git a/llvm/lib/Transforms/Utils/LowerSwitch.cpp b/llvm/lib/Transforms/Utils/LowerSwitch.cpp index f5921e5ccb09..f4ef6d02abf0 100644 --- a/llvm/lib/Transforms/Utils/LowerSwitch.cpp +++ b/llvm/lib/Transforms/Utils/LowerSwitch.cpp @@ -208,7 +208,7 @@ BasicBlock *NewLeafBlock(CaseRange &Leaf, Value *Val, ConstantInt *LowerBound, PHINode *PN = cast<PHINode>(I); // Remove all but one incoming entries from the cluster APInt Range = Leaf.High->getValue() - Leaf.Low->getValue(); - for (APInt j(Range.getBitWidth(), 0, true); j.slt(Range); ++j) { + for (APInt j(Range.getBitWidth(), 0, false); j.ult(Range); ++j) { PN->removeIncomingValue(OrigBlock); }
[ { "file": "llvm/test/Transforms/LowerSwitch/93152.ll", "commands": [ "opt < %s -passes=lower-switch -S" ], "tests": [ { "test_name": "<module>", "test_body": "define void @i3_range_4(i3 %0) {\n;\nbb.0:\n switch i3 %0, label %bb.2 [\n i3 -1, label %bb.1\n i3 -2, label %bb.1\n i3 2, label %bb.1\n i3 1, label %bb.1\n i3 0, label %bb.1\n ]\n\nbb.1: ; preds = %bb.0, %bb.0, %bb.0, %bb.0, %bb.0\n %tmp = phi i3 [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\n br label %bb.2\n\nbb.2: ; preds = %bb.1, %bb.0\n ret void\n}\n\ndefine void @i3_range_6(i3 %0) {\n;\nbb.0:\n switch i3 %0, label %bb.2 [\n i3 -1, label %bb.1\n i3 -2, label %bb.1\n i3 -3, label %bb.1\n i3 3, label %bb.1\n i3 2, label %bb.1\n i3 1, label %bb.1\n i3 0, label %bb.1\n ]\n\nbb.1: ; preds = %bb.0, %bb.0, %bb.0, %bb.0, %bb.0\n %tmp = phi i3 [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\n br label %bb.2\n\nbb.2: ; preds = %bb.1, %bb.0\n ret void\n}\n\n\ndefine void @i3_range_7(i3 %0) {\n;\nbb.0:\n switch i3 %0, label %bb.2 [\n i3 -1, label %bb.1\n i3 -2, label %bb.1\n i3 -3, label %bb.1\n i3 -4, label %bb.1\n i3 3, label %bb.1\n i3 2, label %bb.1\n i3 1, label %bb.1\n i3 0, label %bb.1\n ]\n\nbb.1: ; preds = %bb.0, %bb.0, %bb.0, %bb.0, %bb.0\n %tmp = phi i3 [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\n br label %bb.2\n\nbb.2: ; preds = %bb.1, %bb.0\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "LLVM ERROR: Broken function found after pass \"LowerSwitchPass\", compilation aborted!", "body": "llvm commit: 4cc6d0f4dfb26d\r\nReproduce with:\r\n```opt -passes=\"lower-switch\" -verify-each bbi-95731.ll -o /dev/null```\r\nResult:\r\n```\r\nPHINode should have one entry for each predecessor of its parent basic block!\r\n %tmp = phi i3 [ 0, %LeafBlock ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\r\nLLVM ERROR: Broken function found after pass \"LowerSwitchPass\", compilation aborted!\r\n```\r\nIf we look at what lower-switch actually produces (-print-after-all) we see\r\n```\r\n; *** IR Dump After LowerSwitchPass on v_257_0 ***\r\ndefine void @v_257_0(i3 %0) {\r\nbb.0:\r\n br label %LeafBlock\r\n\r\nLeafBlock: ; preds = %bb.0\r\n %.off = add i3 %0, 2\r\n %SwitchLeaf = icmp ule i3 %.off, -4\r\n br i1 %SwitchLeaf, label %bb.1, label %bb.2\r\n\r\nbb.1: ; preds = %LeafBlock\r\n %tmp = phi i3 [ 0, %LeafBlock ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\r\n br label %bb.2\r\n\r\nbb.2: ; preds = %LeafBlock, %bb.1\r\n ret void\r\n}\r\nPHINode should have one entry for each predecessor of its parent basic block!\r\n %tmp = phi i3 [ 0, %LeafBlock ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\r\n```\r\nSo it has removed the switch instruction but it only updated one of the five phi operands for %bb.0.\r\nThe input looked like\r\n```\r\ndefine void @v_257_0(i3 %0) {\r\nbb.0:\r\n switch i3 %0, label %bb.2 [\r\n i3 -1, label %bb.1\r\n i3 -2, label %bb.1\r\n i3 2, label %bb.1\r\n i3 1, label %bb.1\r\n i3 0, label %bb.1\r\n ]\r\n\r\nbb.1: ; preds = %bb.0, %bb.0, %bb.0, %bb.0, %bb.0\r\n %tmp = phi i3 [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ], [ 0, %bb.0 ]\r\n br label %bb.2\r\n\r\nbb.2: ; preds = %bb.1, %bb.0\r\n ret void\r\n}\r\n```\r\nSo there is one phi operand for each of the values that makes it jump from %bb.0 to %bb.1 and lower-switch only updated one of them when it changed things.\r\n[bbi-95731.ll.gz](https://github.com/llvm/llvm-project/files/15414163/bbi-95731.ll.gz)\r\n", "author": "mikaelholmen", "labels": [ "crash-on-valid", "llvm:transforms" ], "comments": [ { "author": "mikaelholmen", "body": "This starts happening with 1db51d8eb2d\r\n```\r\n[Transform] Rewrite LowerSwitch using APInt\r\n\r\nThis rewrite fixes https://github.com/llvm/llvm-project/issues/59316.\r\n\r\nPreviously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits.\r\nUsing APInt fixes this problem. This patch also includes a test\r\n\r\nReviewed By: RKSimon\r\n\r\nDifferential Revision: https://reviews.llvm.org/D140747\r\n```" }, { "author": "DataCorrupted", "body": "I am taking a look. Some initial thoughts:\r\n\r\n- https://github.com/llvm/llvm-project/commit/1db51d8eb2d220a4f0000555ada310990098cf5b didn't attempt to change how it optimizes the switch. Maybe we forgot to change the API in that optimization.\r\n- `i3` is playing a role here: if you switch it to `i32`, [it'll pass](https://godbolt.org/z/c5Yveb8Kf). " }, { "author": "DataCorrupted", "body": "I found the problem. Fixing it now. Will push a patch shortly" } ] }
true
null
114879
https://github.com/llvm/llvm-project/issues/114879
miscompilation
3850801ca57575640a6ad3a5a421a416dc5c6f12
2024-11-04T22:12:00
[ "llvm/test/Transforms/IndVarSimplify", "llvm/test/Transforms/LoopStrengthReduce", "llvm/test/Transforms/LoopUnroll", "llvm/test/Transforms/LoopVectorize" ]
{ "fix_commit": "0b9f1cc024ca6c7e8d60524be07c0ddfcd08b23c", "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": [ [ 6023, 6029 ] ], "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::createNodeForPHI" ], "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 0b9f1cc024ca6c7e8d60524be07c0ddfcd08b23c Author: Yingwei Zheng <[email protected]> Date: Thu Nov 7 15:53:51 2024 +0800 [SCEV] Disallow simplifying phi(undef, X) to X (#115109) See the following case: ``` @GlobIntONE = global i32 0, align 4 define ptr @src() { entry: br label %for.body.peel.begin for.body.peel.begin: ; preds = %entry br label %for.body.peel for.body.peel: ; preds = %for.body.peel.begin br i1 true, label %cleanup.peel, label %cleanup.loopexit.peel cleanup.loopexit.peel: ; preds = %for.body.peel br label %cleanup.peel cleanup.peel: ; preds = %cleanup.loopexit.peel, %for.body.peel %retval.2.peel = phi ptr [ undef, %for.body.peel ], [ @GlobIntONE, %cleanup.loopexit.peel ] br i1 true, label %for.body.peel.next, label %cleanup7 for.body.peel.next: ; preds = %cleanup.peel br label %for.body.peel.next1 for.body.peel.next1: ; preds = %for.body.peel.next br label %entry.peel.newph entry.peel.newph: ; preds = %for.body.peel.next1 br label %for.body for.body: ; preds = %cleanup, %entry.peel.newph %retval.0 = phi ptr [ %retval.2.peel, %entry.peel.newph ], [ %retval.2, %cleanup ] br i1 false, label %cleanup, label %cleanup.loopexit cleanup.loopexit: ; preds = %for.body br label %cleanup cleanup: ; preds = %cleanup.loopexit, %for.body %retval.2 = phi ptr [ %retval.0, %for.body ], [ @GlobIntONE, %cleanup.loopexit ] br i1 false, label %for.body, label %cleanup7.loopexit cleanup7.loopexit: ; preds = %cleanup %retval.2.lcssa.ph = phi ptr [ %retval.2, %cleanup ] br label %cleanup7 cleanup7: ; preds = %cleanup7.loopexit, %cleanup.peel %retval.2.lcssa = phi ptr [ %retval.2.peel, %cleanup.peel ], [ %retval.2.lcssa.ph, %cleanup7.loopexit ] ret ptr %retval.2.lcssa } define ptr @tgt() { entry: br label %for.body.peel.begin for.body.peel.begin: ; preds = %entry br label %for.body.peel for.body.peel: ; preds = %for.body.peel.begin br i1 true, label %cleanup.peel, label %cleanup.loopexit.peel cleanup.loopexit.peel: ; preds = %for.body.peel br label %cleanup.peel cleanup.peel: ; preds = %cleanup.loopexit.peel, %for.body.peel %retval.2.peel = phi ptr [ undef, %for.body.peel ], [ @GlobIntONE, %cleanup.loopexit.peel ] br i1 true, label %for.body.peel.next, label %cleanup7 for.body.peel.next: ; preds = %cleanup.peel br label %for.body.peel.next1 for.body.peel.next1: ; preds = %for.body.peel.next br label %entry.peel.newph entry.peel.newph: ; preds = %for.body.peel.next1 br label %for.body for.body: ; preds = %cleanup, %entry.peel.newph br i1 false, label %cleanup, label %cleanup.loopexit cleanup.loopexit: ; preds = %for.body br label %cleanup cleanup: ; preds = %cleanup.loopexit, %for.body br i1 false, label %for.body, label %cleanup7.loopexit cleanup7.loopexit: ; preds = %cleanup %retval.2.lcssa.ph = phi ptr [ %retval.2.peel, %cleanup ] br label %cleanup7 cleanup7: ; preds = %cleanup7.loopexit, %cleanup.peel %retval.2.lcssa = phi ptr [ %retval.2.peel, %cleanup.peel ], [ %retval.2.lcssa.ph, %cleanup7.loopexit ] ret ptr %retval.2.lcssa } ``` 1. `simplifyInstruction(%retval.2.peel)` returns `@GlobIntONE`. Thus, `ScalarEvolution::createNodeForPHI` returns SCEV expr `@GlobIntONE` for `%retval.2.peel`. 2. `SimplifyIndvar::replaceIVUserWithLoopInvariant` tries to replace the use of `%retval.2.peel` in `%retval.2.lcssa.ph` with `@GlobIntONE`. 3. `simplifyLoopAfterUnroll -> simplifyLoopIVs -> SCEVExpander::expand` reuses `%retval.2.peel = phi ptr [ undef, %for.body.peel ], [ @GlobIntONE, %cleanup.loopexit.peel ]` to generate code for `@GlobIntONE`. It is incorrect. This patch disallows simplifying `phi(undef, X)` to `X` by setting `CanUseUndef` to false. Closes https://github.com/llvm/llvm-project/issues/114879. diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 58e23e9556f1..b10811133770 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -6023,7 +6023,11 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) { if (const SCEV *S = createAddRecFromPHI(PN)) return S; - if (Value *V = simplifyInstruction(PN, {getDataLayout(), &TLI, &DT, &AC})) + // We do not allow simplifying phi (undef, X) to X here, to avoid reusing the + // phi node for X. + if (Value *V = simplifyInstruction( + PN, {getDataLayout(), &TLI, &DT, &AC, /*CtxI=*/nullptr, + /*UseInstrInfo=*/true, /*CanUseUndef=*/false})) return getSCEV(V); if (const SCEV *S = createNodeFromSelectLikePHI(PN))
[ { "file": "llvm/test/Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll", "commands": [ "opt -passes='loop(indvars,loop-deletion)' -verify-scev -S %s" ], "tests": [ { "test_name": "test_pr52023", "test_body": "define i8 @test_pr52023(i1 %c.1, i1 %c.2) {\nentry:\n br label %loop.1\n\nloop.1: ; preds = %loop.1.latch, %entry\n %inc79 = phi i8 [ %inc.lcssa, %loop.1.latch ], [ 0, %entry ]\n br label %loop.2\n\nloop.2: ; preds = %loop.2.latch, %loop.1\n %inc6 = phi i8 [ %inc79, %loop.1 ], [ %inc, %loop.2.latch ]\n %inc = add i8 %inc6, 1\n br i1 %c.1, label %loop.2.latch, label %loop.1.latch\n\nloop.2.latch: ; preds = %loop.2\n br i1 false, label %loop.2, label %loop.1.latch\n\nloop.1.latch: ; preds = %loop.2.latch, %loop.2\n %inc.lcssa = phi i8 [ %inc, %loop.2.latch ], [ undef, %loop.2 ]\n br i1 %c.2, label %exit, label %loop.1\n\nexit: ; preds = %loop.1.latch\n %inc.lcssa.lcssa = phi i8 [ %inc.lcssa, %loop.1.latch ]\n ret i8 %inc.lcssa.lcssa\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/IndVarSimplify/no-iv-rewrite.ll", "commands": [ "opt < %s -passes=indvars -S -indvars-predicate-loops=0" ], "tests": [ { "test_name": "identityphi", "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\n; Function Attrs: nounwind\ndefine void @identityphi(i32 %limit) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %control, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %control ]\n br i1 undef, label %if.then, label %control\n\nif.then: ; preds = %loop\n br label %control\n\ncontrol: ; preds = %if.then, %loop\n %iv.next = phi i32 [ %iv, %loop ], [ undef, %if.then ]\n %cmp = icmp slt i32 %iv.next, %limit\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %control\n ret void\n}\n\nattributes #0 = { nounwind }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopStrengthReduce/X86/2012-01-13-phielim.ll", "commands": [ "opt < %s -S -loop-reduce -mtriple=x86_64-- -mcpu=core2" ], "tests": [ { "test_name": "test3", "test_body": "; Function Attrs: nounwind ssp uwtable\ndefine fastcc void @test3(ptr nocapture %u) #0 {\nentry:\n br i1 undef, label %meshBB1, label %meshBB5\n\nfor.inc8.us.i: ; preds = %for.body3.us.i\n br i1 undef, label %meshBB1, label %meshBB\n\nfor.body3.us.i: ; preds = %meshBB, %for.body3.lr.ph.us.i\n %indvars.iv.i.SV.phi = phi i64 [ %indvars.iv.next.i, %meshBB ], [ 0, %for.body3.lr.ph.us.i ]\n %storemerge13.us.i.SV.phi = phi i32 [ 0, %meshBB ], [ 0, %for.body3.lr.ph.us.i ]\n %Opq.sa.calc12 = sub i32 undef, 227\n %0 = add nsw i64 %indvars.iv.i.SV.phi, %indvars.iv8.i.SV.phi26\n %1 = trunc i64 %0 to i32\n %mul.i.us.i = mul nsw i32 0, %1\n %arrayidx5.us.i = getelementptr inbounds double, ptr %u, i64 %indvars.iv.i.SV.phi\n %2 = load double, ptr %arrayidx5.us.i, align 8\n %indvars.iv.next.i = add i64 %indvars.iv.i.SV.phi, 1\n br i1 undef, label %for.inc8.us.i, label %meshBB\n\nfor.body3.lr.ph.us.i: ; preds = %meshBB1, %meshBB\n %indvars.iv8.i.SV.phi26 = phi i64 [ undef, %meshBB1 ], [ %indvars.iv8.i.SV.phi24, %meshBB ]\n %arrayidx.us.i = getelementptr inbounds double, ptr undef, i64 %indvars.iv8.i.SV.phi26\n %3 = add i64 %indvars.iv8.i.SV.phi26, 1\n br label %for.body3.us.i\n\nfor.inc8.us.i2: ; preds = %meshBB5\n unreachable\n\neval_At_times_u.exit: ; preds = %meshBB5\n ret void\n\nmeshBB: ; preds = %for.body3.us.i, %for.inc8.us.i\n %indvars.iv8.i.SV.phi24 = phi i64 [ undef, %for.body3.us.i ], [ %3, %for.inc8.us.i ]\n %meshStackVariable.phi = phi i32 [ %Opq.sa.calc12, %for.body3.us.i ], [ undef, %for.inc8.us.i ]\n br i1 undef, label %for.body3.lr.ph.us.i, label %for.body3.us.i\n\nmeshBB1: ; preds = %for.inc8.us.i, %entry\n br label %for.body3.lr.ph.us.i\n\nmeshBB5: ; preds = %entry\n br i1 undef, label %eval_At_times_u.exit, label %for.inc8.us.i2\n}\n\nattributes #0 = { nounwind ssp uwtable }\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/LoopUnroll/pr114879.ll", "commands": [ "opt -S -passes=loop-unroll-full -unroll-full-max-count=1 %s" ], "tests": [ { "test_name": "test", "test_body": "@GlobIntONE = external global i32, align 4\n\ndefine ptr @test() {\nentry:\n br label %for.body\n\nfor.body: ; preds = %cleanup, %entry\n %retval.0 = phi ptr [ undef, %entry ], [ %retval.2, %cleanup ]\n %cmp1.not = phi i1 [ true, %entry ], [ false, %cleanup ]\n br i1 %cmp1.not, label %cleanup, label %cleanup.loopexit\n\ncleanup.loopexit: ; preds = %for.body\n br label %cleanup\n\ncleanup: ; preds = %cleanup.loopexit, %for.body\n %retval.2 = phi ptr [ %retval.0, %for.body ], [ @GlobIntONE, %cleanup.loopexit ]\n br i1 %cmp1.not, label %for.body, label %cleanup2\n\ncleanup2: ; preds = %cleanup\n %retval.2.lcssa = phi ptr [ %retval.2, %cleanup ]\n ret ptr %retval.2.lcssa\n}\n", "lli_expected_out": null, "additional_args": "--src-unroll=10 -tgt-unroll=10" } ] }, { "file": "llvm/test/Transforms/LoopVectorize/uniform-blend.ll", "commands": [ "opt -passes=loop-vectorize -force-vector-width=4 -S %s" ], "tests": [ { "test_name": "blend_uniform_iv", "test_body": "@dst = external global [32 x i16], align 1\n\ndefine void @blend_uniform_iv(i1 %c) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.next, label %loop.latch\n\nloop.next: ; preds = %loop.header\n br label %loop.latch\n\nloop.latch: ; preds = %loop.next, %loop.header\n %blend = phi i64 [ poison, %loop.header ], [ %iv, %loop.next ]\n %dst.ptr = getelementptr inbounds [32 x i16], ptr @dst, i16 0, i64 %blend\n store i16 0, ptr %dst.ptr, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp439 = icmp ult i64 %iv, 31\n br i1 %cmp439, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "blend_uniform_iv_trunc", "test_body": "@dst = external global [32 x i16], align 1\n\ndefine void @blend_uniform_iv_trunc(i1 %c) {\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.trunc.2 = trunc i64 %iv to i16\n br i1 %c, label %loop.next, label %loop.latch\n\nloop.next: ; preds = %loop.header\n br label %loop.latch\n\nloop.latch: ; preds = %loop.next, %loop.header\n %blend = phi i16 [ poison, %loop.header ], [ %iv.trunc.2, %loop.next ]\n %dst.ptr = getelementptr inbounds [32 x i16], ptr @dst, i16 0, i16 %blend\n store i16 0, ptr %dst.ptr, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp439 = icmp ult i64 %iv, 31\n br i1 %cmp439, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "WRONG code: GVN? Loop opts?", "body": "cat wrong0.i\r\n```\r\nint printf(const char *, ...);\r\nunsigned int IntArr[6];\r\nunsigned int GlobIntONE = 1, GlobIntZERO = 0;\r\nconst unsigned int *GlobIntPtr = 0;\r\nunsigned long Res;\r\nunsigned long *ResPtr = &Res;\r\nconst unsigned int **GlobIntPtrPTr = &GlobIntPtr;\r\nunsigned int *func() {\r\n int *GlobIntONEPtr = &GlobIntONE;\r\n for (int Idx = 0; Idx <= 7; Idx += 1) {\r\n int Idx2 = 1;\r\n if (Idx > 0) {\r\n for (; Idx2 <= 7; Idx2 += 1)\r\n ;\r\n return GlobIntONEPtr;\r\n }\r\n }\r\n 0 != &GlobIntONEPtr;\r\n return &GlobIntZERO;\r\n}\r\n\r\nint main() {\r\n IntArr[GlobIntZERO] = GlobIntZERO;\r\n *GlobIntPtrPTr = func();\r\n unsigned char Byte = *GlobIntPtr;\r\n *ResPtr = Byte;\r\n printf(\"checksum = %X\\n\", Res);\r\n}\r\n```\r\n\r\n\r\nIn the above file, func() should obviously should return GlobIntONEPtr, but it does not if compiled with '-fno-inline -mllvm -unroll-full-max-count=1'.\r\n\r\n```\r\nclang -O0 -march=z16 wrong0.i -o a.out -w -fno-inline ; ./a.out\r\nchecksum = 1\r\n\r\nclang -O3 -march=z16 wrong0.i -o a.out -w -fno-inline ; ./a.out\r\nchecksum = 1\r\n\r\nclang -O3 -march=z16 wrong0.i -o a.out -w -fno-inline -mllvm -unroll-full-max-count=1 ; ./a.out\r\nchecksum = 0\r\n\r\n```\r\nIt may be that GVN does something wrong, as after it @func() is always returning ptr undef. Or it could very well be some of the loop optimizations that is run just before it.\r\n\r\nA bisect shows that\r\n\r\n```\r\nd77067d08a3f56dc2d0e6c95bd2852c943df743a is the first bad commit\r\ncommit d77067d08a3f56dc2d0e6c95bd2852c943df743a\r\nAuthor: Nikita Popov <[email protected]>\r\nDate: Wed Dec 6 14:17:18 2023 +0100\r\n\r\n [ValueTracking] Add dominating condition support in computeKnownBits() (#73662)\r\n\r\n```\r\n@nikic ", "author": "JonPsson1", "labels": [ "miscompilation", "llvm:SCEV" ], "comments": [ { "author": "dtcxzyw", "body": "Bisected to LoopUnrollFullPass:\r\n```\r\n; bin/opt -passes=loop-unroll-full -unroll-full-max-count=1 test.ll -S\r\n\r\n@GlobIntONE = dso_local global i32 1, align 4\r\n@GlobIntZERO = dso_local local_unnamed_addr global i32 0, align 4\r\n\r\ndefine i32 @main() local_unnamed_addr {\r\nentry:\r\n br label %for.body\r\n\r\nfor.body: ; preds = %entry, %cleanup\r\n %retval.0 = phi ptr [ undef, %entry ], [ %retval.2, %cleanup ]\r\n %cmp1.not = phi i1 [ true, %entry ], [ false, %cleanup ]\r\n br i1 %cmp1.not, label %cleanup, label %for.cond2.preheader\r\n\r\nfor.cond2.preheader: ; preds = %for.body\r\n br label %cleanup.loopexit\r\n\r\ncleanup.loopexit: ; preds = %for.cond2.preheader\r\n br label %cleanup\r\n\r\ncleanup: ; preds = %cleanup.loopexit, %for.body\r\n %retval.2 = phi ptr [ %retval.0, %for.body ], [ @GlobIntONE, %cleanup.loopexit ]\r\n br i1 %cmp1.not, label %for.body, label %cleanup7\r\n\r\ncleanup7: ; preds = %cleanup\r\n %retval.2.lcssa = phi ptr [ %retval.2, %cleanup ]\r\n %res = load i32, ptr %retval.2.lcssa, align 4\r\n ret i32 %res\r\n}\r\n```\r\n```\r\nsource_filename = \"test.ll\"\r\n\r\n@GlobIntONE = dso_local global i32 1, align 4\r\n@GlobIntZERO = dso_local local_unnamed_addr global i32 0, align 4\r\n\r\ndefine i32 @main() local_unnamed_addr {\r\nentry:\r\n br label %for.body.peel.begin\r\n\r\nfor.body.peel.begin: ; preds = %entry\r\n br label %for.body.peel\r\n\r\nfor.body.peel: ; preds = %for.body.peel.begin\r\n br i1 true, label %cleanup.peel, label %for.cond2.preheader.peel\r\n\r\nfor.cond2.preheader.peel: ; preds = %for.body.peel\r\n br label %cleanup.loopexit.peel\r\n\r\ncleanup.loopexit.peel: ; preds = %for.cond2.preheader.peel\r\n br label %cleanup.peel\r\n\r\ncleanup.peel: ; preds = %cleanup.loopexit.peel, %for.body.peel\r\n %retval.2.peel = phi ptr [ undef, %for.body.peel ], [ @GlobIntONE, %cleanup.loopexit.peel ]\r\n br i1 true, label %for.body.peel.next, label %cleanup7\r\n\r\nfor.body.peel.next: ; preds = %cleanup.peel\r\n br label %for.body.peel.next1\r\n\r\nfor.body.peel.next1: ; preds = %for.body.peel.next\r\n br label %entry.peel.newph\r\n\r\nentry.peel.newph: ; preds = %for.body.peel.next1\r\n br label %for.body\r\n\r\nfor.body: ; preds = %cleanup, %entry.peel.newph\r\n br i1 false, label %cleanup, label %for.cond2.preheader\r\n\r\nfor.cond2.preheader: ; preds = %for.body\r\n br label %cleanup.loopexit\r\n\r\ncleanup.loopexit: ; preds = %for.cond2.preheader\r\n br label %cleanup\r\n\r\ncleanup: ; preds = %cleanup.loopexit, %for.body\r\n br i1 false, label %for.body, label %cleanup7.loopexit, !llvm.loop !0\r\n\r\ncleanup7.loopexit: ; preds = %cleanup\r\n %retval.2.lcssa.ph = phi ptr [ %retval.2.peel, %cleanup ]\r\n br label %cleanup7\r\n\r\ncleanup7: ; preds = %cleanup7.loopexit, %cleanup.peel\r\n %retval.2.lcssa = phi ptr [ %retval.2.peel, %cleanup.peel ], [ %retval.2.lcssa.ph, %cleanup7.loopexit ]\r\n %res = load i32, ptr %retval.2.lcssa, align 4\r\n ret i32 %res\r\n}\r\n\r\n!0 = distinct !{!0, !1}\r\n!1 = !{!\"llvm.loop.peeled.count\", i32 1}\r\n```" }, { "author": "dtcxzyw", "body": "`simplifyLoopAfterUnroll -> simplifyLoopIVs` causes the miscompilation: https://alive2.llvm.org/ce/z/yiBsZt\r\nI will post a fix later.\r\n" }, { "author": "dtcxzyw", "body": "The root cause is:\r\n1. `simplifyInstruction(%retval.2.peel)` returns `@GlobIntONE`. Thus, `ScalarEvolution::createNodeForPHI` returns SCEV expr `@GlobIntONE` for `%retval.2.peel`.\r\n2. `SimplifyIndvar::replaceIVUserWithLoopInvariant` tries to replace the use of `%retval.2.peel` in `%retval.2.lcssa.ph` with `@GlobIntONE`.\r\n3. `SCEVExpander::expand` reuses `%retval.2.peel = phi ptr [ undef, %for.body.peel ], [ @GlobIntONE, %cleanup.loopexit.peel ]` to generate code for `@GlobIntONE`. It is incorrect.\r\n\r\nTwo possible solutions:\r\n1. Set `CanUseUndef` to false in `simplifyInstruction`.\r\n2. Block this case in `ScalarEvolution::canReuseInstruction`.\r\n\r\n@nikic @preames Any thoughts?\r\n" }, { "author": "nikic", "body": "I think setting `CanUseUndef=false` would be the correct thing to do. The reverse replacement here is particularly fishy, but more generally, if we make an assumption about the value of undef at a particular use, we have to be consistent about that assumption, and SCEV cannot really guarantee that this is the case." } ] }
true
null
113451
https://github.com/llvm/llvm-project/issues/113451
crash
7a1036935f8122d9120df5ecf5afb5c927a9ea8b
2024-10-23T12:43:54
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "a3508e0246741851f06cb9ba86203be8d89febed", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 11588, 11594 ] ], "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::isTreeTinyAndNotFullyVectorizable" ], "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 a3508e0246741851f06cb9ba86203be8d89febed Author: Alexey Bataev <[email protected]> Date: Wed Oct 23 10:25:41 2024 -0700 [SLP]Small buidlvector only graph should contains scalars from same block If the graph is small and has single buildvector node, all scalars instructions must be from the same basic block to prevent compiler crash. Fixes #113451 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 756b25ac9856..d824c40c401d 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -11588,7 +11588,8 @@ bool BoUpSLP::isTreeTinyAndNotFullyVectorizable(bool ForReduction) const { if (VectorizableTree.back()->isGather() && VectorizableTree.back()->isAltShuffle() && - VectorizableTree.back()->getVectorFactor() > 2) + VectorizableTree.back()->getVectorFactor() > 2 && + allSameBlock(VectorizableTree.back()->Scalars)) return false; assert(VectorizableTree.empty()
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/small-graph-diff-block-instructions.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512dq -slp-threshold=-99999 < %s" ], "tests": [ { "test_name": "test", "test_body": "define i32 @test(i32 %arg, i32 %arg1) {\nbb:\n %zext = zext i32 %arg1 to i64\n %zext2 = zext i32 %arg to i64\n %sext = sext i32 %arg to i64\n br label %bb3\n\nbb3: ; preds = %bb\n %getelementptr = getelementptr i64, ptr addrspace(1) null, i64 %zext\n %getelementptr4 = getelementptr i64, ptr addrspace(1) null, i64 %zext2\n %getelementptr5 = getelementptr i64, ptr addrspace(1) null, i64 %sext\n %zext6 = zext i32 0 to i64\n %getelementptr7 = getelementptr i64, ptr addrspace(1) null, i64 %zext6\n ret i32 0\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Assertion `((GatheredLoadsEntriesFirst.has_value() && E->getOpcode() == Instruction::Load && E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) || all_of(E->Scalars, [=](Value *V) -> bool { if (E->getOpcode() == Instruction::GetElementPtr && !isa<GetElementPtrInst>(V)) return true; auto *I = cast<Instruction>(V); return !E->isOpcodeOrAlt(I) || I->getParent() == BB || isVectorLikeInstWithConstOps(I); })) && \"Expected gathered loads or GEPs or instructions from same basic \" \"block.\"' failed.", "body": "To reproduce the test below with -passes slp-vectorizer -slp-threshold=-99999 \r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i32 @wombat(i32 %arg, i32 %arg1) #0 gc \"statepoint-example\" {\r\nbb:\r\n %zext = zext i32 %arg1 to i64\r\n %zext2 = zext i32 %arg to i64\r\n %sext = sext i32 %arg to i64\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb\r\n %getelementptr = getelementptr i64, ptr addrspace(1) null, i64 %zext\r\n %getelementptr4 = getelementptr i64, ptr addrspace(1) null, i64 %zext2\r\n %getelementptr5 = getelementptr i64, ptr addrspace(1) null, i64 %sext\r\n %zext6 = zext i32 0 to i64\r\n %getelementptr7 = getelementptr i64, ptr addrspace(1) null, i64 %zext6\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+prfchw,-cldemote,+avx,+aes,+sahf,+pclmul,-xop,+crc32,+xsaves,-avx512fp16,-usermsr,-sm4,-egpr,+sse4.1,-avx512ifma,+xsave,+sse4.2,-tsxldtrk,-sm3,-ptwrite,-widekl,+invpcid,+64bit,+xsavec,-avx10.1-512,-avx512vpopcntdq,+cmov,-avx512vp2intersect,+avx512cd,+movbe,-avxvnniint8,-ccmp,-amx-int8,-kl,-avx10.1-256,+evex512,-avxvnni,+rtm,+adx,+avx2,-hreset,-movdiri,-serialize,-sha512,-vpclmulqdq,+avx512vl,-uintr,-cf,+clflushopt,-raoint,-cmpccxadd,+bmi,-amx-tile,+sse,-avx10.2-256,-gfni,-avxvnniint16,-amx-fp16,-zu,-ndd,+xsaveopt,+rdrnd,+avx512f,-amx-bf16,-avx512bf16,-avx512vnni,-push2pop2,+cx8,+avx512bw,+sse3,+pku,-nf,+fsgsbase,-clzero,-mwaitx,-lwp,+lzcnt,-sha,-movdir64b,-ppx,-wbnoinvd,-enqcmd,-avx10.2-512,-avxneconvert,-tbm,-pconfig,-amx-complex,+ssse3,+cx16,+bmi2,+fma,+popcnt,-avxifma,+f16c,-avx512bitalg,-rdpru,+clwb,+mmx,+sse2,+rdseed,-avx512vbmi2,-prefetchi,-rdpid,-fma4,-avx512vbmi,-shstk,-vaes,-waitpkg,-sgx,+fxsr,+avx512dq,-sse4a,-avx512f\" }\r\n\r\n```\r\nReproducer: https://godbolt.org/z/8WhP4hY6G\r\n\r\nStack dump:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13048: llvm::Instruction& llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(const llvm::slpvectorizer::BoUpSLP::TreeEntry*): Assertion `((GatheredLoadsEntriesFirst.has_value() && E->getOpcode() == Instruction::Load && E->isGather() && E->Idx < *GatheredLoadsEntriesFirst) || all_of(E->Scalars, [=](Value *V) -> bool { if (E->getOpcode() == Instruction::GetElementPtr && !isa<GetElementPtrInst>(V)) return true; auto *I = cast<Instruction>(V); return !E->isOpcodeOrAlt(I) || I->getParent() == BB || isVectorLikeInstWithConstOps(I); })) && \"Expected gathered loads or GEPs or instructions from same basic \" \"block.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\r\n #0 0x00000000050d8608 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x50d8608)\r\n #1 0x00000000050d5fbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000070a067c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000070a067c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000070a067c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000070a067c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000070a067c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000070a067c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004157831 llvm::slpvectorizer::BoUpSLP::getLastInstructionInBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4157831)\r\n #9 0x0000000004157890 llvm::slpvectorizer::BoUpSLP::setInsertPointAfterBundle(llvm::slpvectorizer::BoUpSLP::TreeEntry const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4157890)\r\n#10 0x00000000041820da llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41820da)\r\n#11 0x00000000041a7a5c llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::SmallDenseSet<llvm::Value*, 4u, llvm::DenseMapInfo<llvm::Value*, void>> const&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41a7a5c)\r\n#12 0x00000000041ab4ad llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41ab4ad)\r\n#13 0x00000000041c0e45 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c0e45)\r\n#14 0x00000000041c2f7b llvm::SLPVectorizerPass::vectorizeGEPIndices(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41c2f7b)\r\n#15 0x00000000041cf257 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#16 0x00000000041cfedb llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x41cfedb)\r\n#17 0x0000000002f64f0e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f64f0e)\r\n#18 0x0000000004ed9788 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed9788)\r\n#19 0x0000000000e2773e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe2773e)\r\n#20 0x0000000004ed81ae llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed81ae)\r\n#21 0x0000000000e26e8e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe26e8e)\r\n#22 0x0000000004ed7be0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4ed7be0)\r\n#23 0x000000000090a07a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x90a07a)\r\n#24 0x00000000008fce7c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce7c)\r\n#25 0x000070a067c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x000070a067c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008f493e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f493e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash" ], "comments": [] }
true
null
102187
https://github.com/llvm/llvm-project/issues/102187
crash
4b6e3e38c46f8fedb92a30b29cc9654450244e2d
2024-08-06T17:31:46
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "2601d6f189cf1d4e4e77a7cba83e5d32c87bf079", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 14049, 14060 ], [ 14080, 14090 ] ], "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 2601d6f189cf1d4e4e77a7cba83e5d32c87bf079 Author: Alexey Bataev <[email protected]> Date: Tue Aug 6 12:27:36 2024 -0700 [SLP]Fix PR102187: do not insert extractelement before landingpad instruction. Landingpad instruction must be the very first instruction after the phi nodes, so need to inser extractelement/shuffles after this instruction. Fixes https://github.com/llvm/llvm-project/issues/102187 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 9589d306581e..5c8873853a73 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -14049,12 +14049,19 @@ Value *BoUpSLP::vectorizeTree( "ExternallyUsedValues map or remain as scalar in vectorized " "instructions"); if (auto *VecI = dyn_cast<Instruction>(Vec)) { - if (auto *PHI = dyn_cast<PHINode>(VecI)) - Builder.SetInsertPoint(PHI->getParent(), - PHI->getParent()->getFirstNonPHIIt()); - else + if (auto *PHI = dyn_cast<PHINode>(VecI)) { + if (PHI->getParent()->isLandingPad()) + Builder.SetInsertPoint( + PHI->getParent(), + std::next( + PHI->getParent()->getLandingPadInst()->getIterator())); + else + Builder.SetInsertPoint(PHI->getParent(), + PHI->getParent()->getFirstNonPHIIt()); + } else { Builder.SetInsertPoint(VecI->getParent(), std::next(VecI->getIterator())); + } } else { Builder.SetInsertPoint(&F->getEntryBlock(), F->getEntryBlock().begin()); } @@ -14080,11 +14087,18 @@ Value *BoUpSLP::vectorizeTree( auto VecIt = VectorCasts.find(Key); if (VecIt == VectorCasts.end()) { IRBuilderBase::InsertPointGuard Guard(Builder); - if (auto *IVec = dyn_cast<PHINode>(Vec)) - Builder.SetInsertPoint( - IVec->getParent()->getFirstNonPHIOrDbgOrLifetime()); - else if (auto *IVec = dyn_cast<Instruction>(Vec)) + if (auto *IVec = dyn_cast<PHINode>(Vec)) { + if (IVec->getParent()->isLandingPad()) + Builder.SetInsertPoint(IVec->getParent(), + std::next(IVec->getParent() + ->getLandingPadInst() + ->getIterator())); + else + Builder.SetInsertPoint( + IVec->getParent()->getFirstNonPHIOrDbgOrLifetime()); + } else if (auto *IVec = dyn_cast<Instruction>(Vec)) { Builder.SetInsertPoint(IVec->getNextNonDebugInstruction()); + } Vec = Builder.CreateIntCast( Vec, getWidenedType(
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/extractelement-phi-in-landingpad.ll", "commands": [ "opt -S --passes=slp-vectorizer -slp-threshold=-99999 -mtriple=x86_64-unknown-linux-gnu < %s" ], "tests": [ { "test_name": "test", "test_body": "define void @test() personality ptr null {\nbb:\n invoke void null()\n to label %bb65 unwind label %bb4\n\nbb2: ; No predecessors!\n invoke void null()\n to label %bb65 unwind label %bb4\n\nbb4: ; preds = %bb2, %bb\n %phi5 = phi i32 [ 0, %bb ], [ 0, %bb2 ]\n %phi6 = phi i32 [ 0, %bb ], [ 0, %bb2 ]\n %landingpad = landingpad { ptr, i32 }\n cleanup\n call void null(i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5, i32 %phi5)\n ret void\n\nbb65: ; preds = %bb2, %bb\n ret void\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "LLVM ERROR: Broken module found, compilation aborted!", "body": "To reproduce run opt with \r\n[Test.ll.tgz](https://github.com/user-attachments/files/16513795/Test.ll.tgz)\r\nusing `-passes slp-vectorizer -slp-threshold=-99999` \r\n\r\nReproducer https://godbolt.org/z/f4szGsMYd\r\n\r\n```\r\nThe unwind destination does not have an exception handling instruction!\r\n %invoke = invoke i64 null(ptr addrspace(1) null, i32 0, i64 0, i32 0)\r\n to label %bb65 unwind label %bb4\r\nThe unwind destination does not have an exception handling instruction!\r\n %invoke3 = invoke i64 null(ptr addrspace(1) null, i32 0, i64 0, i32 0)\r\n to label %bb65 unwind label %bb4\r\nLandingPadInst not the first non-PHI instruction in the block.\r\n %landingpad = landingpad { ptr, i32 }\r\n cleanup\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"verify\" on module \"<source>\"\r\n #0 0x0000000004f1d2d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f1d2d8)\r\n #1 0x0000000004f1aa4c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x0000788c1ca42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x0000788c1ca969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x0000788c1ca42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x0000788c1ca287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007b40fd llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x0000000004e571e8 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e571e8)\r\n #8 0x0000000004d53550 llvm::VerifierPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d53550)\r\n #9 0x00000000008d8a7e 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+0x8d8a7e)\r\n#10 0x0000000004d17270 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d17270)\r\n#11 0x00000000008e37f2 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+0x8e37f2)\r\n#12 0x00000000008d671c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d671c)\r\n#13 0x0000788c1ca29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x0000788c1ca29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x00000000008cdb7e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cdb7e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
null
115574
https://github.com/llvm/llvm-project/issues/115574
miscompilation
00bdce1c373a1c5b756f4cf694a952ef702d0294
2024-11-09T01:49:48
[ "llvm/test/Transforms/InstSimplify" ]
{ "fix_commit": "1af627b592dd15bbe58136f902ced46251fc344d", "components": [ "InstructionSimplify" ], "bug_location_lineno": { "llvm/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": [ [ 27, 32 ], [ 4731, 4742 ] ], "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": [ "simplifySelectWithICmpCond" ], "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 1af627b592dd15bbe58136f902ced46251fc344d Author: Yingwei Zheng <[email protected]> Date: Sun Feb 2 19:04:23 2025 +0800 [InstSimplify] Add additional checks when substituting pointers (#125385) Compile-time impact: https://llvm-compile-time-tracker.com/compare.php?from=d09b521624f263b5f1296f8d4771836b97e600cb&to=e437ba2cb83bb965e13ef00727671896f03ff84f&stat=instructions:u IR diff looks acceptable. Closes https://github.com/llvm/llvm-project/issues/115574 diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 21c937530cd8..3cbc4107433e 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -27,6 +27,7 @@ #include "llvm/Analysis/CmpInstAnalysis.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/InstSimplifyFolder.h" +#include "llvm/Analysis/Loads.h" #include "llvm/Analysis/LoopAnalysisManager.h" #include "llvm/Analysis/MemoryBuiltins.h" #include "llvm/Analysis/OverflowInstAnalysis.h" @@ -4731,12 +4732,16 @@ static Value *simplifySelectWithICmpCond(Value *CondVal, Value *TrueVal, // the arms of the select. See if substituting this value into the arm and // simplifying the result yields the same value as the other arm. if (Pred == ICmpInst::ICMP_EQ) { - if (Value *V = simplifySelectWithEquivalence({{CmpLHS, CmpRHS}}, TrueVal, - FalseVal, Q, MaxRecurse)) - return V; - if (Value *V = simplifySelectWithEquivalence({{CmpRHS, CmpLHS}}, TrueVal, - FalseVal, Q, MaxRecurse)) - return V; + if (CmpLHS->getType()->isIntOrIntVectorTy() || + canReplacePointersIfEqual(CmpLHS, CmpRHS, Q.DL)) + if (Value *V = simplifySelectWithEquivalence({{CmpLHS, CmpRHS}}, TrueVal, + FalseVal, Q, MaxRecurse)) + return V; + if (CmpLHS->getType()->isIntOrIntVectorTy() || + canReplacePointersIfEqual(CmpRHS, CmpLHS, Q.DL)) + if (Value *V = simplifySelectWithEquivalence({{CmpRHS, CmpLHS}}, TrueVal, + FalseVal, Q, MaxRecurse)) + return V; Value *X; Value *Y;
[ { "file": "llvm/test/Transforms/InstSimplify/select-icmp.ll", "commands": [ "opt < %s -passes=instsimplify -S" ], "tests": [ { "test_name": "icmp_ptr_eq_replace_null", "test_body": "target datalayout = \"p:8:8:8\"\n\ndefine ptr @icmp_ptr_eq_replace_null(ptr %a) {\n %cmp = icmp eq ptr %a, null\n %sel = select i1 %cmp, ptr null, ptr %a\n ret ptr %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "ptr_eq_replace_same_underlying_object", "test_body": "target datalayout = \"p:8:8:8\"\n\ndefine ptr @ptr_eq_replace_same_underlying_object(ptr %st, i64 %i, i64 %j) {\n %a = getelementptr inbounds i8, ptr %st, i64 %i\n %b = getelementptr inbounds i8, ptr %st, i64 %j\n %cmp = icmp eq ptr %a, %b\n %sel = select i1 %cmp, ptr %a, ptr %b\n ret ptr %sel\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "icmp_ptr_eq_replace", "test_body": "target datalayout = \"p:8:8:8\"\n\ndefine ptr @icmp_ptr_eq_replace(ptr %a, ptr %b) {\n %cmp = icmp eq ptr %a, %b\n %sel = select i1 %cmp, ptr %a, ptr %b\n ret ptr %sel\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstSimplify] wrong folding of pointer comparison `select (icmp eq ptr ...)`", "body": "https://github.com/llvm/llvm-project/blob/c93e001ca695e905cb965b36d63f7a348d1dd809/llvm/lib/Analysis/InstructionSimplify.cpp#L148-L167\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/aux2zY\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine ptr @smin_test8.2(ptr %a, ptr %b, ptr %c) {\r\n#0:\r\n %cmp1 = icmp eq ptr %a, %b\r\n %umin1 = select i1 %cmp1, ptr %a, ptr %b\r\n %cmp2 = icmp slt ptr %b, %c\r\n %umin2 = select i1 %cmp2, ptr %b, ptr %c\r\n %cmp3 = icmp ult ptr %umin2, %a\r\n %umin3 = select i1 %cmp3, ptr %umin2, ptr %a\r\n %cmp4 = icmp slt ptr %c, %umin3\r\n %res = select i1 %cmp4, ptr %umin1, ptr %umin3\r\n ret ptr %res\r\n}\r\n=>\r\ndefine ptr @smin_test8.2(ptr %a, ptr %b, ptr %c) {\r\n#0:\r\n %cmp2 = icmp slt ptr %b, %c\r\n %umin2 = select i1 %cmp2, ptr %b, ptr %c\r\n %cmp3 = icmp ult ptr %umin2, %a\r\n %umin3 = select i1 %cmp3, ptr %umin2, ptr %a\r\n %cmp4 = icmp slt ptr %c, %umin3\r\n %res = select i1 %cmp4, ptr %b, ptr %umin3\r\n ret ptr %res\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\nptr %a = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\nptr %b = pointer(non-local, block_id=1, offset=0) / Address=#x1\r\nptr %c = pointer(non-local, block_id=0, offset=-8) / Address=#x8\r\n\r\nSource:\r\ni1 %cmp1 = #x1 (1)\r\nptr %umin1 = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\ni1 %cmp2 = #x0 (0)\r\nptr %umin2 = pointer(non-local, block_id=0, offset=-8) / Address=#x8\r\ni1 %cmp3 = #x0 (0)\r\nptr %umin3 = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\ni1 %cmp4 = #x1 (1)\r\nptr %res = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\n\r\nSOURCE MEMORY STATE\r\n===================\r\nNON-LOCAL BLOCKS:\r\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\r\nBlock 1 >\tsize: 1\talign: 1\talloc type: 0\talive: true\taddress: 1\r\nBlock 2 >\tsize: 1\talign: 1\talloc type: 0\talive: true\taddress: 2\r\nBlock 3 >\tsize: 3\talign: 1\talloc type: 0\talive: true\taddress: 8\r\n\r\nTarget:\r\ni1 %cmp2 = #x0 (0)\r\nptr %umin2 = pointer(non-local, block_id=0, offset=-8) / Address=#x8\r\ni1 %cmp3 = #x0 (0)\r\nptr %umin3 = pointer(non-local, block_id=0, offset=1) / Address=#x1\r\ni1 %cmp4 = #x1 (1)\r\nptr %res = pointer(non-local, block_id=1, offset=0) / Address=#x1\r\nSource value: pointer(non-local, block_id=0, offset=1) / Address=#x1\r\nTarget value: pointer(non-local, block_id=1, offset=0) / Address=#x1\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```", "author": "bongjunj", "labels": [ "miscompilation", "llvm:analysis" ], "comments": [] }
true
null