Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
code
DOI:
Libraries:
Datasets
pandas
License:
Dataset Viewer
Auto-converted to Parquet
bug_id
stringlengths
5
6
issue_url
stringlengths
49
50
bug_type
stringclasses
3 values
base_commit
stringlengths
40
40
knowledge_cutoff
timestamp[us]
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
nullclasses
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13353, 13358 ], [ 13453, 13459 ] ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledSingleRegisterEntry" ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 12466, 12472 ] ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::isGatherShuffledSingleRegisterEntry" ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 13398, 13404 ] ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::getLastInstructionInBundle" ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ "InstCombinerImpl::foldICmpWithMinMax" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 7144, 7149 ] ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec" ], "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/DeadStoreElimination.cpp": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.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/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": 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, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.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/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 }, "bug_location_funcname": { "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "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/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/VectorCombine.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/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/Scalar/GVNSink.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.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/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.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 } }
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_locat(...TRUNCATED)
"commit 71051deff27928cff908ea794e09806eee662801\nAuthor: Nikita Popov <[email protected]>\nDate: (...TRUNCATED)
[{"file":"llvm/test/Transforms/MemCpyOpt/memcpy-zero-size.ll","commands":["opt -S -passes=memcpyopt (...TRUNCATED)
{"title":"Clang hangs forever building under -O1","body":"ToT Clang hangs when building under -O1.\r(...TRUNCATED)
true
null
End of preview. Expand in Data Studio

LLVM APR Benchmark: A Large-Scale Automated Program Repair Benchmark of Real-World LLVM Middle-End Bugs

GitHub (We only accept pull requests from GitHub)

Hugging Face Mirror

Hugging Face Leaderboard

Evaluation Result Submission

Motivation

The compiler is a critical infrastructure in the software development. The LLVM compiler infrastructure is widely used in both academia and industry. However, due to its inherent complexity, the LLVM compiler still contains many bugs that can be triggered in edge cases. As one of the LLVM maintainers, my job is to provide the minimal reproducible test cases for issues from fuzzers/ downstream users, and fix these bugs (or assign them to the right person). However, the process is time-consuming and boring. Thanks to the recent advances in compiler testing, we can automatically generate interesting test cases that trigger bugs and automatically reduce the tests to minimal ones. If we can also perform bug localization and repair automatically, it will significantly reduce the workload of us maintainers! Recently, LLM-based automated program repair (APR) techniques have been proposed. We have seen some successful cases in APR benchmarks like Defects4J and SWE-bench. But I believe that fixing LLVM bugs is more challenging than existing benchmarks due to its large C/C++ codebase, complex logic, long history, and the need for domain-specific knowledge. Therefore, I build this benchmark to see if we can automatically repair real-world LLVM bugs with the help of large language models and APR techniques. I hope this benchmark can help both SE researchers and LLVM community to understand how APR techniques work on a large-scale, real-world C/C++ project.

Dataset Description

In this benchmark, we only focus on three kinds of bugs in the LLVM middle-end:

  • Crash: the compiler terminates exceptionally or hits an assertion failure (LLVM is built with -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ABI_BREAKING_CHECKS=WITH_ASSERTS).
  • Miscompilation: the compiler generates incorrect program from a well-defined source code.
  • Hang: the compiler runs into an infinite loop or fails to reach a fixpoint.

All bugs can be triggered with an opt command and a small piece of LLVM textual IR.

This dataset collects some fixed LLVM middle-end bugs from GitHub issues since 2024-01-01. Each issue contains issue description, test cases, a reference patch, and some hints. All issues are checked against the following criteria:

  • At least one of the given test cases can be used to reproduce the bug at a specific commit (base_commit). For most of the miscompilation bugs, the src and tgt functions will be checked with alive2, an automatic refinement verification tool for LLVM. If miscompilation happens, alive-tv will provide a counterexample. The remaining miscompilation bugs will be checked by lli.
  • opt passes all the given tests after fixing the bug with the given reference patch (patch).
  • opt passes all regression tests at a specific commit (hints.fix_commit).

Take Issue121459 as an example:

{
  // Identifier of the bug. It can be an issue number, a pull request number,
  // or a commit hash.
  "bug_id": "121459",
  // Points to issue/PR/commit url
  "issue_url": "https://github.com/llvm/llvm-project/issues/121459",
  // Bug type: crash/miscompilation/hang
  "bug_type": "miscompilation",
  // Fixes should be applied at the base commit
  "base_commit": "68d265666e708bad1c63b419b6275aaba1a7dcd2",
  // Knowledge cutoff date. It is not allowed to use the web knowledge base
  // after this date or use a large language model trained with newer
  // information. Please check the "Rules" section for exemptions.
  "knowledge_cutoff": "2025-01-02T09:03:32Z",
  // Regression test directories
  "lit_test_dir": [
    "llvm/test/Transforms/InstCombine"
  ],
  // Bug localization hints at different granularity levels.
  // Note that this information is provided in a best-effort way.
  // They are not guaranteed to be available or accurate.
  "hints": {
    "fix_commit": "a4d92400a6db9566d84cb4b900149e36e117f452",
    "components": [
      "InstCombine"
    ],
    "bug_location_lineno": {
      "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [
        [
          2782,
          2787
        ],
        [
          2838,
          2843
        ],
        [
          2847,
          2852
        ]
      ]
    },
    "bug_location_funcname": {
      "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [
        "foldGEPOfPhi"
      ]
    }
  },
  // A reference patch extracted from hints.fix_commit
  "patch": "<omitted>",
  // Minimal reproducible tests
  "tests": [
    {
      "file": "llvm/test/Transforms/InstCombine/opaque-ptr.ll",
      "commands": [
        "opt -S -passes='instcombine<no-verify-fixpoint>' < %s"
      ],
      "tests": [
        {
          "test_name": "gep_of_phi_of_gep_different_type",
          "test_body": "<omitted>"
        },
        {
          "test_name": "gep_of_phi_of_gep_flags2",
          "test_body": "<omitted>"
        },
        {
          "test_name": "gep_of_phi_of_gep_flags1",
          "test_body": "<omitted>"
        }
      ]
    }
  ],
  // Issue description
  "issue": {
    "title": "[InstCombine] GEPNoWrapFlags is propagated incorrectly",
    "body": "<omitted>",
    "author": "dtcxzyw",
    "labels": [
      "miscompilation",
      "llvm:instcombine"
    ],
    "comments": []
  },
  "verified": true
}

As of January 20, 2025, this benchmark contains 226 issues. You can run python3 scripts/dataset_summary.py locally to obtain the latest statistics.

Total issues: 226
Verified issues: 226 (100.00%)

Bug type summary:
  miscompilation: 84
  crash: 135
  hang: 7

Bug component summary (Total = 43):
  LoopVectorize: 60
  SLPVectorizer: 50
  InstCombine: 47
  ScalarEvolution: 10
  VectorCombine: 7
  ValueTracking: 5
  IR: 5
  ConstraintElimination: 4
  InstructionSimplify: 4
  Local: 3
  MemCpyOptimizer: 3
  ...

Label summary:
  miscompilation: 86
  crash: 82
  vectorizers: 67
  llvm:instcombine: 50
  llvm:SLPVectorizer: 50
  crash-on-valid: 44
  llvm:transforms: 31
  llvm:analysis: 14
  llvm:SCEV: 11
  release:backport: 9
  confirmed: 9
  llvm:crash: 8
  regression: 6
  llvm:hang: 6
  floating-point: 4
  ...

Changed files count summary:
  Average: 1.15
  Max: 4
  Min: 1
  Median: 1

Inserted lines summary:
  Average: 11.04
  Max: 164
  Min: 0
  Median: 6

Deleted lines summary:
  Average: 5.64
  Max: 169
  Min: 0
  Median: 2

Test count summary:
  Average: 3.73
  Max: 107
  Min: 1
  Median: 1

Patch summary:
  Single file fix: 201 (88.94%)
  Single func fix: 173 (76.55%)
  Single hunk fix: 129 (57.08%)

You can see from the statistics that more than half of the bugs can be fixed with a single hunk. So I believe most of bugs can be fixed with the aid of LLM-based APR techniques :)

Getting Started

Prerequisites

  • A C++17 compatible compiler
  • ninja
  • ccache
  • Pre-built LLVM core libraries
  • alive-tv

You can follow the Dockerfile to setup the environment.

Installation

git clone https://github.com/dtcxzyw/llvm-apr-benchmark.git
cd llvm-apr-benchmark
pip3 install -r requirements.txt
mkdir -p work && cd work
git clone https://github.com/llvm/llvm-project.git

Please set the following environment variables:

export LAB_LLVM_DIR=<path-to-llvm-src>
export LAB_LLVM_BUILD_DIR=<path-to-llvm-build-dir>
export LAB_LLVM_ALIVE_TV=<path-to-alive-tv>
export LAB_DATASET_DIR=<path-to-llvm-apr-benchmark>/dataset
export LAB_FIX_DIR=<path-to-llvm-apr-benchmark>/examples/fixes

Usage

This benchmark provides two helper modules to allow researchers to easily interact with LLVM and this benchmark.

To use these two helpers:

sys.path.append(os.path.join(os.path.dirname(os.environ["LAB_DATASET_DIR"]), "scripts"))
import llvm_helper
from lab_env import Environment as Env

llvm_helper

# Environment variables
llvm_helper.llvm_dir # os.environ["LAB_LLVM_DIR"]
llvm_helper.llvm_build_dir # os.environ["LAB_LLVM_BUILD_DIR"]
llvm_helper.llvm_alive_tv # os.environ["LAB_LLVM_ALIVE_TV"]
llvm_helper.dataset_dir # os.environ["LAB_DATASET_DIR"]

# Execute git commands on the llvm source tree
source_code = llvm_helper.git_execute(['show', f'{commit}:{file_path}'])

# Get information of first failed test from the result of Environment.check_fast/check_full
res, log = env.check_fast()
if isinstance(log, list):
  test = llvm_helper.get_first_failed_test(log)

lab_env

env = Env(
    # Load an issue from dataset/{issue_id}.json
    issue_id,
    # The knowledge cutoff date of LLM
    base_model_knowledge_cutoff = "2024-01-01Z",
    # Max concurrent jobs for build/test
    max_build_jobs=None,
    max_test_jobs=None,
  )

# If any external knowledge is used, please call this function.
env.use_knowledge(url = "<url>", date = "<date>")
# Reset the source tree to the base commit. Please call it before each attempt.
env.reset()
# Build llvm
res, log = env.build()
# Provide a certificate with the patch and verification result
certificate = env.dump()
# Perform build + test
res, log = env.check_fast()
# Perform build + test + lit regression test
res, log = env.check_full()
# Issue information (always available)
bug_type = env.get_bug_type()
base_commit = env.get_base_commit()
tests = env.get_tests()
# Hints (optional)
fix_commit = env.get_hint_fix_commit()
components = env.get_hint_components()
files = env.get_hint_files()
functions = env.get_hint_bug_functions()
linenos = env.get_hint_line_level_bug_locations()
# Issue description (optional)
issue = env.get_hint_issue()
# Collect instructions and intrinsics from the given LLVM IR.
# Then it will retrieve descriptions from llvm/docs/LangRef.dst.
# It is useful for LLMs to understand new flags/attributes/metadata.
keywords = env.get_ir_keywords(llvm_ir)
desc = env.get_langref_desc(keywords)

Here is a simple repair loop:

env = Env(...)
# System prompts and user prompts
messages = []
while True:
  # Reset the LLVM source code tree
  env.reset()
  # Get information from env
  ...
  # Chat with LLM
  ...
  # Modify the source code in place
  ...
  res, log = env.check_full()
  if res:
    # The bug is fixed successfully
    cert = json.dumps(env.dump(log = messages), indent=2)
    print(cert)
    break
  # Append the feedback into user prompts for the next iteration
  messages.append(construct_user_prompt_from_feedback(log))

I have drafted a poor baseline which is powered by DeepSeek-R1. This baseline implementation is only for reference purposes since I am neither an expert in LLM nor APR.

Rules

To claim that your APR tool successfully fixes a bug, please obey the following rules:

  • Knowledge allowed to use:
    • Any static content/ dynamic feedback provided by lab_env.Environment
    • Any content in the LLVM source tree before the base commit
    • Large language model trained with dataset before the knowledge cutoff date
    • Any other content on the web created before the knowledge cutoff date
  • opt with this patch passes both the given tests and the regression testsuite.

License

This project is licensed under the Apache License 2.0. Please see the LICENSE for details.

Please cite this work with the following BibTex entry:

@misc{llvm-apr-benchmark,
  title = {LLVM APR Benchmark: A Large-Scale Automated Program Repair Benchmark of Real-World LLVM Middle-End Bugs},
  url = {https://github.com/dtcxzyw/llvm-apr-benchmark},
  author = {Yingwei Zheng},
  year = {2025},
}
Downloads last month
1,616

Space using dtcxzyw/llvm-apr-benchmark 1