Datasets:

Modalities:
Text
Formats:
json
Size:
< 1K
Tags:
code
DOI:
Libraries:
Datasets
pandas
License:
Dataset Viewer
Auto-converted to Parquet
bug_id
string
issue_url
string
bug_type
string
base_commit
string
knowledge_cutoff
timestamp[us]
lit_test_dir
list
hints
dict
patch
string
tests
list
issue
dict
verified
bool
properties
dict
test_commit
null
94897
https://github.com/llvm/llvm-project/issues/94897
miscompilation
add89088fb8de84fdbeb97c0386a831e51d090a1
2024-06-09T10:15:35
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "e4b0655b297e4f4b0eb26548c8be48d527ebc178", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ [ 2441, 2449 ] ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [ "InstCombinerImpl::foldICmpShlConstant" ], "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit e4b0655b297e4f4b0eb26548c8be48d527ebc178 Author: Yingwei Zheng <dtcxzyw2333@gmail.com> Date: Mon Jun 10 03:17:01 2024 +0800 [InstCombine] Fix missing argument typo in `InstCombinerImpl::foldICmpShlConstant` (#94899) Closes #94897. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 4203147bc6a5..3fce4a3c20b3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2441,9 +2441,10 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp, Type *TruncTy = ShType->getWithNewBitWidth(TypeBits - Amt); Constant *NewC = ConstantInt::get(TruncTy, RHSC.ashr(*ShiftAmt).trunc(TypeBits - Amt)); - return new ICmpInst( - CmpPred, Builder.CreateTrunc(X, TruncTy, "", Shl->hasNoSignedWrap()), - NewC); + return new ICmpInst(CmpPred, + Builder.CreateTrunc(X, TruncTy, "", /*IsNUW=*/false, + Shl->hasNoSignedWrap()), + NewC); } }
[ { "file": "llvm/test/Transforms/InstCombine/icmp.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "test_icmp_shl_sgt", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @test_icmp_shl_sgt(i64 %x) {\n %shl = shl i64 %x, 32\n %cmp = icmp sgt i64 %shl, 8589934591\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nuw_i31", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @test_icmp_shl_nuw_i31(i31 %x) {\n %shl = shl nuw i31 %x, 23\n %cmp = icmp ugt i31 %shl, -50331648\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_vec", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine <2 x i1> @test_icmp_shl_vec(<2 x i64> %x) {\n %shl = shl <2 x i64> %x, splat (i64 32)\n %cmp = icmp ult <2 x i64> %shl, splat (i64 8589934593)\n ret <2 x i1> %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nsw_i31", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @test_icmp_shl_nsw_i31(i31 %x) {\n %shl = shl nsw i31 %x, 23\n %cmp = icmp ugt i31 %shl, -50331648\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nsw", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @test_icmp_shl_nsw(i64 %x) {\n %shl = shl nsw i64 %x, 32\n %cmp = icmp ult i64 %shl, 8589934593\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "pr94897", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @pr94897(i32 range(i32 -2147483648, 0) %x) {\n %shl = shl nsw i32 %x, 24\n %cmp = icmp ugt i32 %shl, -50331648\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "test_icmp_shl_nuw", "test_body": "target datalayout = \"e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64\"\n\ndefine i1 @test_icmp_shl_nuw(i64 %x) {\n %shl = shl nuw i64 %x, 32\n %cmp = icmp ult i64 %shl, 8589934593\n ret i1 %cmp\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "wrong code at -O1 and above on x86_64-linux-gnu", "body": "This appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier.\r\n\r\nCompiler Explorer: https://godbolt.org/z/T9b4a7z3v\r\n\r\n```console\r\n% clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 338cbfef03e0ab58d7b52f3301928c58b194a1b4)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n% \r\n% clangtk -O0 small.c; ./a.out\r\n% clangtk -O1 small.c\r\n% ./a.out\r\nAborted\r\n% cat small.c\r\nint a;\r\nchar b(char c, char d) { return c - d; }\r\nint main() {\r\n int e;\r\n for (a = -10; a > -11; a--)\r\n e = b(a, -1);\r\n if (e > -2)\r\n __builtin_abort();\r\n return 0;\r\n}\r\n```", "author": "zhendongsu", "labels": [ "miscompilation", "confirmed", "llvm:instcombine" ], "comments": [ { "author": "dtcxzyw", "body": "Reproducer: https://alive2.llvm.org/ce/z/_3cyuT\r\n```ll\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\n\r\ndefine i1 @src() {\r\nentry:\r\n br label %for.body\r\n\r\nfor.body:\r\n %storemerge4 = phi i32 [ -10, %entry ], [ %dec, %for.body ]\r\n %dec = add nsw i32 %storemerge4, -1\r\n %cmp = icmp ugt i32 %dec, -11\r\n br i1 %cmp, label %for.body, label %for.end\r\n\r\nfor.end:\r\n %sub.i.le = shl nsw i32 %storemerge4, 24\r\n %cmp2 = icmp ugt i32 %sub.i.le, -50331648\r\n ret i1 %cmp2\r\n}\r\n\r\ndefine i1 @tgt() {\r\nentry:\r\n br label %for.body\r\n\r\nfor.body:\r\n %storemerge4 = phi i32 [ -10, %entry ], [ %dec, %for.body ]\r\n %dec = add nsw i32 %storemerge4, -1\r\n %cmp = icmp ugt i32 %dec, -11\r\n br i1 %cmp, label %for.body, label %for.end\r\n\r\nfor.end:\r\n %0 = trunc nuw i32 %storemerge4 to i8\r\n %cmp2 = icmp ugt i8 %0, -3\r\n ret i1 %cmp2\r\n}\r\n```\r\n\r\n`nuw` flag is incorrectly added." }, { "author": "dtcxzyw", "body": "Caused by https://github.com/llvm/llvm-project/commit/5c7c1f6aba467b1c5a51d58fc591314ecd7147ce." } ] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
133751
https://github.com/llvm/llvm-project/issues/133751
crash
2d7add6e2e56baf46504a8a22dec42b61f63360f
2025-03-31T16:55:56
[ "llvm/test/Transforms/SLPVectorizer" ]
{ "fix_commit": "bfd8cc0a3e82c5e6345a66dd5db5242accb6874b", "components": [ "SLPVectorizer" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ [ 8854, 8860 ] ], "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [ "BoUpSLP::buildTree_rec" ], "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit bfd8cc0a3e82c5e6345a66dd5db5242accb6874b Author: Alexey Bataev <a.bataev@outlook.com> Date: Mon Mar 31 10:31:18 2025 -0700 [SLP]Fix a check for the whole register use Need to check the value type, not the return type, of the instructions, when doing the analysis for the whole register use to prevent a compiler crash. Fixes #133751 diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index a4b0378abc07..0679eac17658 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -8854,7 +8854,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth, // FIXME: Reshuffing scalars is not supported yet for non-power-of-2 ops. if ((UserTreeIdx.UserTE && UserTreeIdx.UserTE->hasNonWholeRegisterOrNonPowerOf2Vec(*TTI)) || - !hasFullVectorsOrPowerOf2(*TTI, VL.front()->getType(), VL.size())) { + !hasFullVectorsOrPowerOf2(*TTI, getValueType(VL.front()), + VL.size())) { LLVM_DEBUG(dbgs() << "SLP: Reshuffling scalars not yet supported " "for nodes with padding.\n"); auto Invalid = ScheduleBundle::invalid();
[ { "file": "llvm/test/Transforms/SLPVectorizer/X86/cmp-values-non-full-registers.ll", "commands": [ "opt -S --passes=slp-vectorizer -mtriple=x86_64-grtev4-linux-gnu < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @test() {\n;\nentry:\n br i1 false, label %bb1, label %bb2\n\nbb2:\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %bb1\n\nbb1:\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %bb2 ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %bb2 ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %bb2 ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %bb2 ]\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "SLPVectorizer: \"Reshuffling scalars not yet supported for nodes with padding\" assert", "body": "```\n$ cat /tmp/a.ll\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-grtev4-linux-gnu\"\n\ndefine void @gsl_matrix_long_double_minmax_index() {\nentry:\n br i1 false, label %cleanup22, label %for.cond6.preheader.us.preheader\n\nfor.cond6.preheader.us.preheader: ; preds = %entry\n %cmp14.us = fcmp ogt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %jmax.2.us = select i1 %cmp14.us, i64 0, i64 0\n %cmp13.us = fcmp olt x86_fp80 0xK00000000000000000000, 0xK00000000000000000000\n %imin.2.us = select i1 %cmp13.us, i64 0, i64 0\n %jmin.2.us = select i1 %cmp13.us, i64 0, i64 0\n br label %cleanup22\n\ncleanup22: ; preds = %for.cond6.preheader.us.preheader, %entry\n %storemerge64 = phi i64 [ 0, %entry ], [ %imin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge63 = phi i64 [ 0, %entry ], [ %jmin.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge62 = phi i64 [ 0, %entry ], [ %imax.2.us, %for.cond6.preheader.us.preheader ]\n %storemerge = phi i64 [ 0, %entry ], [ %jmax.2.us, %for.cond6.preheader.us.preheader ]\n ret void\n}\n$ opt -p slp-vectorizer /tmp/a.ll -disable-output\nopt: ../../llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3714: TreeEntry *llvm::slpvectorizer::BoUpSLP::newTreeEntry(ArrayRef<Value *>, TreeEntry::EntryState, ScheduleBundle &, const InstructionsState &, const EdgeInfo &, ArrayRef<int>, ArrayRef<unsigned int>): Assertion `(hasFullVectorsOrPowerOf2(*TTI, \ngetValueType(VL.front()), VL.size()) || ReuseShuffleIndices.empty()) && \"Reshuffling scalars not yet supported for nodes with padding\"' failed. \n\n```\n\n@alexey-bataev ", "author": "aeubanks", "labels": [ "llvm:SLPVectorizer", "crash-on-valid" ], "comments": [] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
139103
https://github.com/llvm/llvm-project/issues/139103
crash
77d1db6df757ff86c69661e02dd5b402e120e5f5
2025-05-08T16:09:31
[ "llvm/test/Analysis/MemorySSA" ]
{ "fix_commit": "05f1e313948768fdd8527969cd79809cbd0654ff", "components": [ "MemorySSAUpdater" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ [ 1119, 1124 ], [ 1135, 1144 ] ], "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": [ "MemorySSAUpdater::applyInsertUpdates" ], "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit 05f1e313948768fdd8527969cd79809cbd0654ff Author: Yingwei Zheng <dtcxzyw2333@gmail.com> Date: Sat May 10 21:48:26 2025 +0800 [MemorySSAUpdater] Fix iterator invalidation bug in `applyInsertUpdates` (#139370) This patch defers resetting optimized accesses until all uses are replaced, to avoid invalidating the iterator. Closes https://github.com/llvm/llvm-project/issues/139103. Closes https://github.com/llvm/llvm-project/issues/139289. Closes https://github.com/llvm/llvm-project/issues/139308. diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp index aa9f0b6e100c..ecfecb03c375 100644 --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -1119,6 +1119,9 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates, if (auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) { for (auto &DefToReplaceUses : *DefsList) { BasicBlock *DominatingBlock = DefToReplaceUses.getBlock(); + // We defer resetting optimized accesses until all uses are replaced, to + // avoid invalidating the iterator. + SmallVector<MemoryUseOrDef *, 4> ResetOptimized; for (Use &U : llvm::make_early_inc_range(DefToReplaceUses.uses())) { MemoryAccess *Usr = cast<MemoryAccess>(U.getUser()); if (MemoryPhi *UsrPhi = dyn_cast<MemoryPhi>(Usr)) { @@ -1135,10 +1138,13 @@ void MemorySSAUpdater::applyInsertUpdates(ArrayRef<CFGUpdate> Updates, assert(IDom && "Block must have a valid IDom."); U.set(GetLastDef(IDom->getBlock())); } - cast<MemoryUseOrDef>(Usr)->resetOptimized(); + ResetOptimized.push_back(cast<MemoryUseOrDef>(Usr)); } } } + + for (auto *Usr : ResetOptimized) + Usr->resetOptimized(); } } }
[ { "file": "llvm/test/Analysis/MemorySSA/pr139103.ll", "commands": [ "opt -disable-output -passes=\"loop-mssa(licm,loop-rotate,licm,simple-loop-unswitch<nontrivial>),print<memoryssa>\" -verify-memoryssa < %s 2>&1" ], "tests": [ { "test_name": "<module>", "test_body": "\n; Make sure that we update MSSA correctly in this case.\n\n\ndefine void @test(ptr %p, i1 %cond) {\nentry:\n br label %for.header\n\nfor.header:\n br i1 false, label %exit.loopexit1, label %for.header2.preheader\n\nfor.header2.preheader:\n br label %for.body\n\nfor.header2:\n br i1 false, label %for.latch, label %for.body\n\nfor.body:\n store i32 0, ptr %p, align 4\n store i8 0, ptr %p, align 1\n br i1 %cond, label %for.header2, label %exit.loopexit\n\nfor.latch:\n br i1 false, label %for.inc, label %exit.loopexit1\n\nfor.inc:\n br label %for.header\n\nexit.loopexit:\n br label %exit\n\nexit.loopexit1:\n br label %exit\n\nexit:\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[MemorySSA][LoopRotate] Assertion `!Paths.empty() && \"Need a path to move\"' failed.", "body": "This is a recent regression (llvm version 37fecfaa63eef7bd9dff9c16d74e61c99e3ce70a).\nReproducer: https://godbolt.org/z/9MGhvsKPb\n```\n> bin/opt -passes=\"loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>)\" test.ll -S\nopt: /data/zyw/llvm-project/llvm/lib/Analysis/MemorySSA.cpp:783: {anonymous}::ClobberWalker::tryOptimizePhi(llvm::MemoryPhi*, llvm::MemoryAccess*, const llvm::MemoryLocation&)::<lambda(llvm::SmallVectorImpl<{anonymous}::ClobberWalker::TerminatedPath>&)>: Assertion `!Paths.empty() && \"Need a path to move\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: ../llvm-build/bin/opt -passes=loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>) test.ll -S\n1. Running pass \"function(loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>))\" on module \"test.ll\"\n2. Running pass \"loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>)\" on function \"func_137\"\n #0 0x00007ffff7dfebb2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/zyw/llvm-build/bin/../lib/libLLVMSupport.so.21.0git+0x1febb2)\n #1 0x00007ffff7dfbd1f llvm::sys::RunSignalHandlers() (/data/zyw/llvm-build/bin/../lib/libLLVMSupport.so.21.0git+0x1fbd1f)\n #2 0x00007ffff7dfbe64 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x00007ffff7842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007ffff78969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x00007ffff7842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007ffff78287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007ffff782871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007ffff7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00007ffff3f85027 (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.21.0git+0x385027)\n#10 0x00007ffff3f88c30 (anonymous namespace)::ClobberWalker::findClobber(llvm::BatchAAResults&, llvm::MemoryAccess*, (anonymous namespace)::UpwardsMemoryQuery&, unsigned int&) MemorySSA.cpp:0:0\n#11 0x00007ffff3f898cc llvm::MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(llvm::MemoryAccess*, llvm::BatchAAResults&, unsigned int&, bool, bool) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.21.0git+0x3898cc)\n#12 0x00007ffff3f8b01a llvm::MemorySSA::SkipSelfWalker::getClobberingMemoryAccess(llvm::MemoryAccess*, llvm::BatchAAResults&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.21.0git+0x38b01a)\n#13 0x00007ffff4f91e6a getClobberingMemoryAccess(llvm::MemorySSA&, llvm::BatchAAResults&, llvm::SinkAndHoistLICMFlags&, llvm::MemoryUseOrDef*) LICM.cpp:0:0\n#14 0x00007ffff4f99055 llvm::canSinkOrHoistInst(llvm::Instruction&, llvm::AAResults*, llvm::DominatorTree*, llvm::Loop*, llvm::MemorySSAUpdater&, bool, llvm::SinkAndHoistLICMFlags&, llvm::OptimizationRemarkEmitter*) (.part.0) LICM.cpp:0:0\n#15 0x00007ffff4fa223a llvm::hoistRegion(llvm::DomTreeNodeBase<llvm::BasicBlock>*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::TargetLibraryInfo*, llvm::Loop*, llvm::MemorySSAUpdater&, llvm::ScalarEvolution*, llvm::ICFLoopSafetyInfo*, llvm::SinkAndHoistLICMFlags&, llvm::OptimizationRemarkEmitter*, bool, bool) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x1a223a)\n#16 0x00007ffff4fa72e0 (anonymous namespace)::LoopInvariantCodeMotion::runOnLoop(llvm::Loop*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::TargetLibraryInfo*, llvm::TargetTransformInfo*, llvm::ScalarEvolution*, llvm::MemorySSA*, llvm::OptimizationRemarkEmitter*, bool) (.part.0) LICM.cpp:0:0\n#17 0x00007ffff4faa26c llvm::LICMPass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x1aa26c)\n#18 0x00007ffff66887f5 llvm::detail::PassModel<llvm::Loop, llvm::LICMPass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMPasses.so.21.0git+0x887f5)\n#19 0x00007ffff5018914 std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::Loop, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) (.isra.0) LoopPassManager.cpp:0:0\n#20 0x00007ffff5019c80 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x219c80)\n#21 0x00007ffff5019e3b llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x219e3b)\n#22 0x00007ffff66886d5 llvm::detail::PassModel<llvm::Loop, llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMPasses.so.21.0git+0x886d5)\n#23 0x00007ffff501b958 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x21b958)\n#24 0x00007ffff70ad865 llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xad865)\n#25 0x00007ffff3909a1d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x309a1d)\n#26 0x00007ffff70ad135 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xad135)\n#27 0x00007ffff39078d0 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x3078d0)\n#28 0x00007ffff70adaf5 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xadaf5)\n#29 0x00007ffff390857d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x30857d)\n#30 0x00007ffff7f9ba9b 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) (/data/zyw/llvm-build/bin/../lib/libLLVMOptDriver.so.21.0git+0x23a9b)\n#31 0x00007ffff7fa58ed optMain (/data/zyw/llvm-build/bin/../lib/libLLVMOptDriver.so.21.0git+0x2d8ed)\n#32 0x00007ffff7829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#33 0x00007ffff7829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#34 0x0000555555555095 _start (../llvm-build/bin/opt+0x1095)\nAborted (core dumped)\n```", "author": "dtcxzyw", "labels": [ "crash-on-valid", "llvm:analysis", "generated by fuzzer" ], "comments": [ { "author": "dtcxzyw", "body": "Reduced:\n```\n; bin/opt -passes=\"loop-mssa(licm,loop-rotate,licm,simple-loop-unswitch<nontrivial>)\" -verify-memoryssa test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @func_137(i1 %0) {\nentry:\n br label %for.cond9\n\nfor.cond9: ; preds = %for.inc519, %entry\n br i1 false, label %for.end521, label %for.cond23\n\nfor.cond23: ; preds = %if.else229, %for.cond9\n %l_1344.1 = phi i32 [ %conv50, %if.else229 ], [ 0, %for.cond9 ]\n br i1 true, label %for.end494, label %for.cond29\n\nfor.cond29: ; preds = %for.cond23\n store i32 0, ptr null, align 4\n %1 = load i32, ptr null, align 4\n %conv50 = xor i32 %1, %l_1344.1\n br i1 %0, label %if.else229, label %if.then204\n\nif.then204: ; preds = %for.cond29\n ret void\n\nif.else229: ; preds = %for.cond29\n br label %for.cond23\n\nfor.end494: ; preds = %for.cond23\n br i1 false, label %for.inc519, label %for.end521\n\nfor.inc519: ; preds = %for.end494\n br label %for.cond9\n\nfor.end521: ; preds = %for.end494, %for.cond9\n ret void\n}\n```\n```\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/Analysis/MemorySSA.cpp:2067: void llvm::MemorySSA::verifyOrderingDominationAndDefUses(IterT, VerificationLevel) const [with IterT = llvm::iterator_range<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, false, false, void, false, void>, false, false> >]: Assertion `dominates(MD, U) && \"Memory Def does not dominate it's uses\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: bin/opt -passes=loop-mssa(licm,loop-rotate,licm,simple-loop-unswitch<nontrivial>) -verify-memoryssa test.ll -S\n1. Running pass \"function(loop-mssa(licm<allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>))\" on module \"test.ll\"\n2. Running pass \"loop-mssa(licm<allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>)\" on function \"func_137\"\n #0 0x00007dd7dd025f52 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.21.0git+0x225f52)\n #1 0x00007dd7dd022e2f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.21.0git+0x222e2f)\n #2 0x00007dd7dd022f74 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #3 0x00007dd7dca45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)\n #4 0x00007dd7dca9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\n #5 0x00007dd7dca9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10\n #6 0x00007dd7dca9eb2c pthread_kill ./nptl/pthread_kill.c:89:10\n #7 0x00007dd7dca4527e raise ./signal/../sysdeps/posix/raise.c:27:6\n #8 0x00007dd7dca288ff abort ./stdlib/abort.c:81:7\n #9 0x00007dd7dca2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9\n#10 0x00007dd7dca3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)\n#11 0x00007dd7d43b84ef void llvm::MemorySSA::verifyOrderingDominationAndDefUses<llvm::iterator_range<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, false, false, void, false, void>, false, false>>>(llvm::iterator_range<llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, false, false, void, false, void>, false, false>>, llvm::MemorySSA::VerificationLevel) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.21.0git+0x3b84ef)\n#12 0x00007dd7d43b8c11 llvm::MemorySSA::verifyMemorySSA(llvm::MemorySSA::VerificationLevel) const (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMAnalysis.so.21.0git+0x3b8c11)\n#13 0x00007dd7d49c96ce (anonymous namespace)::LoopRotate::rotateLoop(llvm::Loop*, bool) LoopRotationUtils.cpp:0:0\n#14 0x00007dd7d49c9fbf llvm::LoopRotation(llvm::Loop*, llvm::LoopInfo*, llvm::TargetTransformInfo const*, llvm::AssumptionCache*, llvm::DominatorTree*, llvm::ScalarEvolution*, llvm::MemorySSAUpdater*, llvm::SimplifyQuery const&, bool, unsigned int, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMTransformUtils.so.21.0git+0x1c9fbf)\n#15 0x00007dd7d583ff34 llvm::LoopRotatePass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x23ff34)\n#16 0x00007dd7d73ac765 llvm::detail::PassModel<llvm::Loop, llvm::LoopRotatePass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libPolly.so.21.0git+0x1ac765)\n#17 0x00007dd7d5834aed llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x234aed)\n#18 0x00007dd7d583459c llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x23459c)\n#19 0x00007dd7d73ac815 llvm::detail::PassModel<llvm::Loop, llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libPolly.so.21.0git+0x1ac815)\n#20 0x00007dd7d5836395 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.21.0git+0x236395)\n#21 0x00007dd7dbcdaa45 llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xdaa45)\n#22 0x00007dd7d3d2a494 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x32a494)\n#23 0x00007dd7dbcda315 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xda315)\n#24 0x00007dd7d3d28d70 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x328d70)\n#25 0x00007dd7dbcdacd5 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.21.0git+0xdacd5)\n#26 0x00007dd7d3d29365 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.21.0git+0x329365)\n#27 0x00007dd7dd2712e9 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.21.0git+0x2c2e9)\n#28 0x00007dd7dd27c306 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.21.0git+0x37306)\n#29 0x00007dd7dca2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\n#30 0x00007dd7dca2a28b call_init ./csu/../csu/libc-start.c:128:20\n#31 0x00007dd7dca2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5\n#32 0x000063062f7cd095 _start (bin/opt+0x1095)\n\nAborted (core dumped)\n```" }, { "author": "dtcxzyw", "body": "Bisected to 4d60c6d9b2c863d773aac9b59af8780e5ba23fcd\ncc @arsenm @nikic " }, { "author": "dtcxzyw", "body": "Another reproducer:\n```\n; bin/opt -passes=\"loop-mssa(licm,loop-rotate,licm,simple-loop-unswitch<nontrivial>)\" -verify-memoryssa test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test(ptr %p, i1 %cond) {\nentry:\n br label %for.header\n\nfor.header:\n br i1 false, label %exit.loopexit1, label %for.header2.preheader\n\nfor.header2.preheader:\n br label %for.body\n\nfor.header2:\n br i1 false, label %for.latch, label %for.body\n\nfor.body:\n store i32 0, ptr %p, align 4\n store i8 0, ptr %p, align 1\n br i1 %cond, label %for.header2, label %exit.loopexit\n\nfor.latch:\n br i1 false, label %for.inc, label %exit.loopexit1\n\nfor.inc:\n br label %for.header\n\nexit.loopexit:\n br label %exit\n\nexit.loopexit1:\n br label %exit\n\nexit:\n ret void\n}\n```" }, { "author": "dtcxzyw", "body": "I will post a patch later.\n" }, { "author": "dtcxzyw", "body": "https://github.com/llvm/llvm-project/commit/4d60c6d9b2c863d773aac9b59af8780e5ba23fcd is correct. This is an iterator-invalidation bug in MemorySSA.\n" } ] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
102351
https://github.com/llvm/llvm-project/issues/102351
miscompilation
203a2ca8cd6af505e11a38aebceeaf864271042c
2024-08-07T18:49:59
[ "llvm/test/Transforms/SimplifyCFG" ]
{ "fix_commit": "3c9022c965b85951f30af140da591f819acef8a0", "components": [ "Local" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": [ [ 1028, 1034 ], [ 1133, 1139 ] ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": [ "CanRedirectPredsOfEmptyBBToSucc", "llvm::TryToSimplifyUncondBranchFromEmptyBlock" ], "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit 3c9022c965b85951f30af140da591f819acef8a0 Author: AdityaK <hiraditya@msn.com> Date: Tue Sep 10 22:39:02 2024 -0700 Bail out jump threading on indirect branches (#103688) The bug was introduced by https://github.com/llvm/llvm-project/pull/68473 Fixes: #102351 diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index d0669e44f821..c85c819263e2 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1028,7 +1028,14 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ, if (!BB->hasNPredecessorsOrMore(2)) return false; - // Get single common predecessors of both BB and Succ + if (any_of(BBPreds, [](const BasicBlock *Pred) { + return isa<PHINode>(Pred->begin()) && + isa<IndirectBrInst>(Pred->getTerminator()); + })) + return false; + + // Get the single common predecessor of both BB and Succ. Return false + // when there are more than one common predecessors. for (BasicBlock *SuccPred : SuccPreds) { if (BBPreds.count(SuccPred)) { if (CommonPred) @@ -1133,7 +1140,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, bool BBKillable = CanPropagatePredecessorsForPHIs(BB, Succ, BBPreds); - // Even if we can not fold bB into Succ, we may be able to redirect the + // Even if we can not fold BB into Succ, we may be able to redirect the // predecessors of BB to Succ. bool BBPhisMergeable = BBKillable ||
[ { "file": "llvm/test/Transforms/SimplifyCFG/switch-branch-fold-indirectbr-102351.ll", "commands": [ "opt < %s -passes=simplifycfg -S" ], "tests": [ { "test_name": "main", "test_body": "@.str = private unnamed_addr constant [23 x i8] c\"OP_1:(instruction=%d)\\0A\\00\", align 1\n@.str.1 = private unnamed_addr constant [28 x i8] c\"TERMINATE:(instruction=%d)\\0A\\00\", align 1\n\n; Function Attrs: mustprogress norecurse uwtable\ndefine dso_local noundef i32 @main() #0 {\nentry:\n %bytecode = alloca [2 x ptr], align 16\n store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5\n %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1\n store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5\n br label %while.body\n\nwhile.body: ; preds = %entry, %sw.epilog\n %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ]\n %index.0 = phi i32 [ 0, %entry ], [ %index.2, %sw.epilog ]\n switch i32 %state.0, label %sw.epilog [\n i32 0, label %sw.bb\n i32 1, label %VM__OP_1\n i32 2, label %sw.bb4\n ]\n\nsw.bb: ; preds = %while.body\n br label %indirectgoto\n\nVM__OP_1: ; preds = %while.body, %indirectgoto\n %index.1 = phi i32 [ %index.3, %indirectgoto ], [ %index.0, %while.body ]\n br label %sw.epilog\n\nsw.bb4: ; preds = %while.body\n %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0)\n %inc = add nsw i32 %index.0, 1\n br label %indirectgoto\n\nsw.epilog: ; preds = %while.body, %VM__OP_1\n %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ]\n %index.2 = phi i32 [ %index.0, %while.body ], [ %index.1, %VM__OP_1 ]\n br label %while.body, !llvm.loop !9\n\nVM__TERMINATE: ; preds = %indirectgoto\n %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3)\n ret i32 0\n\nindirectgoto: ; preds = %sw.bb4, %sw.bb\n %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %sw.bb ]\n %idxprom.pn = sext i32 %index.3 to i64\n %indirect.goto.dest.in = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 %idxprom.pn\n %indirect.goto.dest = load ptr, ptr %indirect.goto.dest.in, align 8, !tbaa !5\n indirectbr ptr %indirect.goto.dest, [label %VM__OP_1, label %VM__TERMINATE]\n}\ndeclare i32 @printf(ptr noundef, ...) #1\n\nattributes #0 = { mustprogress norecurse uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\nattributes #1 = { \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\n\n!llvm.module.flags = !{!0, !1, !2, !3}\n!llvm.ident = !{!4}\n\n!0 = !{i32 1, !\"wchar_size\", i32 4}\n!1 = !{i32 8, !\"PIC Level\", i32 2}\n!2 = !{i32 7, !\"PIE Level\", i32 2}\n!3 = !{i32 7, !\"uwtable\", i32 2}\n!4 = !{!\"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)\"}\n!5 = !{!6, !6, i64 0}\n!6 = !{!\"any pointer\", !7, i64 0}\n!7 = !{!\"omnipotent char\", !8, i64 0}\n!8 = !{!\"Simple C++ TBAA\"}\n!9 = !{!10, !10, i64 0}\n!10 = !{!\"int\", !7, i64 0}\n!11 = distinct !{!11, !12, !13}\n!12 = !{!\"llvm.loop.mustprogress\"}\n!13 = !{!\"llvm.loop.unroll.disable\"}", "lli_expected_out": "OP_1:(instruction=0)\nTERMINATE:(instruction=1)\n", "additional_args": null } ] } ]
{ "title": "Miscompile in code with indirect gotos", "body": "The simplifycfg pass (incorrectly?) optimizes one of the case statements.\r\n\r\n```llvm\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n@.str = private unnamed_addr constant [23 x i8] c\"OP_1:(instruction=%d)\\0A\\00\", align 1\r\n@.str.1 = private unnamed_addr constant [28 x i8] c\"TERMINATE:(instruction=%d)\\0A\\00\", align 1\r\n\r\n; Function Attrs: mustprogress norecurse uwtable\r\ndefine dso_local noundef i32 @main() #0 {\r\nentry:\r\n %bytecode = alloca [2 x ptr], align 16\r\n store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5\r\n %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1\r\n store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5\r\n br label %while.body\r\n\r\nwhile.body: ; preds = %entry, %sw.epilog\r\n %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ]\r\n %index.0 = phi i32 [ 0, %entry ], [ %index.2, %sw.epilog ]\r\n switch i32 %state.0, label %sw.epilog [\r\n i32 0, label %sw.bb\r\n i32 1, label %VM__OP_1\r\n i32 2, label %sw.bb4\r\n ]\r\n\r\nsw.bb: ; preds = %while.body\r\n br label %indirectgoto\r\n\r\nVM__OP_1: ; preds = %while.body, %indirectgoto\r\n %index.1 = phi i32 [ %index.3, %indirectgoto ], [ %index.0, %while.body ]\r\n br label %sw.epilog\r\n\r\nsw.bb4: ; preds = %while.body\r\n %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0)\r\n %inc = add nsw i32 %index.0, 1\r\n br label %indirectgoto\r\n\r\nsw.epilog: ; preds = %while.body, %VM__OP_1\r\n %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ]\r\n %index.2 = phi i32 [ %index.0, %while.body ], [ %index.1, %VM__OP_1 ]\r\n br label %while.body, !llvm.loop !9\r\n\r\nVM__TERMINATE: ; preds = %indirectgoto\r\n %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3)\r\n ret i32 0\r\n\r\nindirectgoto: ; preds = %sw.bb4, %sw.bb\r\n %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %sw.bb ]\r\n %idxprom.pn = sext i32 %index.3 to i64\r\n %indirect.goto.dest.in = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 %idxprom.pn\r\n %indirect.goto.dest = load ptr, ptr %indirect.goto.dest.in, align 8, !tbaa !5\r\n indirectbr ptr %indirect.goto.dest, [label %VM__OP_1, label %VM__TERMINATE]\r\n}\r\ndeclare i32 @printf(ptr noundef, ...) #1\r\n\r\nattributes #0 = { mustprogress norecurse uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #1 = { \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\n\r\n!llvm.module.flags = !{!0, !1, !2, !3}\r\n!llvm.ident = !{!4}\r\n\r\n!0 = !{i32 1, !\"wchar_size\", i32 4}\r\n!1 = !{i32 8, !\"PIC Level\", i32 2}\r\n!2 = !{i32 7, !\"PIE Level\", i32 2}\r\n!3 = !{i32 7, !\"uwtable\", i32 2}\r\n!4 = !{!\"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)\"}\r\n!5 = !{!6, !6, i64 0}\r\n!6 = !{!\"any pointer\", !7, i64 0}\r\n!7 = !{!\"omnipotent char\", !8, i64 0}\r\n!8 = !{!\"Simple C++ TBAA\"}\r\n!9 = !{!10, !10, i64 0}\r\n!10 = !{!\"int\", !7, i64 0}\r\n!11 = distinct !{!11, !12, !13}\r\n!12 = !{!\"llvm.loop.mustprogress\"}\r\n!13 = !{!\"llvm.loop.unroll.disable\"}\r\n```\r\n\r\n$ opt -passes=simplifycfg orig.ll -S -o out.ll\r\n```llvm\r\n; ModuleID = 'orig.ll'\r\nsource_filename = \"orig.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n@.str = private unnamed_addr constant [23 x i8] c\"OP_1:(instruction=%d)\\0A\\00\", align 1\r\n@.str.1 = private unnamed_addr constant [28 x i8] c\"TERMINATE:(instruction=%d)\\0A\\00\", align 1\r\n\r\n; Function Attrs: mustprogress norecurse uwtable\r\ndefine dso_local noundef i32 @main() #0 {\r\nentry:\r\n %bytecode = alloca [2 x ptr], align 16\r\n store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5\r\n %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1\r\n store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5\r\n br label %while.body\r\n\r\nwhile.body: ; preds = %sw.epilog, %entry\r\n %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ]\r\n %index.0 = phi i32 [ 0, %entry ], [ %index.0, %sw.epilog ]\r\n switch i32 %state.0, label %sw.epilog [\r\n i32 0, label %VM__TERMINATE\r\n i32 1, label %VM__OP_1\r\n i32 2, label %sw.bb4\r\n ]\r\n\r\nVM__OP_1: ; preds = %while.body\r\n br label %sw.epilog\r\n\r\nsw.bb4: ; preds = %while.body\r\n %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0)\r\n %inc = add nsw i32 %index.0, 1\r\n br label %VM__TERMINATE\r\n\r\nsw.epilog: ; preds = %VM__OP_1, %while.body\r\n %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ]\r\n br label %while.body, !llvm.loop !9\r\n\r\nVM__TERMINATE: ; preds = %sw.bb4, %while.body\r\n %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %while.body ]\r\n %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3)\r\n ret i32 0\r\n}\r\n\r\ndeclare i32 @printf(ptr noundef, ...) #1\r\n\r\nattributes #0 = { mustprogress norecurse uwtable \"min-legal-vector-width\"=\"0\" \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\nattributes #1 = { \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"x86-64\" \"target-features\"=\"+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87\" \"tune-cpu\"=\"generic\" }\r\n\r\n!llvm.module.flags = !{!0, !1, !2, !3}\r\n!llvm.ident = !{!4}\r\n\r\n!0 = !{i32 1, !\"wchar_size\", i32 4}\r\n!1 = !{i32 8, !\"PIC Level\", i32 2}\r\n!2 = !{i32 7, !\"PIE Level\", i32 2}\r\n!3 = !{i32 7, !\"uwtable\", i32 2}\r\n!4 = !{!\"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)\"}\r\n!5 = !{!6, !6, i64 0}\r\n!6 = !{!\"any pointer\", !7, i64 0}\r\n!7 = !{!\"omnipotent char\", !8, i64 0}\r\n!8 = !{!\"Simple C++ TBAA\"}\r\n!9 = !{!10, !10, i64 0}\r\n!10 = !{!\"int\", !7, i64 0}\r\n```", "author": "hiraditya", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "hiraditya", "body": "Original C code\r\n\r\n```c\r\nextern int printf(const char *fmt, ...);\r\n\r\nint main() {\r\n void* bytecode[2];\r\n bytecode[0] = &&VM__OP_1;\r\n bytecode[1] = &&VM__TERMINATE;\r\n\r\n int state = 0;\r\n int index = 0;\r\n\r\n while (1) {\r\n switch (state) {\r\n case 0:\r\n goto *bytecode[index];\r\n case 1:\r\n // NOTE: THIS IS ONLY REACHABLE VIA INDIRECT GOTOS\r\n VM__OP_1:\r\n state = 2;\r\n break;\r\n case 2:\r\n printf(\"OP_1:(instruction=%d)\\n\", index);\r\n index++;\r\n goto *bytecode[index];\r\n }\r\n }\r\n\r\nVM__TERMINATE:\r\n printf(\"TERMINATE:(instruction=%d)\\n\", index);\r\n return 0;\r\n}\r\n```\r\n\r\nhttps://github.com/llvm/llvm-project/pull/76295 makes the miscompile go away(https://godbolt.org/z/d9bGnhhv6) but I think simplifycfg still has the bug.\r\n" }, { "author": "efriedma-quic", "body": "Looks like TryToSimplifyUncondBranchFromEmptyBlock is not handling indirectbr predecessors correctly: the indirectbr's successor list is rewritten so it has a successor that isn't address-taken. That edge is then proven impossible, so the indirectbr is completely eliminated." } ] }
true
{ "is_single_file_fix": true, "is_single_func_fix": false }
null
76852
https://github.com/llvm/llvm-project/issues/76852
crash
4d11f04b20f0bd7488e19e8f178ba028412fa519
2024-01-03T19:32:37
[ "llvm/test/Transforms/LoopDeletion" ]
{ "fix_commit": "a0b911745494e3c2f53a27f23c536314818ce0b1", "components": [ "LoopDeletion" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": [ [ 452, 457 ], [ 487, 499 ] ], "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": [ "deleteLoopIfDead" ], "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit a0b911745494e3c2f53a27f23c536314818ce0b1 Author: Manish Kausik H <46352931+Nirhar@users.noreply.github.com> Date: Fri Jan 19 20:00:20 2024 +0530 LoopDeletion: Move EH pad check before the isLoopNeverExecuted Check (#78189) This commit modifies `LoopDeletion::deleteLoopIfDead` to check if the exit block of a loop is an EH pad before checking if the loop gets executed. This handles the case where an unreachable loop has a landingpad as an Exit block, and the loop gets deleted, leaving leaving the landingpad without an edge from an unwind clause. Fixes #76852. diff --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp index c041e3621a16..bfe9374cf2f8 100644 --- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp @@ -452,6 +452,13 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT, BasicBlock *ExitBlock = L->getUniqueExitBlock(); + // We can't directly branch to an EH pad. Don't bother handling this edge + // case. + if (ExitBlock && ExitBlock->isEHPad()) { + LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n"); + return LoopDeletionResult::Unmodified; + } + if (ExitBlock && isLoopNeverExecuted(L)) { LLVM_DEBUG(dbgs() << "Loop is proven to never execute, delete it!\n"); // We need to forget the loop before setting the incoming values of the exit @@ -487,13 +494,6 @@ static LoopDeletionResult deleteLoopIfDead(Loop *L, DominatorTree &DT, return LoopDeletionResult::Unmodified; } - // We can't directly branch to an EH pad. Don't bother handling this edge - // case. - if (ExitBlock && ExitBlock->isEHPad()) { - LLVM_DEBUG(dbgs() << "Cannot delete loop exiting to EH pad.\n"); - return LoopDeletionResult::Unmodified; - } - // Finally, we have to check that the loop really is dead. bool Changed = false; if (!isLoopDead(L, SE, ExitingBlocks, ExitBlock, Changed, Preheader, LI)) {
[ { "file": "llvm/test/Transforms/LoopDeletion/loop-with-ehpad-not-executed.ll", "commands": [ "opt %s -passes=loop-deletion -S" ], "tests": [ { "test_name": "<module>", "test_body": "\ndefine void @wombat() personality ptr null {\n;\nbb:\n br i1 false, label %bb1, label %bb4\n\nbb1: ; preds = %bb\n br label %bb2\n\nbb2: ; preds = %bb1, %bb2\n %invoke = invoke double null()\n to label %bb2 unwind label %bb3\n\nbb3: ; preds = %bb2\n %landingpad = landingpad { ptr, i32 }\n cleanup\n ret void\n\nbb4: ; preds = %bb\n ret void\n}", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": " LLVM ERROR: Broken module found, compilation aborted!", "body": "The bug was found by FuzzGen IR test generator\r\n\r\nRun opt with -passes=loop-deletion \r\nhttps://godbolt.org/z/16zoTYEqx\r\n\r\nTest.ll\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() gc \"statepoint-example\" personality ptr null {\r\nbb:\r\n br i1 false, label %bb1, label %bb4\r\n\r\nbb1: ; preds = %bb\r\n br label %bb2\r\n\r\nbb2: ; preds = %bb1, %bb2\r\n %invoke = invoke double null(i64 0)\r\n to label %bb2 unwind label %bb3\r\n\r\nbb3: ; preds = %bb2\r\n %landingpad = landingpad { ptr, i32 }\r\n cleanup\r\n ret void\r\n\r\nbb4: ; preds = %bb\r\n ret void\r\n}\r\n```\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-deletion <source>\r\n #0 0x0000000003597b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3597b18)\r\n #1 0x000000000359526c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007fee38042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007fee380969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007fee38042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007fee380287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00000000007905f3 llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0\r\n #7 0x00000000034dea68 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x34dea68)\r\n #8 0x0000000002f6f993 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f6f993)\r\n #9 0x000000000088bbae llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x88bbae)\r\n#10 0x0000000002f34d6c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f34d6c)\r\n#11 0x0000000000895cca llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x895cca)\r\n#12 0x000000000079c483 main (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x79c483)\r\n#13 0x00007fee38029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#14 0x00007fee38029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#15 0x000000000088af1e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x88af1e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```", "author": "TatyanaDoubts", "labels": [ "loopoptim", "crash" ], "comments": [ { "author": "Nirhar", "body": "Just looked at the IR after loop deletion and before the verify pass, and looks like loop-deletion incorrectly considered the block with the landingpad as the exit block of the loop:\r\n```\r\ndefine void @wombat() gc \"statepoint-example\" personality ptr null {\r\nbb:\r\n br i1 false, label %bb1, label %bb4\r\n\r\nbb1: ; preds = %bb\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb1\r\n %landingpad = landingpad { ptr, i32 }\r\n cleanup\r\n ret void\r\n\r\nbb4: ; preds = %bb\r\n ret void\r\n}\r\n\r\n$28 = void\r\n```\r\nThe problem seems to be with `Loop::getUniqueExitBlock` from https://github.com/llvm/llvm-project/blob/b6fc463d4c0b00e0741776f9d41b47f532a80b9e/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L453\r\n\r\nwhich returns the landingpad as the exit block of the loop. Perhaps this must be altered to consider that unwind edges are not real edges in the DAG. \r\n\r\n\r\n" }, { "author": "Nirhar", "body": "I'm not sure who are the right persons to consult on this. @EugeneZelenko I leave it to you for you to add them." }, { "author": "nikic", "body": "@Nirhar Isn't this already guarded by https://github.com/llvm/llvm-project/blob/b6fc463d4c0b00e0741776f9d41b47f532a80b9e/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L492?" }, { "author": "nikic", "body": "Ah, this case hits the isLoopNeverExecuted() branch. So that check should just get moved higher, so it covers that case as well." }, { "author": "Nirhar", "body": "@nikic Ah yes that makes sense. I'll land a patch for this soon!\r\n" }, { "author": "Nirhar", "body": "@nikic On second thought, moving the landing pad check higher will not delete the loop, given that this loop never gets executed as well. Isn't it a better solution to delete the loop as well as delete the landing pad instruction?\r\n\r\nEssentially I propose to first check if the loop never gets executed. If yes, delete the loop. Next check if the exit block is a landing pad used exclusively by the loop. If yes, delete the landing pad as well. Is this solution acceptable to you?\r\n\r\nAlso is it correct to call the landing pad as an `ExitBlock`? In my opinion, semantically the landingpad should not be the block that `L->getUniqueExitBlock` returns given that the landingpad is not a part of the loop's logic. Thus in this case according to me `L->getUniqueExitBlock` should have returned a nullptr, and we should have hit the branch https://github.com/llvm/llvm-project/blob/b6fc463d4c0b00e0741776f9d41b47f532a80b9e/llvm/lib/Transforms/Scalar/LoopDeletion.cpp#L485 " }, { "author": "nikic", "body": "> On second thought, moving the landing pad check higher will not delete the loop, given that this loop never gets executed as well. Isn't it a better solution to delete the loop as well as delete the landing pad instruction?\r\n\r\nThis is a degenerate case, it is not worthwhile to try and optimize it. It's possible to handle this case, but it's much harder than you think. The current code will always replace a loop with a branch to the exit, even if the loop is known to never execute, because this preserves the outer loop structure. If we replaced the entire loop with unreachable (which is what would really be necessary to handle the landingpad case) we may also break an outer loop and would have to perform corresponding loop info updates.\r\n\r\n> Also is it correct to call the landing pad as an ExitBlock? \r\n\r\nNote that ExitBlock and ExitingBlock are different things. And ExitingBlock is part of the loop and branches to an ExitBlock not part of the loop. So yes, landingpad is a valid ExitBlock here." }, { "author": "Nirhar", "body": "Understood, thanks for the clarification @nikic !" } ] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
118467
https://github.com/llvm/llvm-project/issues/118467
miscompilation
73731d6873b6fb0757c3065aaf2452eaccd0eebc
2024-12-03T10:44:21
[ "llvm/test/Transforms/AggressiveInstCombine" ]
{ "fix_commit": "f68b0e36997322eeda8fd199ea80deb1b49c5410", "components": [ "AggressiveInstCombine" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": [ [ 803, 810 ] ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": [ "foldConsecutiveLoads" ], "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit f68b0e36997322eeda8fd199ea80deb1b49c5410 Author: Antonio Frighetto <me@antoniofrighetto.com> Date: Wed Dec 4 10:15:11 2024 +0100 [AggressiveInstCombine] Use APInt and avoid truncation when folding loads A miscompilation issue has been addressed with improved handling. Fixes: https://github.com/llvm/llvm-project/issues/118467. diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp index b5b561797f75..45ee2d472a11 100644 --- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp +++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp @@ -803,8 +803,7 @@ static bool foldConsecutiveLoads(Instruction &I, const DataLayout &DL, APInt Offset1(DL.getIndexTypeSizeInBits(Load1Ptr->getType()), 0); Load1Ptr = Load1Ptr->stripAndAccumulateConstantOffsets( DL, Offset1, /* AllowNonInbounds */ true); - Load1Ptr = Builder.CreatePtrAdd(Load1Ptr, - Builder.getInt32(Offset1.getZExtValue())); + Load1Ptr = Builder.CreatePtrAdd(Load1Ptr, Builder.getInt(Offset1)); } // Generate wider load. NewLoad = Builder.CreateAlignedLoad(WiderType, Load1Ptr, LI1->getAlign(),
[ { "file": "llvm/test/Transforms/AggressiveInstCombine/X86/or-load.ll", "commands": [ "opt < %s -passes=aggressive-instcombine -mtriple x86_64-none-eabi -mattr=avx2 -data-layout=\"e-n64\" -S", "opt < %s -passes=aggressive-instcombine -mtriple x86_64-none-eabi -mattr=avx2 -data-layout=\"E-n64\" -S" ], "tests": [ { "test_name": "loadcombine_consecutive_idx_64", "test_body": "define i32 @loadcombine_consecutive_idx_64(ptr %data) {\nentry:\n %arrayidx = getelementptr inbounds nuw i8, ptr %data, i64 2149675577\n %val = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %val to i32\n %arrayidx.2 = getelementptr inbounds nuw i8, ptr %data, i64 2149675576\n %val.2 = load i8, ptr %arrayidx.2, align 1\n %conv.2 = zext i8 %val.2 to i32\n %shl = shl nuw nsw i32 %conv, 8\n %or = or disjoint i32 %shl, %conv.2\n ret i32 %or\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "Invalid LLVM IR code generated on x86-64 with a very simple sample (crash the generated executable code)", "body": "Below is a very simple program that's loading 16 bits table value into a 32 bits variable from a 8 bits table.\nOn **x86-64** with **-O2** or **-O3** flags, this program works fine with LLVM 16.0.0 and below, but since LLVM 17.0.0, the LLVM IR and the generated assembly code are using a wrong calculated offset on the table (doesn't occurs on LLVM armv8 whatever the version).\nAs you can see below, the offset in the table which is supposed to be **2149675576** (**0x80217238**) has its 32 upper bits inverted for **-2145291720** (**0xFFFFFFFF80217238**).\n\n```c\n\n#include <stdint.h>\n\n// Load 16 bits into 32 bits value from data offset 0x80217238\n\nuint32_t Test(const uint8_t* data)\n{ \n uint32_t a, b, c; \n\tb = 0xFFFF8022 << 16;\n b += 0xFFFFE808; \n a = data[b + 0xFFFF8A31];\n c = data[b + 0xFFFF8A30];\n c &= ~0x0000FF00;\n c |= ((a << 8) | (a >> 24)) & 0x0000FF00;\n\treturn c;\n}\n\n```\n\nLLVM IR with LLVM 16.0.0 (from Compiler Explorer)\n```ll\ndefine dso_local noundef i32 @Test(unsigned char const*)(ptr nocapture noundef readonly %data) local_unnamed_addr {\nentry:\n %arrayidx4 = getelementptr inbounds i8, ptr %data, i64 2149675576\n %0 = load i16, ptr %arrayidx4, align 1\n %1 = zext i16 %0 to i32\n ret i32 %1\n}\n\ndeclare void @llvm.dbg.value(metadata, metadata, metadata) #1\n```\nLLVM IR with LLVM 19.1.0 and trunk (from Compiler Explorer)\n```ll\ndefine dso_local noundef range(i32 0, 65536) i32 @Test(unsigned char const*)(ptr nocapture noundef readonly %data) local_unnamed_addr {\nentry:\n %0 = getelementptr i8, ptr %data, i64 -2145291720\n %1 = load i16, ptr %0, align 1\n %2 = zext i16 %1 to i32\n ret i32 %2\n}\n```\n\n\n\n\n\n", "author": "dje64240", "labels": [ "miscompilation", "llvm:transforms" ], "comments": [ { "author": "topperc", "body": "opt-bisect suggests AggressiveInstCominer. There were two separate loads that got merged. The resulting GEP had an index of `i32 -2145291720` with trunk and `i64 2149675576` with clang 16. Those would be the same number if GEP zero extended indices instead of sign extending." }, { "author": "antoniofrighetto", "body": "Alive2: https://alive2.llvm.org/ce/z/G5CgkD." }, { "author": "AZero13", "body": "> opt-bisect suggests AggressiveInstCominer. There were two separate loads that got merged. The resulting GEP had an index of `i32 -2145291720` with trunk and `i64 2149675576` with clang 16. Those would be the same number if GEP zero extended indices instead of sign extending.\n\nSee my PR for 19.x " } ] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
112467
https://github.com/llvm/llvm-project/issues/112467
miscompilation
9df8d8d05c2650b51bd4233e1759206d163f3133
2024-10-16T03:31:20
[ "llvm/test/Transforms/InstCombine" ]
{ "fix_commit": "3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a", "components": [ "InstCombine" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ [ 3369, 3376 ] ], "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [ "InstCombinerImpl::foldAndOrOfICmps" ], "llvm/lib/Transforms/IPO/GlobalOpt.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit 3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a Author: Yingwei Zheng <dtcxzyw2333@gmail.com> Date: Wed Oct 16 16:24:44 2024 +0800 [InstCombine] Drop `samesign` flag in `foldAndOrOfICmpsWithConstEq` (#112489) In https://github.com/llvm/llvm-project/commit/5dbfca30c1a672cd0c5089df2b4fdd171436643a we assume that RHS is poison implies LHS is also poison. It doesn't hold after introducing samesign flag. This patch drops the `samesign` flag on RHS if the original expression is a logical and/or. Closes #112467. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 64bee4ab974e..c8407e8ba5ab 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -3369,8 +3369,14 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, // We can convert this case to bitwise and, because both operands are used // on the LHS, and as such poison from both will propagate. if (Value *V = foldAndOrOfICmpsWithConstEq(RHS, LHS, IsAnd, - /*IsLogical*/ false, Builder, Q)) + /*IsLogical=*/false, Builder, Q)) { + // If RHS is still used, we should drop samesign flag. + if (IsLogical && RHS->hasSameSign() && !RHS->use_empty()) { + RHS->setSameSign(false); + addToWorklist(RHS); + } return V; + } if (Value *V = foldIsPowerOf2OrZero(LHS, RHS, IsAnd, Builder, *this)) return V;
[ { "file": "llvm/test/Transforms/InstCombine/and-or-icmp-min-max.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "sge_and_max_commute", "test_body": "define i1 @sge_and_max_commute(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp eq i8 %x, 127\n %r = and i1 %cmpeq, %cmp\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sge_and_max_logical", "test_body": "define i1 @sge_and_max_logical(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp eq i8 %x, 127\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sge_and_max_logical_samesign", "test_body": "define i1 @sge_and_max_logical_samesign(i8 %x, i8 %y) {\n %cmp = icmp sge i8 %x, %y\n %cmpeq = icmp samesign eq i8 %x, 127\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null } ] }, { "file": "llvm/test/Transforms/InstCombine/and-or-icmp-nullptr.ll", "commands": [ "opt < %s -passes=instcombine -S" ], "tests": [ { "test_name": "sgt_and_min_logical_samesign", "test_body": "define i1 @sgt_and_min_logical_samesign(ptr %x, ptr %y) {\n %cmp = icmp sgt ptr %x, %y\n %cmpeq = icmp samesign eq ptr %x, null\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sgt_and_min_logical", "test_body": "define i1 @sgt_and_min_logical(ptr %x, ptr %y) {\n %cmp = icmp sgt ptr %x, %y\n %cmpeq = icmp eq ptr %x, null\n %r = select i1 %cmp, i1 %cmpeq, i1 false\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null }, { "test_name": "sle_or_not_min", "test_body": "define i1 @sle_or_not_min(ptr %x, ptr %y) {\n %cmp = icmp sle ptr %x, %y\n %cmpeq = icmp ne ptr %x, null\n %r = or i1 %cmp, %cmpeq\n ret i1 %r\n}\n", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[InstCombine] `samesign` flag should be dropped in `foldAndOrOfICmpsWithConstEq`", "body": "Reproducer:\r\n```\r\n; bin/opt -passes=instcombine test.ll -S\r\ndefine i1 @src(i8 %x, i8 %y) {\r\n %cmp = icmp sgt i8 %x, %y\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %r = select i1 %cmp, i1 true, i1 %cmpeq\r\n ret i1 %r\r\n}\r\n```\r\n```\r\ndefine i1 @tgt(i8 %x, i8 %y) {\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %1 = icmp slt i8 %y, 0\r\n %r = or i1 %cmpeq, %1\r\n ret i1 %r\r\n}\r\n```\r\n```\r\n----------------------------------------\r\ndefine i1 @src(i8 %x, i8 %y) {\r\n#0:\r\n %cmp = icmp sgt i8 %x, %y\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %r = select i1 %cmp, i1 1, i1 %cmpeq\r\n ret i1 %r\r\n}\r\n=>\r\ndefine i1 @tgt(i8 %x, i8 %y) {\r\n#0:\r\n %cmpeq = icmp samesign ne i8 %x, 0\r\n %#1 = icmp slt i8 %y, 0\r\n %r = or i1 %cmpeq, %#1\r\n ret i1 %r\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni8 %x = #x81 (129, -127)\r\ni8 %y = #x80 (128, -128)\r\n\r\nSource:\r\ni1 %cmp = #x1 (1)\r\ni1 %cmpeq = poison\r\ni1 %r = #x1 (1)\r\n\r\nTarget:\r\ni1 %cmpeq = poison\r\ni1 %#1 = #x1 (1)\r\ni1 %r = poison\r\nSource value: #x1 (1)\r\nTarget value: poison\r\n```\r\n", "author": "dtcxzyw", "labels": [ "miscompilation", "llvm:instcombine" ], "comments": [] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
137152
https://github.com/llvm/llvm-project/issues/137152
crash
224cd50e005a9215e8c528d5ce68d4fcdfcdb98f
2025-04-24T10:47:46
[ "llvm/test/Transforms/GlobalOpt" ]
{ "fix_commit": "57530c23a53b5e003d389437637f61c5b9814e22", "components": [ "GlobalOpt" ], "bug_location_lineno": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": [ [ 719, 728 ] ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/include/llvm/Analysis/LoopAccessAnalysis.h": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/include/llvm/Analysis/ScalarEvolution.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/include/llvm/Analysis/MemorySSAUpdater.h": null, "llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/include/llvm/IR/CmpPredicate.h": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanValue.h": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/include/llvm/Transforms/IPO/DeadArgumentElimination.h": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanHelpers.h": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/IR/Instruction.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null }, "bug_location_funcname": { "llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null, "llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null, "llvm/lib/Analysis/MemorySSAUpdater.cpp": null, "llvm/lib/Transforms/Utils/Local.cpp": null, "llvm/lib/Transforms/Scalar/LoopDeletion.cpp": null, "llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null, "llvm/lib/Transforms/IPO/GlobalOpt.cpp": [ "allUsesOfLoadedValueWillTrapIfNull" ], "llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null, "llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null, "llvm/lib/Analysis/ConstantFolding.cpp": null, "llvm/lib/Analysis/ScalarEvolution.cpp": null, "llvm/lib/IR/Operator.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null, "llvm/lib/Transforms/Scalar/LoopFuse.cpp": null, "llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null, "llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null, "llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null, "llvm/lib/Transforms/Utils/LoopPeel.cpp": null, "llvm/lib/Analysis/InstructionSimplify.cpp": null, "llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null, "llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp": null, "llvm/lib/Analysis/ValueTracking.cpp": null, "llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null, "llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null, "llvm/lib/IR/AsmWriter.cpp": null, "llvm/lib/Transforms/Utils/PredicateInfo.cpp": null, "llvm/lib/Transforms/Utils/SCCPSolver.cpp": null, "llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null, "llvm/lib/Transforms/IPO/FunctionAttrs.cpp": null, "llvm/lib/Analysis/LoopAccessAnalysis.cpp": null, "llvm/lib/IR/ConstantFold.cpp": null, "llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null, "llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null, "llvm/lib/Transforms/Scalar/LICM.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null, "llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null, "llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp": null, "llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null, "llvm/lib/Transforms/IPO/SCCP.cpp": null, "llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp": null, "llvm/lib/Analysis/LazyValueInfo.cpp": null, "llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp": null, "llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp": null, "llvm/include/llvm/IR/GenericFloatingPointPredicateUtils.h": null, "llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null, "llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null, "llvm/include/llvm/IR/PatternMatch.h": null, "llvm/lib/Analysis/LoopCacheAnalysis.cpp": null, "llvm/include/llvm/Transforms/IPO/FunctionSpecialization.h": null, "llvm/lib/Transforms/IPO/FunctionSpecialization.cpp": null, "llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null, "llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null, "llvm/lib/IR/Value.cpp": null, "llvm/include/llvm/Analysis/AliasAnalysis.h": null, "llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null, "llvm/lib/Analysis/BasicAliasAnalysis.cpp": null, "llvm/lib/Transforms/Scalar/JumpThreading.cpp": null, "llvm/lib/Analysis/Loads.cpp": null, "llvm/lib/Transforms/Scalar/GVN.cpp": null, "llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp": null, "llvm/lib/Transforms/Scalar/Scalarizer.cpp": null, "llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null, "llvm/lib/IR/Instructions.cpp": null, "llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null, "llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp": null, "llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null, "llvm/lib/Transforms/Utils/ValueMapper.cpp": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null, "llvm/lib/Transforms/Vectorize/VPlan.h": null, "llvm/lib/Transforms/Scalar/Reassociate.cpp": null, "llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp": null, "llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp": null, "llvm/lib/Transforms/Scalar/NewGVN.cpp": null, "llvm/lib/Analysis/InlineCost.cpp": null, "llvm/include/llvm/Analysis/SimplifyQuery.h": null, "llvm/lib/Transforms/Vectorize/VPlan.cpp": null, "llvm/lib/Transforms/Utils/LowerSwitch.cpp": null, "llvm/lib/Transforms/Scalar/GVNSink.cpp": null, "llvm/include/llvm/Analysis/ValueTracking.h": null, "llvm/lib/IR/Instruction.cpp": null, "llvm/lib/Transforms/Scalar/BDCE.cpp": null, "llvm/lib/Transforms/Vectorize/VPlanUtils.h": null, "llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp": null, "llvm/lib/Analysis/VectorUtils.cpp": null, "llvm/include/llvm/Transforms/Utils/Evaluator.h": null, "llvm/lib/Transforms/Utils/Evaluator.cpp": null } }
commit 57530c23a53b5e003d389437637f61c5b9814e22 Author: Nikita Popov <npopov@redhat.com> Date: Thu Apr 24 15:15:47 2025 +0200 [GlobalOpt] Do not promote malloc if there are atomic loads/stores (#137158) When converting a malloc stored to a global into a global, we will introduce an i1 flag to track whether the global has been initialized. In case of atomic loads/stores, this will result in verifier failures, because atomic ops on i1 are illegal. Even if we changed this to i8, I don't think it is a good idea to change atomic types in that way. Instead, bail out of the transform is we encounter any atomic loads/stores of the global. Fixes https://github.com/llvm/llvm-project/issues/137152. diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index cfba8dcc05b2..3771cccbde17 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -719,10 +719,14 @@ static bool allUsesOfLoadedValueWillTrapIfNull(const GlobalVariable *GV) { const Value *P = Worklist.pop_back_val(); for (const auto *U : P->users()) { if (auto *LI = dyn_cast<LoadInst>(U)) { + if (!LI->isSimple()) + return false; SmallPtrSet<const PHINode *, 8> PHIs; if (!AllUsesOfValueWillTrapIfNull(LI, PHIs)) return false; } else if (auto *SI = dyn_cast<StoreInst>(U)) { + if (!SI->isSimple()) + return false; // Ignore stores to the global. if (SI->getPointerOperand() != P) return false;
[ { "file": "llvm/test/Transforms/GlobalOpt/malloc-promote-atomic.ll", "commands": [ "opt -passes=globalopt -S < %s" ], "tests": [ { "test_name": "<module>", "test_body": "\n@g = internal global ptr null, align 8\n\ndefine void @init() {\n;\n %alloc = call ptr @malloc(i64 48)\n store atomic ptr %alloc, ptr @g seq_cst, align 8\n ret void\n}\n\ndefine i1 @check() {\n;\n %val = load atomic ptr, ptr @g seq_cst, align 8\n %cmp = icmp eq ptr %val, null\n ret i1 %cmp\n}\n\ndeclare ptr @malloc(i64) allockind(\"alloc,uninitialized\") allocsize(0)", "lli_expected_out": null, "additional_args": null } ] } ]
{ "title": "[GlobalOpt] Incorrect change of atomic type", "body": "```llvm\n; RUN: opt -S -passes=globalopt\n@g = internal global ptr null, align 8\n\ndefine void @init() {\n %alloc = call ptr @malloc(i64 48)\n store atomic ptr %alloc, ptr @g seq_cst, align 8\n ret void\n} \n\ndefine i1 @check() {\n %val = load atomic ptr, ptr @g seq_cst, align 8\n %cmp = icmp eq ptr %val, null\n ret i1 %cmp\n}\n\ndeclare ptr @malloc(i64) allockind(\"alloc,uninitialized\") allocsize(0)\n```\nResults in:\n```\natomic memory access' size must be byte-sized\n i1 store atomic i1 true, ptr @g.init seq_cst, align 1\natomic memory access' size must be byte-sized\n i1 %g.init.val = load atomic i1, ptr @g.init seq_cst, align 1\nLLVM ERROR: Broken module found, compilation aborted!\n```\n", "author": "nikic", "labels": [ "ipo", "release:backport", "crash" ], "comments": [] }
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
119173
https://github.com/llvm/llvm-project/issues/119173
miscompilation
ab77db03ce28e86a61010e51ea13796ea09efc46
2024-12-09T07:19:06
[ "llvm/test/Transforms/LoopVectorize" ]
{"fix_commit":"30f3752e54fa7cd595a434a985efbe9a7abe9b65","components":["LoopVectorize"],"bug_locatio(...TRUNCATED)
"commit 30f3752e54fa7cd595a434a985efbe9a7abe9b65\nAuthor: Florian Hahn <flo@fhahn.com>\nDate: Mon (...TRUNCATED)
[{"file":"llvm/test/Transforms/LoopVectorize/AArch64/mul-simplification.ll","commands":["opt -p loop(...TRUNCATED)
{"title":"[clang] Miscompilation at -O3","body":"This code prints 15 at -O3, but prints 5 at -O0/1/2(...TRUNCATED)
true
{ "is_single_file_fix": true, "is_single_func_fix": false }
null
157335
https://github.com/llvm/llvm-project/issues/157335
crash
61a8d2deec7341527a35299d1b1ed2cf2327706f
2025-09-07T09:21:41
[ "llvm/test/Transforms/VectorCombine" ]
{"fix_commit":"ad3a0ae9e15f102e2cdc37e34d47b5b9d6e09497","components":["VectorCombine"],"bug_locatio(...TRUNCATED)
"commit ad3a0ae9e15f102e2cdc37e34d47b5b9d6e09497\nAuthor: Simon Pilgrim <llvm-dev@redking.me.uk>\nDa(...TRUNCATED)
[{"file":"llvm/test/Transforms/VectorCombine/pr157335.ll","commands":["opt -passes=vector-combine -S(...TRUNCATED)
{"title":"[VectorCombine] llvm/test/CodeGen/PowerPC/swaps-le-7.ll crashes with -passes=vector-combin(...TRUNCATED)
true
{ "is_single_file_fix": true, "is_single_func_fix": true }
null
End of preview. Expand in Data Studio
YAML Metadata Warning: The task_categories "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other

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,
  // You are allowed to choose a subset of issues to fix.
  // Althrough these properties are obtained from the golden patch,
  // using properties is not treated as using hints.
  "properties": {
    "is_single_file_fix": true,
    "is_single_func_fix": true
  }
}

As of May 19, 2025, this benchmark contains 295 issues. You can run python3 scripts/dataset_summary.py locally to obtain the latest statistics.

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

Bug type summary:
  miscompilation: 106
  crash: 181
  hang: 8

Bug component summary (Total = 50):
  SLPVectorizer: 73
  LoopVectorize: 71
  InstCombine: 54
  ScalarEvolution: 15
  VectorCombine: 11
  ValueTracking: 8
  IR: 6
  ConstraintElimination: 5
  InstructionSimplify: 5
  SimplifyIndVar: 4
  Local: 4
  LoopAccessAnalysis: 3
  LoopPeel: 3
  MemCpyOptimizer: 3
  DeadStoreElimination: 3
  MemorySSAUpdater: 3
  ...

Label summary:
  crash: 111
  miscompilation: 108
  vectorizers: 81
  llvm:SLPVectorizer: 73
  crash-on-valid: 61
  llvm:instcombine: 57
  llvm:transforms: 40
  llvm:analysis: 22
  release:backport: 16
  llvm:SCEV: 16
  generated by fuzzer: 13
  confirmed: 9
  llvm:crash: 8
  regression: 7
  llvm:hang: 6
  ...

Changed files count summary:
  Average: 1.17
  Max: 5
  Min: 1
  Median: 1

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

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

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

Patch summary:
  Single file fix: 264 (89.49%)
  Single func fix: 227 (76.95%)
  Single hunk fix: 168 (56.95%)

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)
# Properties
is_single_func_fix = env.is_single_func_fix()
is_single_file_fix = env.is_single_file_fix()

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
875

Space using dtcxzyw/llvm-apr-benchmark 1